//+------------------------------------------------------------------+ //| +MA | //| programming & support - Alexey Sergeev (profy.mql@gmail.com) | //| 1.04 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Alexey Sergeev" #property link "profy.mql@gmail.com" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 LimeGreen extern int TF=240; // таймфрейм extern int PeriodMA=14; // период МА extern int MethodMA=0; // метод МА extern int PriceMA=0; // цена МА extern bool ShowSimple=false; // double MA[],PR[]; datetime last=0; //------------------------------------------------------------------ init void init() { SetIndexBuffer(0,MA); SetIndexStyle(0,DRAW_LINE); SetIndexLabel(0,"MA"); IndicatorShortName("MA("+PeriodMA+")"); ArrayResize(PR,PeriodMA+1); ArraySetAsSeries(PR,true); if(TF0) counted_bars--; int limit=Bars-counted_bars; if(counted_bars==0) limit-=1+PeriodMA; if(counted_bars<=0) for(int i=1; i<=PeriodMA; i++) MA[limit-i]=EMPTY_VALUE; for(i=limit-1; i>=0; i--) { int b=iBarShift(smb,TF,Time[i]); // бар текущего времени младшего на старшем ТФ if(last!=iTime(smb,TF,b)) // если это новый бар { last=iTime(smb,TF,b); for(int j=PeriodMA-1; j>=0; j--) PR[j]=GetPrice(smb,TF,b+j,PriceMA); // сместили бары на новые } if(!ShowSimple) PR[0]=GetPrice(smb,Period(),i,PriceMA); // обновили текущий бар MA[i]=iMAOnArray(PR,0,PeriodMA,0,MethodMA,0); // расчитали МА } } //------------------------------------------------------------------ double GetPrice(string smb,int tf,int i,int price) { if(price==PRICE_CLOSE) return(iClose(smb,tf,i)); if(price==PRICE_OPEN) return(iOpen(smb, tf, i)); if(price==PRICE_HIGH) return(iHigh(smb, tf, i)); if(price==PRICE_LOW) return(iLow(smb,tf,i)); if(price==PRICE_MEDIAN) return((iHigh(smb,tf,i)+iLow(smb,tf,i))/2); if(price==PRICE_TYPICAL) return((iHigh(smb,tf,i)+iLow(smb,tf,i)+iClose(smb,tf,i))/3); if(price==PRICE_WEIGHTED) return((iHigh(smb,tf,i)+iLow(smb,tf,i)+iClose(smb,tf,i)+iClose(smb,tf,i))/4); } //+------------------------------------------------------------------+