//+------------------------------------------------------------------+ //| d_MA.mq4 | //| Дмитрий Бургазли | //| dmitriy62@i.ua | //+------------------------------------------------------------------+ #property copyright "Дмитрий Бургазли" #property link "dmitriy62@i.ua" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Magenta //--- input parameters extern int pMA=80; extern int metod=1; extern int cena=0; int expBars=0; int p_ma; //--- buffers double bufMA[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() {p_ma=pMA; //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,bufMA); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+---------------------------------------------------------------+ //|Функция возвращает true, если появиться новый бар, иначе false | //+---------------------------------------------------------------+ bool isNewBar() { bool res=false; if(expBars!=Bars) {expBars=Bars; res=true; } return(res); } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { if (isNewBar()==false) return(0); // если не появился новый бар - выходим //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx int counted_bars=IndicatorCounted(), i; int limit=Bars-counted_bars-1; // Индекс первого непосчитанного double ma1; double ma2; //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+ for(i=limit; i>=0; i--) // Цикл по непосчитанным барам {ma1=iMA(NULL,0,p_ma,0,metod,cena,i+1); ma2=iMA(NULL,0,p_ma,0,metod,cena,i+2); bufMA[i]=iMA(NULL,0,p_ma,0,metod,cena,i); if(Close[i+1]>Close[i+2]) { if( Close[i+1]-ma1 > Close[i+2]-ma2 ) {p_ma=p_ma-1; if(p_ma<2)p_ma=2;} else p_ma=p_ma; } else { p_ma=p_ma; } if(Close[i+1]ma1 && Close[i+2]ma2 ) p_ma=pMA; } //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+ return(0); } //+------------------------------------------------------------------+