Нужна помощь в переделке индикатора (в место стандартной синусойды отрисовывает прямоугольную синусойду)

 

Должно быть вот так (мт4)

вот сам рабочий код (мт4)

//+------------------------------------------------------------------+
//|                                                 Palpite_MACD.mq4 |
//|                                        Copyright © 2016, Palpite |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Palpite"
#property link      ""

#property indicator_separate_window
#property indicator_height  150
#property indicator_buffers 4
#property indicator_color1  Red
#property indicator_color2  ForestGreen
#property indicator_color3  Yellow
#property indicator_color4  Cyan
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
//---- input parameters
extern int FastMAPeriod   = 12, 
           SlowMAPeriod   = 26,
           SignalMAPeriod = 9;
//---- buffers
double     MACDLineBuffer[],
           SignalLineBuffer[],
           HistogramBuffer[],
           HistogramBuffer1[],
           Signal,
           Signal_1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorDigits(Digits + 1);
   //---- indicators
   SetIndexStyle (0, DRAW_HISTOGRAM);        SetIndexBuffer   (0, HistogramBuffer) ; SetIndexLabel(0, "Histo");SetLevelValue(0, 0);SetLevelStyle(STYLE_DOT,1,DimGray);
   SetIndexStyle (1, DRAW_HISTOGRAM);        SetIndexBuffer   (1, HistogramBuffer1); SetIndexLabel(1, "Histo1");
   SetIndexStyle (2, DRAW_LINE, STYLE_SOLID);SetIndexDrawBegin(2, SlowMAPeriod)     ;SetIndexBuffer(2, MACDLineBuffer);
   SetIndexBuffer(3, SignalLineBuffer)      ;SetIndexDrawBegin(3, SlowMAPeriod - SignalMAPeriod); SetIndexLabel(3, "Signal");
   IndicatorShortName("   Palpite_MACD   (" + FastMAPeriod+" , " + SlowMAPeriod + " , " + SignalMAPeriod + ")");
   //----
        Signal   = 1.5 / (SignalMAPeriod - 1.0);
        Signal_1 = 1.0 - Signal;
   //----
   return(Digits);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   //----
   return(1);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
   //---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
//----
   double value=0;
   for(int i = limit; i >= 0; i--)
     {
       MACDLineBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i) - iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA, PRICE_CLOSE, i);
       SignalLineBuffer[i]= Signal*MACDLineBuffer[i] + Signal_1*SignalLineBuffer[i+1];    
         HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i]/100;
         HistogramBuffer1[i] = HistogramBuffer[i];
         if (value>SignalLineBuffer[i] - MACDLineBuffer[i]) HistogramBuffer[i]=value;
         if (value<SignalLineBuffer[i] - MACDLineBuffer[i]) HistogramBuffer1[i]=value;
     }
//----
   return(counted_bars);
  }

вот, что у меня получается в мт5

вот код в мт5

//+------------------------------------------------------------------+
//|                                                 Palpite_MACD.mq5 |
//|                                        Copyright © 2016, Palpite |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Palpite"
#property link      ""

#property indicator_separate_window
//#property indicator_height  150
#property indicator_buffers  5
#property indicator_plots   3
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  Red
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_type2   DRAW_HISTOGRAM2
#property indicator_color2  ForestGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1

#property indicator_color2  ForestGreen
#property indicator_type2   DRAW_LINE
#property indicator_color3  Yellow
#property indicator_type3   DRAW_LINE
#property indicator_color4  Cyan

#property indicator_width3 1
#property indicator_width4 1
//---- input parameters
input int  FastMAPeriod   = 12,//InpPeriodFastMA 
           SlowMAPeriod   = 26,// InpPeriodSlowMA 
           SignalMAPeriod = 9;//InpPeriodSignal 
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // Applied price
           
//---- buffers
double     MACDLineBuffer[],//BufferMACD
           SignalLineBuffer[],//BufferSignal
           HistogramBuffer[],// BufferHistogram
           HistogramBuffer1[],
           Signal,
           Signal_1;
 
