Tutorial 130 | How to plot linear regression channels

Tutorial 130 | Part 1 | Creating a linear regression channel plot

Back in tutorial 49 I created a linear regression show me study that used TradeStation’s legacy drawing tools to draw a linear regression channel.

Tutorial 130 demonstrates how tutorial 49 could be rewritten using Plot statements as a TradeStation indicator (but still including the original legacy drawing statements). In part 2 (see below), I demonstrate the program after the legacy drawing tools have been removed.

If you are a MultiCharts user, please see notes at the end of this page.

Tutorial 130 applied to an EURUSD 1 minute chart. The image shows lines plotted overlaid with lines drawn.

There are several advantages in using plot statements rather than the legacy drawing tools:

    • The plots can be formatted using TradeStation’s standard plot dialogs for color, style, and transparency
    • Plots can be used on sub-minute bars, e.g. tick, second, advanced bar charts (whereas the legacy drawing tools are only accurate when used to the minute level)
    • The syntax is a lot simpler when new lines need to be added
    • By overlaying the drawing on top of the plot gives the user more display options
    • It is optional as to whether you set color defaults in the program
    • A setting in the TradeStation indicator dialog enables you to determine whether the indicator updates every tick or a the end of the bar
    • Markers show the end values of the levels in the price axis (if turned on)

On the downside plots have the following disadvantages:

  • Only one Plot1, Plot2, Plot3 etc is allowed per bar, therefore option 2 in the tutorial program is not possible using plots (at least not easily)
  • The style options (dashes etc) are limited at the heavier weights

Some of the benefits of using Plot to create a linear regression channel:

The pricipal coding concept explored in this tutorial is the ability of Plot statement to plot, or modify the plot an an historic bar and change the color of an historic plot to transparent.

The following is plot syntax to plot something (in this case Plot1 plots Value1 and Plot2 plots Value2) on the current bar:

Plot1( Value1 );
Plot2[0]( Value2 );

The following plots something on the last bar:

Plot2[1]( Value2 );

and this would plot something on the bar before that:

Plot2[2]( Value2 );

The linear regression calculations are covered extensively in tutorial 48. You might also be interested in program 63. Program 63 draws linear regression lines, and then creates a smoothed plot based on the linear regression end point. It also offers the option to plot oscillators based on non-smoothed plots.

The tutorial 130 program (_Tutorial130) is available for download for $34.95 by clicking the following link. The program works with TradeStation and MultiCharts. The download includes a bonus program (_Tutorial130 Only Plots) in which the drawing aspects of program are removed leaving the Plot functionality and a much simpler program. See more about this below.

Areas covered in Tutorial 130

The tutorial demonstrates how to:

  • Use and format legacy drawing tools
  • Plot values on historic bars
  • Make historic plots appear to disappear by using the transparent color attribute

Inputs

NumBars( 20 ), // The number of bars to consider when calculating the linear regression
Price( C ), // The price to consider when calculating the linear regression
NumDevsUp( 2 ), // The number of standard deviations of the end of the linear regression to draw upper channel above linear regression line
NumDevsDn( -2 ), // The number of standard deviations of the end of the linear regression to draw lower channel below linear regression line
NumDevsUp2( 3 ), // The number of standard deviations of the end of the linear regression to draw second upper channel above linear regression line
NumDevsDn2( -3 ), // The number of standard deviations of the end of the linear regression to draw second lower channel below linear regression line

GraphOption( 3 ), // See different presentation options explained below

// Style options for the lines that are drawn
TopLineCol( Red ), // Color of the line above the mid line
MidLineCol( Yellow ), // Color of the mid line
LowLineCol( Cyan ), // Color of the line below the mid line

{ 1 Tool_Solid
2 Tool_Dashed
3 Tool_Dotted
4 Tool_Dashed2
5 Tool_Dashed3 }

TopLineStyle( 1 ), // Style (e.g. solid or dashed) of the line above the mid line
MidLineStyle( 3 ), // Style (e.g. solid or dashed) of the mid line
LowLineStyle( 5 ), // Style (e.g. solid or dashed) of the line below the mid line

LineThickness( 3 ); // Thickness of all the lines (must be an integer between 0 and 6)

GraphOption input

GraphOption = 1: The linear regression is continually calculated for the last NumBars bars on the chart. Lines are plotted and drawn for the last NumBars.

GraphOption = 2: The linear regression is continually calculated for the last NumBars bars on the chart. Lines are drawn for the last NumBars. Once a line has been drawn, it remains on the chart.

GraphOption = 3: When applied to the chart the linear regression is calculated for the last NumBars bars on the chart. Lines are plotted and drawn for the last NumBars. As new bars are added the linear regression moves across the chart.

Video explanation of Tutorial 130


Please let me know if you spot any mistakes or errors or have questions.

The tutorial 130 program (_Tutorial130) is available for download for $34.95 by clicking the following link. The program works with TradeStation and MultiCharts. The download includes a bonus program (_Tutorial130 Only Plots) in which the drawing aspects of program are removed leaving the Plot functionality and a much simpler program. See more about this below.

Tutorial 130 | Part 2

_Tutorial130 Only Plots applied to a 53 second EURUSD chart

