Logarithmic Regression Indicator For MT5
Table Of Contents:
- Logarithmic Regression Indicator For MT5
- Installing the Logarithmic Regression Indicator For MT5
- Parameters of the Logarithmic Regression Indicator For MT5
- Buffers of the Logarithmic Regression Indicator For MT5
- Main Parts Of The Code
The Logarithmic Regression Indicator For MT5 draws a price channel based on the logarithmic regression algorithm. The curve of the the channel will adapt according to the direction of the trend. You can configure the indicator by changing the parameters Length, Deviation and Applied Price.
Installing the Logarithmic Regression 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 Logarithmic_Regression.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 Logarithmic Regression Indicator For MT5
The Logarithmic Regression Indicator For MT5 has 3 parameters to configure.
input uint InpLength = 50; // Length input double InpDeviation = 1.0; // Deviation input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price
Buffers of the Logarithmic Regression Indicator For MT5
The Logarithmic Regression Indicator For MT5 provides 4 buffers.
SetIndexBuffer(0,BufferUpper,INDICATOR_DATA); SetIndexBuffer(1,BufferMiddle,INDICATOR_DATA); SetIndexBuffer(2,BufferLower,INDICATOR_DATA); SetIndexBuffer(3,BufferMA,INDICATOR_CALCULATIONS);
Main Parts Of The Code
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- @ gt 25@:0 =0 lt 8=8 lt 0;L= gt 5 : gt ;8G5AB2 gt 10@ gt 2 4;O @0AGQB0 if(rates_total lt length) return 0; //--- @ gt 25@:0 8 @0AGQB : gt ;8G5AB20 ?@ gt AG8BK205 lt KE 10@ gt 2 int limit=rates_total-prev_calculated; if(limit gt 1) { limit=rates_total-1; ArrayInitialize(BufferUpper,EMPTY_VALUE); ArrayInitialize(BufferMiddle,EMPTY_VALUE); ArrayInitialize(BufferLower,EMPTY_VALUE); ArrayInitialize(BufferMA,EMPTY_VALUE); } //--- gt 43 gt B gt 2:0 40==KE int count=(limit==0 ? 1 : rates_total); int copied_ma=CopyBuffer(handle_ma,0,0,count,BufferMA); if(copied_ma!=count) return 0; ArrayInitialize(summ_x_value,0); ArrayInitialize(summ_y_value,0); ArrayInitialize(constant,0); ArrayInitialize(matrix,0); double summ_x=0,summ_y=0,summ=0; summ_x_value[0]=length; for(int exp_n=1; exp_n lt =2; exp_n++) { summ_x=0; summ_y=0; for(int k=1; k lt =length; k++) { double lnx=MathLog(k); summ_x+=MathPow(lnx,exp_n); if(exp_n==1) summ_y+=MathLog(BufferMA[length-k]); else summ_y+=MathLog(BufferMA[length-k])*MathPow(lnx,exp_n-1); } summ_x_value[exp_n]=summ_x; if(summ_y!=0) summ_y_value[exp_n-1]=summ_y; } for(int row=0; row lt =1; row++) for(int col=0; col lt =1; col++) matrix=summ_x_value; //--- summ_y_value[1]=summ_y_value[1]-(matrix[1][0]/matrix[0][0])*summ_y_value[0]; matrix[1][1]=matrix[1][1]-(matrix[1][0]/matrix[0][0])*matrix[0][1]; constant[1]=summ_y_value[1]/matrix[1][1]; double a=(summ_y_value[0]-constant[1]*matrix[0][1])/matrix[0][0]; constant[0]=MathExp(a); //--- 0AGQB 8=48:0B gt @0 int k=1; summ=0; for(int i=length-1;i gt =0;i--) { BufferMiddle[i]=constant[0]*MathPow(k,constant[1]); summ+=MathPow(BufferMA[i]-BufferMiddle[i],2); k++; } BufferMiddle[length]=EMPTY_VALUE; double variance=MathSqrt(summ/length); for(int i=length-1; i gt =0; i--) { BufferUpper[i]=BufferMiddle[i]+deviation*variance; BufferLower[i]=BufferMiddle[i]-deviation*variance; } BufferUpper[length]=EMPTY_VALUE; BufferLower[length]=EMPTY_VALUE; //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+