//+------------------------------------------------------------------+ //| Custom Moving Average.mq4 | //| Copyright © 2004, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #property copyright "Copyright © 2004, MetaQuotes Software Corp." #property link "http://www.metaquotes.net/" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //---- indicator parameters extern int Price_Mode=0; extern int MA_Period=13; extern int CountTick=100; extern bool DrawAll=false; //---- indicator buffers double ExtMapBuffer[]; int ExtCountedBars=0; double Price[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; SetIndexStyle(0,DRAW_SECTION); short_name="SMA("; IndicatorShortName(short_name+MA_Period+")"); SetIndexBuffer(0,ExtMapBuffer); ArrayResize(Price,MA_Period); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int limit; int counted_bars=IndicatorCounted(); int i, pos; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; for (i = limit;i>=0;i--){ PriceArray(Price,i); sma(i); } return(0); } bool PriceArray(double &Price[], int pos){ int i,shift; shift=0; for (i=0;iBars-ExtCountedBars) pos=Bars-ExtCountedBars; while(pos>=0) { if(pos==Bars-MA_Period) { //---- initial accumulation for(i=0,k=pos;i=0) { ExtMapBuffer[pos]=sum/weight; if(pos==0) break; pos--; i--; price=Close[pos]; sum=sum-lsum+price*MA_Period; lsum-=Close[i]; lsum+=price; } //---- zero initial bars if(ExtCountedBars<1) for(i=1;i