Нужна помощь (неправильно отрисовывает переднланный Palpite_MACD под мт5, ошибок нет). - страница 2

 
Игорь:

Привет всем. Люди помогите поправить код в переделанном индикаторе под мт5. Переделал интересный индикатор Palpite_MACD под мт4.

Вот его исходный код

в мт4 он выглядит вот так


Вот переделанный мною код под мт5

Вот что данный код отрисовывает в мт5


А Вы этот код просмотрите https://www.mql5.com/ru/code/33272 и может как то, сообразите как переделать свой.

MACD Four Colors
MACD Four Colors
  • www.mql5.com
Индикатор iMACD (Moving Average Convergence/Divergence, MACD) - гистограмма в четырёх цветах
 

вот я что то попытался нахимичить 

//+------------------------------------------------------------------+
//|                                                 Palpite_MACD.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property description "Moving Average Convergence/Divergence"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   2
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_color1  clrAqua,clrDeepPink,clrDarkGray
#property indicator_color2  clrRed
#property indicator_width1  2
#property indicator_width2  1
#property indicator_label1  "MACD"
#property indicator_label2  "Signal"
//--- input parameters
input int                InpFastEMA=12;               // Fast EMA period
input int                InpSlowEMA=26;               // Slow EMA period
input int                InpSignalSMA=9;              // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtMacdBuffer[];
double ExtMacdBufferColor[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];

int    ExtFastMaHandle;
int    ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtMacdBufferColor,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for indicator subwindow label
   string short_name=StringFormat("MACD(%d,%d,%d)",InpFastEMA,InpSlowEMA,InpSignalSMA);
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- get MA handles
   ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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<InpSignalSMA)
      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
   if(IsStopped()) // checking for stop flag
      return(0);
   if(CopyBuffer(ExtFastMaHandle,0,0,to_copy,ExtFastMaBuffer)<=0)
     {
      Print("Getting fast EMA is failed! Error ",GetLastError());
      return(0);
     }
//--- get SlowSMA buffer
   if(IsStopped()) // checking for stop flag
      return(0);
   if(CopyBuffer(ExtSlowMaHandle,0,0,to_copy,ExtSlowMaBuffer)<=0)
     {
      Print("Getting slow SMA is failed! Error ",GetLastError());
      return(0);
     }
//---
   int start;
   if(prev_calculated==0)
      start=0;
   else
      start=prev_calculated-1;
//--- calculate MACD
   for(int i=start; i<rates_total && !IsStopped(); i++)
     {
      if(i==rates_total-2)
         ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
      else
        {
         ExtMacdBuffer[i]=ExtFastMaBuffer[i]-ExtSlowMaBuffer[i];
         ExtMacdBufferColor[i]=(ExtMacdBuffer[i]>0 ? 0 : ExtMacdBuffer[i]<0 ? 1 : 2);
        }
     }
//--- calculate Signal
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+

Palpite_MACD

 
SanAlex:

вот я что то попытался нахимичить 


можно ещё вот тут исправить на так вместо нуля вставить ExtSignalBuffer[i]

         ExtMacdBufferColor[i]=(ExtMacdBuffer[i]>ExtSignalBuffer[i] ? 0 : ExtMacdBuffer[i]<ExtSignalBuffer[i] ? 1 : 2);

Palpite_MACD ExtSignalBuffer

 
Vitaly Muzichenko:

У вас есть технически 2 разных индикатора, вот и нужно создавать 2 разных хендла и 2 CopyBuffer. Соответственно нужно по 2 разные переменные


Далее примерно так:

Обращение по начальной позиции и количеству требуемых элементов

int  CopyBuffer(
   int       indicator_handle,   // handle индикатора
   int       buffer_num,           // номер буфера индикатора
   int       start_pos,              // откуда начнем 
   int       count,                   // сколько копируем
   double    buffer[]              // массив, куда будут скопированы данные
   );


В итоге, эта конструкция:

заменяется на такую:

Сейчас попробую

Причина обращения: