LinearRegLine
Author: Panache
Creation Date: 6/23/2015 6:57 PM
profile picture

Panache

#1
I don't understand the results I'm getting using LinearRegLine. The QuickRef says the last parameter specifies the bar for which you want to predict a value. Therefore, I expected the Blue line to be a correct implementation.

When I run the following code against 1 year (250 bars) of data for AA, it is obvious from the chart that the blue line is not a linear regression of anything, since it is below every price. Instead, the orange line appears to be the correct linear regression.

Is that the way it is supposed to work? If so, what is the purpose of the last parameter?

CODE:
Please log in to see this code.
profile picture

Eugene

#2
This is predicted value for a bar in the future (250) because it's calculated using the span of bars 236-245:
CODE:
Please log in to see this code.


The orange line is real. However, sometimes...
profile picture

Panache

#3
Thanks. So the reason it is graphing funny is that the orange line should be drawn by only going from 236 to 245.

CODE:
Please log in to see this code.


And to be precise, the blue line should be drawn starting at 236 also.

CODE:
Please log in to see this code.
profile picture

Panache

#4
Sorry, I thought I understood this, but I still can't make it work. Shouldn't all three lines overlap? All of these lines have the same starting point (the Close on bar 236) and should have the same slope (the slope of the linear regression line calculated on bars 236 to 245, which is the green line).

CODE:
Please log in to see this code.
profile picture

Panache

#5
I graphed it on Excel, and I think I now understand it. LinearRegLine returns the value of the end point of the linear regression line at the bar number to which it is extended. Therefore, in order to draw the linear regression line, you have to extend it backwards to beginning and forward to the end of the data upon which you are doing a linear regression.

CODE:
Please log in to see this code.
profile picture

Cone

#6
Here's a simple exercise to get a better feel for LinearRegLines and how they're related to the LinearReg.Series indicator

1. Click the Regression Channel drawing tool.

2. Watching the chart status bar, click on say bar 230 (any number will do) and drag it to bar 250 and release.
(The idea is to drag it across 20 bars, which gives the channel a 21-bar period).

3. Drag and drop a LinearReg indicator on to the chart, and set its period to 21. The Source needs to be "Close" for this exercise to work since that's what the Reg Channel is based on.

4. Now click on the center line in the regression channel, and drag it it right and left.

If you've done everything correctly, you'll see that the end of center [regression] line tracks the LinearReg indicator perfectly. And, notice that the slope of the line changes with each movement. That's what the LinearRegSlope indicator measures.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).