How calc the channel of a linear regression?

 

Hi everyone!


    To me the Regression Channel object seems to be very helpful and I would like to code it to a indicator.

    To find the linear regression line is realy easy, there are indicators ready for download in the library that I can pick up to start with. But my dificulty is in calculating the edges of the channel.

    The Help says "The distance between frame of the channel and regression line equals to the value of maximum close price deviation from the regression line", but I didn't realy understand the calculation.

 
Alexess Ss:

    To me the Regression Channel object seems to be very helpful and I would like to code it to a indicator.

    To find the linear regression line is realy easy, there are indicators ready for download in the library that I can pick up to start with. But my dificulty is in calculating the edges of the channel.

    The Help says "The distance between frame of the channel and regression line equals to the value of maximum close price deviation from the regression line", but I didn't realy understand the calculation.

That is called the deviation and in this case it is the Least Squares method. Read up on Linear and Polynomial Regression as well as Least Squares.

 
Alexess Ss:

Hi everyone!


    To me the Regression Channel object seems to be very helpful and I would like to code it to a indicator.

    To find the linear regression line is realy easy, there are indicators ready for download in the library that I can pick up to start with. But my dificulty is in calculating the edges of the channel.

    The Help says "The distance between frame of the channel and regression line equals to the value of maximum close price deviation from the regression line", but I didn't realy understand the calculation.

You'll probably get there much faster if you search here first, because there's almost nothing that hasn't already been programmed for MT4/MT5 and is also ready for you.

 

Thanks, guys!

To make it easier I kept looking in the library until I found this. Unlike others, the calculation of the channel is very close to the Regression Channel object.

The challenge now is to make it work in the price history and not just in real time

LinearRegressionChannel
LinearRegressionChannel
  • www.mql5.com
Custom instrument of the linear regression. LR line, Support and Resistance lines values are in the buffers
 
Alexess Ss: To make it easier I kept looking in the library until I found this. Unlike others, the calculation of the channel is very close to the Regression Channel object. The challenge now is to make it work in the price history and not just in real time

It will not be possible to do linear regression over the entire history as a moving window, because it is a "repainting" indicator. In other words it will update the channel angle and deviation on each new bar, so you can't really keep a history of it in the traditional way indicators work.

Instead consider using the end-points only, so that it does not repaint. An example of this is the Least Squares Moving Average (LSMA), or Endpoint Moving Average (EPMA), which use the end-points of the linear regression line. You can still use the mean deviation of the regression to plot a channel centred around on the end-point as well.