Linear Regression (LinR)

What it does

The Linear Regression tool plots the regression line and a standard error channel, based on the points you click. The distance away from the LR line for the limit lines is either the maximum deviation above and below the LR line, when the Limit Lines parameter is set to Max Deviation, or the standard errors multiplied by the value specified in the Factor parameter when Limit Lines are set to Factor x StdErr. For example, selecting a factor of .5 would plot each line .5 standard errors away from the LR line. The Standard Error is defined as: (The sum of the squares of the deviation from the line)/The number of bars – 1).

Standard mathematics are used for the Linear Regression. The maximum deviation is the price that is furthest from the linear regression line. For example: If the selected price is close and the two selected points are 20 bars apart, the linear regression line is calculated using the 20 closes between the selected points, and then the maximum deviation is found by looking at each close and finding the one that is furthest from the linear regression line. One limit line is placed parallel to the linear regression line, intersecting the close that is furthest from the linear regression line. The other limit line is placed parallel an equal distance to the other side of the linear regression line.

The formula is:

(14 * Sum( Accum(@,none)* Close(@),14) - Sum(Accum(@,none),14) * Sum(Close(@),14)) / (14 * Sum(Power(Accum(@,none),2.00000),14) - Power(Sum(Accum(@,none),14),2.00000))

 *

Accum(@,none) + (MA(@,Sim,14) - MA(Accum(@,none),Sim,14)

*

(14 * Sum( Accum(@,none)* Close(@),14) - Sum(Accum(@,none),14) * Sum(Close(@),14)) / (14 * Sum(Power(Accum(@,none),2.00000),14) - Power(Sum(Accum(@,none),14),2.00000)))

 

Note: If your first point is in the past and your second point is in the future (beyond the current bar), the Linear Regression tool will continue recalculating and redrawing the regression lines, including the new bar data, as it comes in. Additionally, if your first point is in the future and your second point is in the past, LinR will continue including the new data as it comes in, until the time of the first point is reached, when no new data will be included.

Depending on where the mouse is in relation to the bar and the linear regression line, different values will be displayed in the mouse text box.

Pointer is on the linear regression line, but not near a bar, mouse text displays:

P = Price represented by pointer position

LR:DN = Value of the bottom linear regression envelope line.

LR:LR = Value of the linear regression line.

LR:UP = Value of the top regression envelope line.

S = Slope of the line in price per day.

R2 = The square of the error.

Pointer is close to, or on, a bar but not on the linear regression line, mouse text displays:

P = price

O= open

H = high

L = low

C = close

Pointer is not near a bar and not on the linear regression line, mouse text displays:

P = price

How to use it

1.  Right-click the chart, point to Pointer Tools, then click Linear Regression. The cursor becomes a pencil.

2.  Click the a starting point on the chart.

3.  Move the cursor until you reach the desired location, and click to park it.

Linear Regression parameters

LR1:Pnt1

Parameter

Description

Display

Opens sub-window with display parameters:

Color = Select color for lines.

Weight = Select thickness for lines.

Id = Turns labels on and off.

Id Wt = Determines thickness of label.

Date

Indicates the two initial dates used to draw the regression line on intraday charts.

Time

Indicates the two initial times used to draw the regression line on intraday charts.

Price

Price used to draw the regression lines. Choices include: Open, High, Low, Close, Mid, HLC/3, and Average.

Limit Lines

Sets how the standard error channel lines are constructed. Choices include: Factor x Std Err, Factor x Residuals, and Max Deviation.

Standard Error = MLR(@,period) + Factor * StdDev(@,period)

Residual = MLR(@,period) + Factor * SqRoot(MLRResidual(@,period)/(period-1)) with n-1 as divisor

Max Deviation = The close that is furthest from the linear regression line.

Factor

Number of standard errors between the limit lines, if the Limit Lines parameter is set to Factor x Std Err. Otherwise, this setting has no effect on the display.

Divisor

N = a standard deviation calculation

N-1 = population standard deviation calculation.

Length

Determines the direction and length of the line. Options include:

Pnt1-Pnt2 -> (from point one and all the way right)

<- Pnt1-Pnt2 (from point two and all the way left)

Pnt1-Pnt2 (between points one and two)

<- Pnt1-Pnt2 -> (all the way left and all the way right)

Pnt2 -> (from point two and all the way right)

<- Pnt1  (from point one and all the way left)

Update

Number of minutes between recalculations. If set to zero, the study recalculates after every tick. Setting the study to recalculate after every tick allows the two reference points to remain a constant number of bars apart.

ScaleLabel

Select this checkbox to color-code the price scale according to the trend line.

 

LR1:Pnt2

 

Parameter

Description

Date

Indicates the two initial dates used to draw the regression line on intraday charts.

Time

Indicates the two initial times used to draw the regression line on intraday charts.

Factor

Number of standard errors between the limit lines, if the Limit Lines parameter is set to Factor x Std Err. Otherwise, this setting has no effect on the display.