//+------------------------------------------------------------------+ //| SerialMA.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 3 #property indicator_plots 2 //--- plot MA #property indicator_label1 "MA" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Point #property indicator_label2 "Point" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- indicator buffers double BufferMA[]; double BufferPoint[]; double BufferTime[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,BufferMA,INDICATOR_DATA); SetIndexBuffer(1,BufferPoint,INDICATOR_DATA); SetIndexBuffer(2,BufferTime,INDICATOR_CALCULATIONS); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(1,PLOT_ARROW,159); //--- settings indicators parameters IndicatorSetInteger(INDICATOR_DIGITS,Digits()); IndicatorSetString(INDICATOR_SHORTNAME,"Serial MA"); //--- setting buffer arrays as timeseries ArraySetAsSeries(BufferMA,true); ArraySetAsSeries(BufferPoint,true); ArraySetAsSeries(BufferTime,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- Проверка на минимальное количество баров для расчёта if(rates_total<3) return 0; //--- Установка индексации массивов как у таймсерий ArraySetAsSeries(close,true); ArraySetAsSeries(time,true); //--- Проверка и расчёт количества просчитываемых баров int total=rates_total-2,limit=rates_total-prev_calculated; if(limit>1) { limit=total; ArrayInitialize(BufferMA,EMPTY_VALUE); ArrayInitialize(BufferPoint,EMPTY_VALUE); ArrayInitialize(BufferTime,EMPTY_VALUE); } //--- Расчёт индикатора for(int i=limit; i>=0 && !IsStopped(); i--) { if(i==total) BufferTime[i]=(double)time[i]; else { BufferTime[i]=BufferTime[i+1]; int period_ma=BarShift(Symbol(),PERIOD_CURRENT,(datetime)BufferTime[i])-i+1; double summ=0; for(int n=0; nlast_bar) res=0; else { const int shift=::Bars(Symbol(),timeframe,time,last_bar); if(shift>0) res=shift-1; } } return(res); } //+------------------------------------------------------------------+