//+--------------------------------------------------------------------------------------------------+ //| b_Kaufman_Efficiency_Ratio_STD.mq4 | //| Copyright © 2011, barmenteros | //| http://www.mql4.com/users/barmenteros | //+--------------------------------------------------------------------------------------------------+ #property copyright "barmenteros" #property link "barmenteros.fx@gmail.com" #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 1 #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 DeepPink #property indicator_width1 1 #property indicator_width2 2 // ---- inputs // ERperiod It should be >0. If not it will be autoset to default value // histogram [true] - histogram style on; [false] - histogram style off extern int ERperiod =20; // Efficiency ratio period extern bool histogram =false; // Histogram switch extern int shift =0; // Sets offset extern int STDDouble =2; // Sets Standard double extern int STDperiod =100; // Efficiency ratio Standard period // ---- buffers double ERBfr[]; double ERBfrSTD[]; // ---- global variables double direction, noise; //+--------------------------------------------------------------------------------------------------+ //| Custom indicator initialization function | //+--------------------------------------------------------------------------------------------------+ int init() { string short_name; // ---- checking inputs if(ERperiod<=0) { ERperiod=10; Alert("ERperiod readjusted"); } // ---- drawing settings if(!histogram) SetIndexStyle(0,DRAW_LINE); else SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,"KEffRatio"); SetIndexShift(0,shift); SetIndexStyle(1,DRAW_LINE); SetIndexLabel(1,"KEffRatioSTD"); SetIndexShift(1,shift); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); short_name="KEffRatioSTD("; IndicatorShortName(short_name+ERperiod+","+STDDouble+")"); // ---- mapping SetIndexBuffer(0,ERBfr); SetIndexBuffer(1,ERBfrSTD); if(STDDouble<1) STDDouble=1; if(STDperiod0) counted_bars--; limit=Bars-counted_bars-1; maxbar=Bars-1-ERperiod; if(limit>maxbar) limit=maxbar; // ---- main cycle for(i=limit; i>=0; i--) { direction=NetPriceMovement(i); noise=Volatility(i); if(direction==EMPTY_VALUE || noise==EMPTY_VALUE) continue; if(noise==0.0) noise=0.000000001; ERBfr[i]=direction/noise; } // ---- STD cycle for(i=limit; i>=0; i--) { ERBfrSTD[i] = iStdDevOnArray(ERBfr, 0, STDperiod, 0, MODE_SMA, i)*STDDouble; } // ---- return(0); } double NetPriceMovement(int initialbar) { if(initialbar>Bars-ERperiod-1) return(EMPTY_VALUE); double n; n=MathAbs(Close[initialbar]-Close[initialbar+ERperiod]); return(n); } double Volatility(int initialbar) { if(initialbar>Bars-ERperiod-1) return(EMPTY_VALUE); int j; double v=0.0; for(j=0; j