[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LIN REGRESSION LINE indicator and BarsPlus



PureBytes Links

Trading Reference Links


Re: the indicator, LIN REGRESSION LINE(length, BarsPlus, YYMMDD,
SlctTime, Color, ExtRight) and its input BarsPlus. The focus of this
post is with the meaning of BarsPlus and its usefulness. The input
statements for an indicator are listed after its name.

This indicator calls the function, 

 "LinearRegLine(length, BarsPlus, SlctDate, SlctTime, Color, ExtRight)" 

which in turn calls 2 values of the function 

"LinearRegValue(Price, Len, TargetB)"  (which labels BarsPLus as
TargetB). 

Those 2 values are calculated by: 

LRV= LinearRegValue(close, Len, BarsPlus) and 
LRVAgo= LinearRegValue(close, Len, Len-1). 

The former sets the r.h.s. and the latter the l.h.s. of the line. By
changing BarsPlus the r.h.s value of the line changes. 

(Note there is no price in the input of the function  "LinearRegLine". 
When a value in the called function (LinearRegValue) is hardwired as
price is (close) then that parameter can be left out of the input for
the calling function (LinearRegLine). This is important in getting
regression value points, BarsPlus ago, in the gif below).

"LinearRegValue(Price, Len, TargetB)"  itself can be plotted as point
values of the r.h.s. of the line using the indicator in TS, 

"Linear Regression(Price, Length, Displace)".

To see what effect BarsPlus has, a modification of this indicator is
needed. In the original code, BarsPlus is hardwired as 0 and therefore
BarsPlus is omitted from the input statement (which can be done as noted
above).  Replacing the 0 with BarsPlus and adding BarsPlus into the
input statement now gives

"Linear Regression(Price, Length, BarsPlus, Displace)".

When BarsPlus (TargetB) and Displace are = 0, this plot locates the
r.h.s. (end) of a least squares fit over "length" number of bars (the
red dots in the gif below). Setting BarsPlus = 5 gives the blue dots.
These are LRV values. Plotting "Lin Regression LINE" for BarsPlus =0 and
5 gives the red and blue LINES respectively. LRVAgo has not changed so
both start at the same value. THE QUESTION IS, WHAT IS THE MEANING (OR
SIGNIFICANCE) OF THE BLUE LINE?

The value of the  r.h.s. of the blue line is simply the value of the red
line 5 bars back (at A) as shown by the green horizontal line. BarsPlus
simply projects to the CURRENT BAR (at B) a value of the LRL at
"BarsPlus ago" (or "BarsPlus ahead" if BarsPlus<0). Then draws a line
from the start point of the LRL (at C) to the current bar using the
"BarsPlus ago" LRL value (from A). THE RESULTING LINE IS NOT A LRL! I
MAINTAIN THERE IS NO SIGNIFICANCE TO THIS LINE AND BarsPlus SHOULD NOT
BE AN OPTION IN THE  LIN REGRESSION LINE  INDICATOR BUT SHOULD BE
PERMANENTLY SET TO ZERO

(Looking at the last line of code in the LinearRegValue function: 
LinearRegValue = Intercept + Slope*(Len-1 -BarsPlus). This is a straight
line, y=a+bx. For a given Len, LinearRegValue is the value y has at each
bar along this straight line (Slope = constant). Increasing BarsPlus
moves back (left) along the red line, giving the value of y at any bar,
BarsPlus ago. This is then projected to the current bar.)

The TS Help file does not make clear the significance of a line when
BarsPlus<>0. Under  "Linear Regression Line (Indicator)":

BarsPlus is the "Number of bars forward the linear regression line is
extended". "By specifying the number of bars forward to extend the line
(input, BarsPlus) the linear regression line can be plotted to the right
of the chart". THIS RESULTING LINE IS NOT A LIN REGRESSION LINE. 


Wayne Mathews

Attachment: Description: ""