A User-Interactive Linear Regression Channel Indicator: LRChan
The linear regression channel indicator, LRChan, draws a center line between two points on a price chart such that the sum of the squares of the distances from price to this center line is minimized. Linear regression channels are then formed by creating lines parallel to the center line, separated by a deviation distance specified by the user.
The chart below shows DELL has been in a steady up trend since March. The Linear Regression Channel indicator has been applied with user specified input parameters of Length = 100, Deviation = 1 Standard Error Unit and Offset = 1.
One use of this indicator is to provide estimates of entry and exit points for those wishing to swing trade the stock during its upward trend.
The Deviation Function is User Selectable
There is considerable flexibility in specifying the deviation function used to determine the separation between the regression channel lines parallel to the center line.
The user specifies the desired deviation function by entering a deviation ID number as an input parameter, DevID. The deviation function may be selected from any of the following:
The Jurik Average True Range function (ATR using Jurik Moving Average) requires the purchase of a Tradestation add-on from Jurik Research. The call to this function is commented in the code and *.ELD file as most users will not be licensed to use this function. Those that are licensed may un-comment the appropriate section of code in local method (or function) DrawLRChan to implement this feature.
Normally when a user wishes to change the format input parameters of an indicator, such as Length or Offset, the formatting window must be opened and the new parameter values manually entered.
To set the Length of the regression channel to coincide with the starting point of a new trend, a trial and error process then ensues while the user adjusts both the Length and/or Offset so the indicator is positioned exactly as desired on the chart. This is both time consuming and inconvenient to the user.
An improved approach is to allow the user to move the center line of the regression channel indicator to any position on the chart, and to be able to adjust the Length of the channel by moving the beginning point and the end point of the center line.
This is not possible with most indicators as they are produced by plot statements, which have no user interaction capability. However, in this case, since trend lines are used to create this indicator EL code can check to see if the center line has been moved by the user by calling functions such as such as TL_GetBeginDate, TL_GetBeginTime, TL_GetEndDate and TL_GetEndTime.
The LRChan indicator checks the position of the center line every CalcSeconds seconds. CalcSeconds is also a input parameter that may be set by the user. It has a default setting of 2, so any movement of the center line by the user will result in the regression channel being redrawn within a 2 seconds. This value is used to prevent too frequent polling of the center line position when on a chart with a high volume of trades (many ticks per second).
LRChan Indicator Examples
Price is the reference value used to calculate the regression line.
Length is the desired length of the regression channel.
Offset is the number of bars the regression channel is shifted to the left from the rightmost bar displayed. Shifting the regression channel to the left will reduce the influence of the most recent bars on the slope and the deviation of the channel. This will facilitate identifying price break-outs from the channel earlier, as the channel slope will not be "chasing" the the most recent price activity.
TgtBar may be used to estimate the value of the linear regression channel into the future.
DevID selects the function to use to calculate the distance between the center line and the parallel upper and lower lines. The integer value corresponds to the input parameters immediately below it. For example, DevID = 1 for a standard deviation displacement, DevID = 2 for a standard error displacement, etc.
StdDevLength is the length that will be used for the deviation function StdDev, if the user also selects DevID = 1. If StdDevLength = 0, then Length will be used for the deviation function StdDev. If the user changes the end points of the center trend line, the new trend line length is used to calculate the standard deviation.
StdErrLength is the length that will be used for the deviation function StdError, if the user also selects DevID = 2. If StdErrLength = 0, then Length will be used for the deviation function StdErr. If the user changes the end points of the center trend line, the new trend line length is used to calculate the standard error.
NBands is the number of parallel lines above and below the center line.
StartMult is the deviation function multiple used to establish the deviation used for the inner most parallel line adjacent to the center line.
Increment is the deviation function multiple used to establish spacing between all subsequent bands up to the total of NBands.
FreezeBeginPoint is set to true if the beginning point of the channel should not move when new bars are added to the chart. This is useful if the user wishes to move the channel to a pivot point representing the beginning of trend. As the trend continues, the beginning bar for the trend remains constant instead of the entire channel moving one bar to the right each time a new bar is added to the chart.
BeginDate_YYYYMMDD, if specified, sets the begining date of the LR channel, overriding the begin date normally calculated from the specified Length and Offset. This is useful when each the user wishes to set the LR channel beginning date to correspond to a known date, such as an inportant pivot point on the chart.
AlertBand, if non-zero, is the band number that will trigger an alert when price crosses it. This is useful to signal breakouts from the channel.
AlertBandColor is the color of the outer band when the OuterBandAlert is set to true. This reminds the user that the indicator has been set to trigger alerts.
CalcSeconds is the interval (in seconds) that the indicator will test for any movement of the LR channel centerline by the user.
The remainder of the parameters are self-explanatory.