HighTick


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.

linear regression indicator on price chart

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:

  1. Standard Deviation
  2. Standard Error
  3. Average True Range - ATR (Keltner Bands)
  4. Jurik Average True Range JATR (ATR using Jurik Moving Average)
  5. Percentage
  6. Points

 

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.

User-Interactive 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

The LRChan indicator is initially applied with default input settings of Length = 60, Deviation = 1 ATR, Offset = 1.

Adjusting the regression channel to start at the beginning of the up trend in early July, the user drags the leftmost end of the center line to the beginning of the up trend.

When the next data tick is received by the chart, the indicator recognizes that the center line was moved by the user.

This triggers a recalculation of the regression line with a length corresponding to the start of the up trend, Length = 41.

 

Wishing to analyze the sideways moving segment starting at the beginning of August, the user again moves the beginning of the center line to correspond to the beginning of the sideways movement.

 

When the next data tick arrives, the chart again recognizes that the center line has been moved by the user and redraws the regression channel to conform to the new center line position, corresponding to Length = 21.

 

Now, wishing to look at the regression channel during a previous downtrend, the user clicks on the central portion of the center line and drags the entire center line to the left to correspond to the desired time segment of the chart.

 

The regression channel is automatically redrawn in this new position.

This ability to reformat the regression channel without having to opening the formatting window and repeatedly adjust the Length and Offset input parameters makes reformatting much faster and significantly more convenient to the user.

When input parameter BandAlert = 3, the third deviation bands of the indicator will change to a dotted line to remind the user that the Alert is ON. In this state, the alert will be triggered when the price touches either of the 3rd bands, signifying that the price is breaking out of the previous trend.

Note that the right most point of the center line is offset 6 bars to left. This is to remove the influence of the most recent bars from changing the slope or spacing of the indicator when a breakout is starting. Such a setting causes the alert from a price break out to be triggered sooner, since the indicator is not chasing in the direction of the right most bar.



Advantages of the Object Oriented EasyLanguage Version

LRChan, the OOEL version of LinRegChan, enhances the user-interactive features of the indicator over the standard EasyLanguage version in the following way:

  1. The Timer object generates a "tick" every CalcSeconds, which triggers the indicator to respond to any user interactive changes in the Length, Starting Position or Ending Position of the central trend line that defines the linear regression channel.

    LinRegChan, the older standard EL version (TS 8.0) requires a trade "tick" for any user changes to the center line to be recognized and responded to. Therefore, during times when the market was closed and no trades were occurring, there were no user-interactive features of the indicator that worked.

    LRChan, the OOEL version (TS 9.0), solves this problems and responds to the user dragging the center line to a new position, or changing its length by dragging one end of the other, regardless of whether the market is trading. This is a big advantage when the user wants to see how the indicator behaved in historical sections of the chart.
  2. LRChan is much more efficient, as it does not have to use traditional "timer" code, which is CPU intensive, to throttle the frequency the indicator is testing to see if the center line was moved by the user.

    The channel drawing function, DrawLRChan, has also been replaced with a local method (subroutine) DrawLRChan that is significantly more efficient. Local methods eliminate the overhead associated with passing large numbers of parameters to a function with each function call. All variables defined in the indicator (main program) are global to all local methods and do not have to be redefined or passed in the local method.

    Therefore, LRChan enhances responsiveness to user interactions while improving efficiency of the code.


LRChan Input Parameters

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.

 

Downloads:

Initial posted version: 09/06/09

Last Updated: 05/08/13

All Code and *.ELD Files: LRChan.zip

( *.ELD files are compiled for TS 9.1 )


The code may be visualized here:


Indicator LRChan

Function JMATrueRange


 

Bookmark and Share