//+------------------------------------------------------------------+ //| NonLagMA_v2.mq4 | //| Copyright © 2006, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, TrendLaboratory" #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Orange //---- input parameters extern int Price = 0; extern int Len = 39; extern double Cycle = 4; extern int Phase = 2; extern double Level = 0.3; extern double Coeff = 7; //---- indicator buffers double MABuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- indicator line SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,MABuffer); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //---- name for DataWindow and indicator subwindow label short_name="NonLagMA("+Len+")"; IndicatorShortName(short_name); SetIndexLabel(0,"NLMA"); //---- SetIndexDrawBegin(0,Len); //---- return(0); } //+------------------------------------------------------------------+ //| NonLagMA_v2 | //+------------------------------------------------------------------+ int start() { int i,shift, counted_bars=IndicatorCounted(),limit, num; double alfa, beta, t, AvgRange,Weight, step,step1,g; double pi = 3.1415926535; if ( counted_bars > 0 ) limit=Bars-counted_bars; if ( counted_bars < 0 ) return(0); if ( counted_bars ==0 ) limit=Bars-Len-1; step = 2.0*Cycle/(Len-1); num = MathRound((Len-1)/(2.0*Cycle))+Phase; for(shift=limit;shift>=0;shift--) { Weight=0;AvgRange=0; for (i=0;i<=Len-1;i++) { if ( i <= num ) step = 1.0/num; else step = (2.0*Cycle-1)/(Len-1-num); t = i*step; g = 1.0/(Coeff*t+1); if (g > Level ) g = 1; beta = MathSin(pi*(t + 0.5)); alfa = g * beta; AvgRange = AvgRange + alfa*iMA(NULL,0,1,0,MODE_SMA,Price,shift+i); Weight =Weight + alfa; } if (Weight > 0) MABuffer[shift]=AvgRange/Weight; } return(0); }