int            period_fma;
int            period_sma;
int            period_sig;
int            period_max;
int            handle_ma;
 
           
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
  
 //--- set global variables
   period_fma=int(FastMAPeriod<1 ? 1 : FastMAPeriod);
   period_sma=int(SlowMAPeriod==period_fma ? period_fma+1 : SlowMAPeriod<1 ? 1 : SlowMAPeriod);
   period_sig=int(SignalMAPeriod<1 ? 1 : SignalMAPeriod);
   period_max=fmax(period_sig,fmax(period_fma,period_sma)); 
  
  // IndicatorDigits(Digits + 1);
 IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- indicators
   //SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0,HistogramBuffer,INDICATOR_DATA);
  // SetIndexLabel(0, "Histo");
   PlotIndexSetString(0,PLOT_LABEL,"Histo");
  // SetLevelValue(0, 0);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE, 0.0);
   //SetLevelStyle(STYLE_DOT,1,DimGray);
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DOT);//SetLevelStyle(STYLE_DOT,1,DimGray);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,DimGray);  //SetLevelStyle(STYLE_DOT,1,DimGray);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);  //SetLevelStyle(STYLE_DOT,1,DimGray);
   //SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, HistogramBuffer1,INDICATOR_DATA);
   // SetIndexLabel(1, "Histo1");
   PlotIndexSetString(1,PLOT_LABEL,"Histo1");
      //SetIndexStyle(2, DRAW_LINE, STYLE_SOLID);
   //SetIndexDrawBegin(2, SlowMAPeriod);
     PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,SlowMAPeriod);

   SetIndexBuffer(2, MACDLineBuffer);
   SetIndexBuffer(3, SignalLineBuffer);
  // SetIndexDrawBegin(3, SlowMAPeriod - SignalMAPeriod);
   PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,SlowMAPeriod - SignalMAPeriod);
     // SetIndexLabel(3, "Signal");
         PlotIndexSetString(3,PLOT_LABEL,"Signal");
   IndicatorSetString(INDICATOR_SHORTNAME,"Palpite_MACD ("+string(FastMAPeriod)+","+string(SlowMAPeriod)+","+string(SignalMAPeriod)+")");

//----
  Signal   = 1.5 / (SignalMAPeriod - 1.0);
  Signal_1 = 1.0 - Signal;

//----
 
  }



//+------------------------------------------------------------------+
//| 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[])
  {
 //--- Установка массивов буферов как таймсерий
   ArraySetAsSeries(tick_volume,true);
//--- Проверка и расчёт количества просчитываемых баров
   if(rates_total<period_max) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int limit=rates_total-prev_calculated;
   if(limit>1)
     {
      limit=rates_total-period_max-2;
      ArrayInitialize(MACDLineBuffer,0);
      ArrayInitialize(SignalLineBuffer,0);
      ArrayInitialize(HistogramBuffer,0);
      ArrayInitialize(HistogramBuffer1,0);
     }
//----
   double value=0;
   for(int i = limit; i >= 0; i--)
     {
      MACDLineBuffer[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA,InpAppliedPrice) - iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA,InpAppliedPrice);
       SignalLineBuffer[i]= Signal*MACDLineBuffer[i] + Signal_1*SignalLineBuffer[i+1];    
         HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i]/100;
         HistogramBuffer1[i] = HistogramBuffer[i];
         if (value>SignalLineBuffer[i] - MACDLineBuffer[i]) HistogramBuffer[i]=value;
         if (value<SignalLineBuffer[i] - MACDLineBuffer[i]) HistogramBuffer1[i]=value;
     }
//----
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Игорь:

Должно быть вот так (мт4)

вот сам рабочий код (мт4)

вот, что у меня получается в мт5

вот код в мт5

В МТ5 iMA возвращает хендл индикатора, а не значения. И должно использоваться в функции OnInit. А в функции OnCalculate используем CopyBuffer

 
Dmitriy Gizlyk #:

В МТ5 iMA возвращает хендл индикатора, а не значения. И должно использоваться в функции OnInit. А в функции OnCalculate используем CopyBuffer

код стал править "и началось в колхозе утро")

