//+------------------------------------------------------------------+ //| Kaufman Adaptive Moving Average.mq4 | //| | //| | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 LightSeaGreen //---- input parameters extern int periodAMA=20; //extern int nfast=2; //extern int nslow=30; //---- buffers double kAMAbuffer[]; double dSC,slowSC,fastSC; double noise,signal,ER; double ERSC,wlxSSC; bool fc; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,kAMAbuffer); IndicatorDigits(6); SetIndexLabel(0,"KAMA"); SetIndexDrawBegin(0,periodAMA); slowSC=(2.0 /(30+1)); fastSC=(2.0 /(2+1)); dSC=(fastSC-slowSC); fc=true; //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i, pos=1, cbars=IndicatorCounted(); if (Bars<=periodAMA+2) return(0); if(cbars<0) return(-1); if (cbars>0) cbars--; if (fc==true) { pos=(Bars-periodAMA-cbars); kAMAbuffer[pos+1]=(High[pos+1]+Low[pos+1])/2; } else pos=Bars-cbars; while (pos>=0) { signal=MathAbs(((High[pos]+Low[pos])/2)-((High[pos+periodAMA]+Low[pos+periodAMA])/2)); noise=0; for(i=0;i