Note: This tutorial program is included in the part 1 download above.

In part 2 of this tutorial I remove the parts of tutorial 130 which used the TradeStation legacy drawing syntax, those leaving the linear regression line plotted, rather than drawn and plotted.  I also considerable simplified the tutorial program (named _Tutorial130 Only Plots), hopefully making it easier to understand.

In the tutorial I demonstrate how to add additional channels to the program as well as its use on second and tick charts.

Video explanation of Tutorial 130 Only Plots

Gold Pass area

_Tutorial130 Only Plots is also available at no cost to Gold Pass members below. Make sure that you are logged into Gold Pass.

This content is for Gold Pass members only.

_Tutorial130 Only Plots applied to a 600 tick based Three Line Break GBPUSD chart

Notes for MultiCharts users

MultiCharts currently does not support using Transparent in the Plot statement. This is used in both the tutorial 130 programs.

A possible workaround is to replace lines such as:

Plot1[NumBars]( C[Numbars], "Mid", Transparent );

into:

Plot1[NumBars]( C[Numbars], "Mid", getbackgroundcolor,Default, 0 );

This code colors the unwanted plots to be the same as the background and changes their thickness.

The workaround does result in thin lines sometimes partially obscuring the bars and wicks.

THESE INDICATORS, SHOW ME STUDIES, STRATEGIES AND OTHER PROGRAMS HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES.

TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.

ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.

Plot1[NumBars]( C[Numbars], "Mid", Transparent );

Disclaimer The information, materials, products and services on this Web site are made available subject to the following terms and conditions. Markplex Corporation reserves the right to change these terms and conditions at its sole discretion. This Web site and any downloads, videos, tutorials, programs and information contained herein is presented solely for educational, informational, and/or entertainment use and under no circumstances should be used for actual trading. We at Markplex Corporation are not Broker/Dealers, Financial Advisers or Registered Analysts. No offer or solicitation to buy or sell securities, securities derivatives, futures products or off-exchange foreign currency (forex) transactions of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given or in any manner endorsed by Markplex Corporation. You are fully responsible for any investment or trading decisions you make. Futures and options trading has a large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. This Web site is neither a solicitation nor an offer to buy and/or sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed on this Web site. Past performance, whether actual or indicated by historical tests of strategies, is no guarantee of future performance or success. No warranties of profitability are being made or given. There is a possibility that you may sustain a loss equal to or greater than your entire investment regardless of which asset class you trade (equities, options futures or forex); therefore, you should not invest or risk money that you cannot afford to lose. CFTC RULE 4.41 - Hypothetical or simulated performance results have certain inherent limitations. Unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not actually been executed, the results may have under- or over-compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. Screen shots on this site are examples and are not meant to imply that any of the programs or tutorials available on this Web site will generate profitable trades. EasyLanguage or PowerLanguage trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (and parts thereof) and associated techniques referred to, included in or attached to this tutorial or program description are examples only, and have been included solely for educational, informational, and entertainment use. Markplex Corporation does not recommend that you use any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions (or any parts thereof) or techniques. The use of any such trading strategies, signals, studies, indicators, showme studies, paintbar studies, probabilitymap studies, activitybar studies, functions and techniques does not guarantee that you will make profits, increase profits, or minimize losses. Markplex Corporation assumes no liability for any damages, direct or otherwise, resulting from the use of this information and/or program(s) described, and no warranty is made regarding its accuracy or completeness. Use of this Web site including the information, tutorials and/or programs included on it is at your own risk. You shall indemnify and hold Markplex Corporation harmless from any and all liability, loss, trading losses, costs, damage, or expense, including attorneys' fees you or third party may suffer (other than damage to your tangible property or injuries to employees occurring during the course of work) as a result of claims, demands, costs, or judgments arising out of third party and any other claims based on Markplex Corporation's performance, including, but not limited to losses resulting from the use of Markplex Corporation developed software, programs, web sites, tutorials, or the TradeStation charting and/or trading platform. Any testimonials on this Web site may not be representative of the experience of other clients and are not indicative of future results or success.
This Web site contains or may contain references and links to other companies and/or their Web sites, none of which is under the control of Markplex Corporation. Markplex Corporation makes no representations, warranties or endorsements whatsoever about any other Web sites to which you may have access through the Markplex Corporation Web site, or any products or services of those other companies, even if the products or services of those other companies or their Web sites are described or offered on the Markplex Corporation Web site or integrated with Markplex Corporation's products or services. TradeStation®, EasyLanguage® and PowerEditor® are registered trademarks of TradeStation Technologies, Inc. Other brand and product names which appear on this site are the trademarks or service marks of their respective owners, including: Microsoft® is a registered trademark in the United States Microsoft®Excel® is a registered trademark of Microsoft® Neither TradeStation Technologies nor any of its affiliates has reviewed, certified, endorsed, approved, disapproved or recommended, and neither does or will review, certify, endorse, approve, disapprove or recommend, any product or service that offers training, education or consulting regarding the use of EasyLanguage.

By continuing to use and navigate our sites, services, applications, tools or messaging, you are agreeing to our Terms and Conditions and the use of cookies, web beacons and similar technologies as described in our Privacy Policy and Privacy Policy on the use of cookies.