//+------------------------------------------------------------------+ //| Vidya.mq4 | //| Copyright © 2006, Amritend Maji | //+------------------------------------------------------------------+ #property copyright "Copyright © 2006, Amritendu Maji" #property link "None" //---- indicator settings #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Black #property indicator_width1 1 //---- indicator parameters extern int Periods=21; extern double SmoothConst=9; //---- indicator buffers double e0[]; double e1[]; double SC; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(2); //---- drawing settings SetIndexStyle(0,DRAW_LINE); SetIndexDrawBegin(0,Periods); if( !SetIndexBuffer(0,e0) && !SetIndexBuffer(1,e1) ) Print("cannot set indicator buffers!"); //---- name for DataWindow and indicator subwindow label IndicatorShortName("VIDYA("+Periods+")"); SC = 2/(SmoothConst+1); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Average | //+------------------------------------------------------------------+ int start() { int i,j,limit; double day, upday, downday; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars > 0) counted_bars --; if (counted_bars == 0) limit = Bars - Periods; else limit = Bars-counted_bars; //---- main loop for(i=limit; i>=0; i--) { upday = 0; downday = 0; for (j=0; j 0) upday += day; if(day < 0) downday -= day; } e1[i] = MathAbs((upday-downday)/(upday+downday)); e0[i]= SC*e1[i]*Close[i] + (1-SC*e1[i])*e0[i+1]; } //---- done return(0); } //+------------------------------------------------------------------+