//+------------------------------------------------------------------+
//|                                                 Palpite_MACD.mq5 |
//|                                        Copyright © 2016, Palpite |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Palpite"
#property link      ""
#property indicator_separate_window
#property indicator_height  150
#property indicator_buffers  5
#property indicator_plots    3
//--- plot MACD
#property indicator_label1  "MACD"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrForestGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Signal
#property indicator_label2  "MACD"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrYellow
#property indicator_style2  STYLE_DOT
#property indicator_width2  1
//--- plot Histogram
#property indicator_label3  "Histogram"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  clrGreen
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2
//---- input parameters
input int  FastMAPeriod   = 12,//FastMAPeriod 
           SlowMAPeriod   = 26,// SlowMAPeriod 
           SignalMAPeriod = 9;//SignalMAPeriod 
input ENUM_APPLIED_PRICE   InpAppliedPrice   =  PRICE_CLOSE;   // Applied price    
//---- buffers
double         BufferMACD[];
double         BufferSignal[];
double         BufferHistogram[];
double         BufferHistogram1[];
double         BufferColors[];
double         BufferMA[];

double         Signal,
               Signal_1;
//--- global variables
int            period_fma;
int            period_sma;
int            period_sig;
int            period_max;
int            handle_ma;
           
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
 //--- set global variables
   period_fma=int(FastMAPeriod<1 ? 1 : FastMAPeriod);
   period_sma=int(SlowMAPeriod==period_fma ? period_fma+1 : SlowMAPeriod<1 ? 1 : SlowMAPeriod);
   period_sig=int(SignalMAPeriod<1 ? 1 : SignalMAPeriod);
   period_max=fmax(period_sig,fmax(period_fma,period_sma));
  //--- indicator buffers mapping
   SetIndexBuffer(0,BufferMACD,INDICATOR_DATA);
   SetIndexBuffer(1,BufferSignal,INDICATOR_DATA);
   SetIndexBuffer(2,BufferHistogram,INDICATOR_DATA);
   SetIndexBuffer(3,BufferColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(4,BufferMA,INDICATOR_CALCULATIONS);
//--- setting indicator parameters
   IndicatorSetString(INDICATOR_SHORTNAME,"VAMA MACD ("+(string)period_fma+","+(string)period_sma+","+(string)period_sig+")");
   IndicatorSetInteger(INDICATOR_DIGITS,Digits());
//--- setting plot buffer parameters
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
//--- setting buffer arrays as timeseries
   ArraySetAsSeries(BufferMACD,true);
   ArraySetAsSeries(BufferSignal,true);
   ArraySetAsSeries(BufferHistogram,true);
   ArraySetAsSeries(BufferColors,true);
   ArraySetAsSeries(BufferMA,true);
//--- create MA's handles
   ResetLastError();
   handle_ma=iMA(NULL,PERIOD_CURRENT,1,0,MODE_SMA,InpAppliedPrice);
   if(handle_ma==INVALID_HANDLE)
     {
      Print("The iMA(1) object was not created: Error ",GetLastError());
      
     }
//---
  
  }
//+------------------------------------------------------------------+
//| 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[])
  {
 //--- Установка массивов буферов как таймсерий
   ArraySetAsSeries(tick_volume,true);
//--- Проверка и расчёт количества просчитываемых баров
   if(rates_total<SignalMAPeriod) return 0;
//--- Проверка и расчёт количества просчитываемых баров
   int calculated=BarsCalculated(ExtFastMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtSlowMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data ; мы можем скопировать не все данные
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//--- get Fast EMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer
   if(IsStopped()) return(0); //Checking for stop flag
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error",GetLastError());
      return(0);
     }
   
     int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
     {
      limit=rates_total-period_max-2;
      ArrayInitialize(BufferMACD,0);
      ArrayInitialize(BufferSignal,0);
      ArrayInitialize(BufferHistogram,0);
      ArrayInitialize(BufferMA,0);
     }
   
//----
   double value=0;
   for(int i = limit; i >= 0; i--)
     {
      BufferMACD[i] = iMA(NULL, 0, FastMAPeriod, 0, MODE_EMA,InpAppliedPrice) - iMA(NULL, 0, SlowMAPeriod, 0, MODE_EMA,InpAppliedPrice);
       BufferSignal[i]= Signal*BufferMACD[i] + Signal_1*BufferSignal[i+1];    
         BufferHistogram[i] = BufferMACD[i] - BufferSignal[i]/100;
         BufferHistogram1[i] = BufferHistogram[i];
         if (value>BufferSignal[i] - BufferMACD[i]) BufferHistogram[i]=value;
         if (value<BufferSignal[i] - BufferMACD[i]) BufferHistogram1[i]=value;
     }
//----
   return(rates_total);
  }
