Profile Picture

Linear Regression Trendline

Posted By ywlee 4 Years Ago
Posted Wednesday June 03 2015

Need to understand more about the Linear Regression Trendline (LRT).

On a simple SMA / LRT crossover, it doesn't seem to trigger where the chart shows the crossover.  Have tested this with other crossover indicators and it seems that it has a tendency to trigger under the LRT levels. 

Not sure if this is a charting issue or I'm using it wrong.

Here is the code:

  LinearRegressionTrendline LinearTL;

public override void Startup()
// Perform initialization here.
   LinearTL = new LinearRegressionTrendline();
   LinearTL.ChartSettings.ChartPaneName = "CrossOver";
   LinearTL.ChartSettings.Color = Color.Red;
   LinearTL.ChartSettings.LineSize = 3;
   LinearTL.ChartSettings.DisplayName = "Linear Regression Trendline";

   SMA5 = new SMA(5);
   SMA5.ChartSettings.ChartPaneName = "CrossOver";
   SMA5.ChartSettings.Color = Color.Green;
   SMA5.ChartSettings.LineSize = 3;
   SMA5.ChartSettings.DisplayName = "SMA";


public override void NewBar()
// Put your trading code here
   if (SystemUtils.CrossOver(SMA5, LinearTL))
    PositionSettings ps = new PositionSettings();   
    ps.Description = "Long";
    ps.PositionType = PositionType.Long;
    ps.OrderType = OrderType.Market;


Posted Wednesday June 03 2015
The Linear Regression trendline displays a trendline of a linear regression of all values up through the current bar.  This means when a new bar comes in, the linear regression is adjusted, and all of the values for the trendline can change.

So when you look at a chart for the simulation, you are seeing the linear regression for the most recent bar, but it's not displaying what the linear regression looked like for the previous bars when the trades were triggered.


Similar Topics

Reading This Topic

2005-2019 © RightEdge Systems