//+------------------------------------------------------------------+ //| MultiMovingAverage.mq4 | //+------------------------------------------------------------------+ #property copyright "Ron T" #property link "http://www.lightpatch.com" #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 White //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; //---- int ExtCountedBars=0; //---- indicator parameters extern int MA_Period=13; extern int Plot_Character=159; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //|------------------------------------------------------------------| int init() { //---- indicators // SetIndexStyle(0,DRAW_ARROW, 0, 1, Red); SetIndexStyle(0,DRAW_ARROW); SetIndexBuffer(0, ExtMapBuffer1); SetIndexArrow(0,Plot_Character); // SetIndexStyle(1,DRAW_ARROW, 0, 1, White); SetIndexStyle(1,DRAW_ARROW); SetIndexBuffer(1, ExtMapBuffer2); SetIndexArrow(1,Plot_Character); //---- SetIndexDrawBegin(0,10); SetIndexDrawBegin(1,10); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer1); SetIndexBuffer(1,ExtMapBuffer2); if(MA_Period<2) MA_Period=13; //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { double sum=0; double oldsum=0; int i; int pos=Bars-ExtCountedBars-1; //---- initial accumulation if(pos0) ExtCountedBars--; //---- main calculation loop while(pos>=0) { oldsum=sum; // add in the leading value to make MA_Period samples sum+=Close[pos]; if(oldsum/(MA_Period-1) > sum/MA_Period) { ExtMapBuffer1[pos]=sum/MA_Period; ExtMapBuffer2[pos]=0; } else { ExtMapBuffer1[pos]=0; ExtMapBuffer2[pos]=sum/MA_Period; } // remove the trailing period to make MA_Period-1 samples sum-=Close[pos+MA_Period-1]; pos--; } //---- zero initial bars if(ExtCountedBars<1) for(i=1;i