# Linear Regression Channel Indicator For MT5

Table Of Contents:

- Linear Regression Channel Indicator For MT5
- Installing the Linear Regression Channel Indicator For MT5
- Parameters of the Linear Regression Channel Indicator For MT5
- Buffers of the Linear Regression Channel Indicator For MT5
- Main Parts Of The Code

The Linear Regression Channel Indicator For MT5 is an interesting technical indicator of magnificent proportions in that it has a great technical method for channeling price action - so what it does is that it plots a colorized and multi-level based channel which is calculated using the linear regression model which works accurately well compared to other channel analysis trading tools. There are mainly five levels to this price action channel so it has the upper level, the lower level, the middle band, in between the middle and the upper band is mid-upper band and in between the lower band and the middle band is another channel line therefore because of the way in which this indicator is set up these levels may actually be used as resistance and support levels because the price action tends to adhere to these levels well enough. However it should be noted that the trader should not use these three resistance and support levels religiously because they are just there to act as guidelines - furthermore this indicator also helps with monitoring or gauging the strength of any given trend so first of all the trader may look at the steepness of the channel which is a useful hint for determining the strength of the trend. This indicator is always recalculating its position relative to the price activity and various other variables and therefore the necessary automatic adjustment needs to be made continuously which is all based on one very important input variable known as the channel period which has a default setting of 150 which is ideal because most trends last for that long so it is a good number to start off with but the trader may adjust the period number to whatever extent they deem fit.

## Installing the Linear Regression Channel Indicator For MT5

After you downloaded the indicator via the form above you need to unzip the zip-file. Then you need to copy the file lrchannel.mq5 into the folder MQL5\Indicators of your MT5 installation. After that please restart MT5 and then you will be able to see the indicator in the list of indicators.

## Parameters of the Linear Regression Channel Indicator For MT5

The Linear Regression Channel Indicator For MT5 has 1 parameters to configure.

`input int InChPeriod = 150; //Channel Period `

## Buffers of the Linear Regression Channel Indicator For MT5

The Linear Regression Channel Indicator For MT5 provides 5 buffers.

`SetIndexBuffer(0,rlBuffer,INDICATOR_DATA); SetIndexBuffer(1,upBuffer,INDICATOR_DATA); SetIndexBuffer(2,downBuffer,INDICATOR_DATA); SetIndexBuffer(3,highBuffer,INDICATOR_DATA); SetIndexBuffer(4,lowBuffer,INDICATOR_DATA); `

## Main Parts Of The Code

`int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { double sumX,sumY,sumXY,sumX2,a,b,F,S; int X; //--- check for bars count if(rates_total lt ExChPeriod+1)return(0); //--- if new bar set, calculate if(rCount!=rates_total) { PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,rates_total-ExChPeriod-1); //--- calculate coefficient a and b of equation linear regression F=0.0; S=0.0; sumX=0.0; sumY=0.0; sumXY=0.0; sumX2=0.0; X=0; for(int i=rates_total-1-ExChPeriod;i lt rates_total-1;i++) { sumX+=X; sumY+=price[i]; sumXY+=X*price[i]; sumX2+=MathPow(X,2); X++; } a=(sumX*sumY-ExChPeriod*sumXY)/(MathPow(sumX,2)-ExChPeriod*sumX2); b=(sumY-a*sumX)/ExChPeriod; //--- calculate values of main line and error F X=0; for(int i=rates_total-1-ExChPeriod;i lt rates_total;i++) { rlBuffer[i]=b+a*X; F+=MathPow(price[i]-rlBuffer[i],2); X++; } //--- calculate deviation S S=NormalizeDouble(MathSqrt(F/(ExChPeriod+1))/MathCos(MathArctan(a*M_PI/180)*M_PI/180),_Digits); //--- calculate values of last buffers for(int i=rates_total-1-ExChPeriod;i lt rates_total;i++) { upBuffer[i]=rlBuffer[i]+S; downBuffer[i]=rlBuffer[i]-S; highBuffer[i]=rlBuffer[i]+2*S; lowBuffer[i]=rlBuffer[i]-2*S; } rCount=rates_total; } return(rates_total); } //+------------------------------------------------------------------+ `