//+------------------------------------------------------------------+

Люди пните меня в нужном направленнн).

 
Люди если не трудно, посмотрите, всё у меня в порядке в этом куске кода.
#property copyright "Copyright © 2005, Palpite"
#property link      ""
#include <MovingAverages.mqh>
#property indicator_separate_window
//#property indicator_height  150
#property indicator_buffers 6
#property indicator_plots   4
//--- plot MACD
#property indicator_type1   DRAW_LINE
#property indicator_color1  White
#property indicator_width1  1
#property indicator_label1  "DIFF"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Yellow
#property indicator_width2  1
#property indicator_label2  "DEA"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  Red
#property indicator_width3  1
#property indicator_label3  "MACD"
#property indicator_type4   DRAW_HISTOGRAM
#property indicator_color4  Turquoise
#property indicator_width4  1
#property indicator_label4  "MACD"
//---- input parameters
input int  FastMAPeriod   = 12,//FastMAPeriod 
           SlowMAPeriod   = 26,//SlowMAPeriod
           SignalMAPeriod = 9;//SignalMAPeriod 
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//---- buffers
double                   ExtDIFFBuffer[];
double                   ExtDEABuffer[];
double                   ExtMACDRBuffer[];
double                   ExtMACDGBuffer[];
double                   ExtFastMaBuffer[];
double                   ExtSlowMaBuffer[];
//--- MA handles
int                      ExtFastMaHandle;
int                      ExtSlowMaHandle; 
int            period_fma;
int            period_sma;
int            period_sig;
int            period_max;
int            handle_ma;
 
           
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
  
 //--- set global variables
   period_fma=int(FastMAPeriod<1 ? 1 : FastMAPeriod);
   period_sma=int(SlowMAPeriod==period_fma ? period_fma+1 : SlowMAPeriod<1 ? 1 : SlowMAPeriod);
   period_sig=int(SignalMAPeriod<1 ? 1 : SignalMAPeriod);
   period_max=fmax(period_sig,fmax(period_fma,period_sma)); 
  
  // IndicatorDigits(Digits + 1);
 IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- indicators
  SetIndexBuffer(0,ExtDIFFBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtDEABuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtMACDRBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtMACDGBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,SignalMAPeriod-1);              // New
//--- name for Dindicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD_DL("+string(FastMAPeriod)+","+string(SlowMAPeriod)+","+string(SignalMAPeriod)+")");
//--- get MA handles
   ExtFastMaHandle=iMA(NULL,0,FastMAPeriod,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,InpAppliedPrice);
  }
 

Ну всё код подправил ошибок и предупреждений нет. Однако выявил разницу в отрисовки индикатора.

должно быть так


после переделки на мт5, выглядит так

вот сам код (возможны ошибки по логике)

//+------------------------------------------------------------------+
//|                                                 Palpite_MACD.mq5 |
//|                                        Copyright © 2016, Palpite |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Palpite"
#property link      ""
#include <MovingAverages.mqh>
#property indicator_separate_window
//#property indicator_height  150
#property indicator_buffers 6
#property indicator_plots   4
//--- plot MACD
#property indicator_type1   DRAW_LINE
#property indicator_color1  White
#property indicator_width1  1
#property indicator_label1  "DIFF"
#property indicator_type2   DRAW_LINE
#property indicator_color2  Yellow
#property indicator_width2  1
#property indicator_label2  "DEA"
#property indicator_type3   DRAW_HISTOGRAM
#property indicator_color3  Red
#property indicator_width3  1
#property indicator_label3  "MACD"
#property indicator_type4   DRAW_HISTOGRAM
#property indicator_color4  Turquoise
#property indicator_width4  1
#property indicator_label4  "MACD"
//---- input parameters
input int  FastMAPeriod   = 12,//FastMAPeriod 
           SlowMAPeriod   = 26,//InpSlowEMA
           SignalMAPeriod = 9;//SlowMAPeriod 
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//---- buffers
double                   ExtDIFFBuffer[];
double                   ExtDEABuffer[];
double                   ExtMACDRBuffer[];
double                   ExtMACDGBuffer[];
double                   ExtFastMaBuffer[];
double                   ExtSlowMaBuffer[];
//--- MA handles
int                      ExtFastMaHandle;
int                      ExtSlowMaHandle; 
int            period_fma;
int            period_sma;
int            period_sig;
int            period_max;
int            handle_ma;
 
           
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
  
 //--- set global variables
   period_fma=int(FastMAPeriod<1 ? 1 : FastMAPeriod);
   period_sma=int(SlowMAPeriod==period_fma ? period_fma+1 : SlowMAPeriod<1 ? 1 : SlowMAPeriod);
   period_sig=int(SignalMAPeriod<1 ? 1 : SignalMAPeriod);
   period_max=fmax(period_sig,fmax(period_fma,period_sma)); 
  
  // IndicatorDigits(Digits + 1);
 IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//---- indicators
  SetIndexBuffer(0,ExtDIFFBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtDEABuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtMACDRBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtMACDGBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,SignalMAPeriod-1);              // New
//--- name for Dindicator subwindow label
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD_DL("+string(FastMAPeriod)+","+string(SlowMAPeriod)+","+string(SignalMAPeriod)+")");
//--- get MA handles
   ExtFastMaHandle=iMA(NULL,0,FastMAPeriod,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,InpAppliedPrice);
  }

//+------------------------------------------------------------------+
//| 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 &TickVolume[],
                const long &Volume[],
                const int &Spread[])
  {
//--- check for data //проверка наличия данных
   if(rates_total<SlowMAPeriod)
      return(0);
//--- not all data may be calculated //не все данные могут быть рассчитаны
   int calculated=BarsCalculated(ExtFastMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtFastMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
   calculated=BarsCalculated(ExtSlowMaHandle);
   if(calculated<rates_total)
     {
      Print("Not all data of ExtSlowMaHandle is calculated (",calculated,"bars ). Error",GetLastError());
      return(0);
     }
//--- we can copy not all data //мы можем скопировать не все данные
   int to_copy;
   if(prev_calculated>rates_total || prev_calculated<0) to_copy=rates_total;
   else
     {
      to_copy=rates_total-prev_calculated;
      if(prev_calculated>0) to_copy++;
     }
//--- get Fast EMA buffer //получите быстрый буфер EMA
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer //получить буфер SlowSMA
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error",GetLastError());
      return(0);
     }
//---
   int limit;
   if(prev_calculated==0)
      limit=0;
   else limit=prev_calculated-1;
//--- calculate DIFF //вычислить РАЗНИЦУ
   for(int i=limit;i<rates_total;i++)
      ExtDIFFBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
//--- calculate DEA  //рассчитать DEA
   SimpleMAOnBuffer(rates_total,prev_calculated,0,SlowMAPeriod,ExtDIFFBuffer,ExtDEABuffer);
//--- calculate MACD  //рассчитать MACD
   for(int i=limit;i<rates_total;i++)
   {
      if(ExtDIFFBuffer[i] > ExtDEABuffer[i]) 
      {
          ExtMACDRBuffer[i] = 2*(ExtDIFFBuffer[i]-ExtDEABuffer[i]); 
          ExtMACDGBuffer[i] = 0;
      }
      else
      {
          ExtMACDGBuffer[i] = 2*(ExtDIFFBuffer[i]-ExtDEABuffer[i]); 
          ExtMACDRBuffer[i] = 0;
      }
   }      
//--- OnCalculate done. Return new prev_calculated. //На расчетном. Возвращает новый prev_calculated.
   return(rates_total);
  }
//+----------------------------