in indicator, line draws but arrow does not

 

There's a given MACD indicator, which has 4 buffers and 2 plots ( ExtFastMaHandle and ExtSlowMaHandle don't draw). Now I'm adding another 2 lines (actually 1 histogram and 1 line) and 2 arrows, making it 8 buffers and 6 plots.

The following is my try. In OnCalculate(), with debugging, I found the 2 arrows (only draws when golden cross or death cross of MACD happen) got correct data, it just does not draw. The 2 lines I added work fine, I don't know why arrows stuck.

Could anybody please give me a hand?  (please just keep an eye on 7 and 8, which is uparrow[] and downarrow[])


#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_plots   6
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_type5   DRAW_HISTOGRAM
#property indicator_type6   DRAW_LINE
#property indicator_type7   DRAW_ARROW
#property indicator_type8   DRAW_ARROW
#property indicator_color1  clrGreen
#property indicator_color2  clrWhite
#property indicator_width1  1
#property indicator_width2  1
#property indicator_color5  clrRed
#property indicator_color6  clrYellow
#property indicator_width5  1
#property indicator_width6  1
#property indicator_color7  clrYellow
#property indicator_color8  clrAqua
#property indicator_width7  1
#property indicator_width8  1

//--- 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 ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];


double ExtMacdBufferred[];
double ExtMacdBufferline[];
double uparrow[];
double downarrow[];


int    ExtFastMaHandle;
int    ExtSlowMaHandle;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);

   SetIndexBuffer(4,ExtMacdBufferred,INDICATOR_DATA);
   SetIndexBuffer(5,ExtMacdBufferline,INDICATOR_DATA);
   SetIndexBuffer(6,uparrow,INDICATOR_DATA);
   SetIndexBuffer(7,downarrow,INDICATOR_DATA);

//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
   /*
      PlotIndexSetInteger(0,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(1,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(2,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(3,PLOT_SHOW_DATA,false);

      PlotIndexSetInteger(4,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(5,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(6,PLOT_SHOW_DATA,false);
      PlotIndexSetInteger(7,PLOT_SHOW_DATA,false);

      IndicatorSetString(INDICATOR_SHORTNAME," ");
      */

   PlotIndexSetDouble(4,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetInteger(6,PLOT_ARROW,225);
   PlotIndexSetDouble(6,PLOT_EMPTY_VALUE,0.0);

   PlotIndexSetInteger(7,PLOT_ARROW,226);
   PlotIndexSetDouble(7,PLOT_EMPTY_VALUE,0.0);
//--- get MA handles
   ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
  }
MACD - Oscillators - MetaTrader 5 Help
MACD - Oscillators - MetaTrader 5 Help
  • www.metatrader5.com
Moving Average Convergence/Divergence (MACD) is a trend-following dynamic indicator. It indicates the correlation between two Moving Averages of a...
 

too many failure.....at the end of the day, I got two things:

1, do not add new buffers/plots after the no-drawing buffers, always before them.

2, do not asign EMPTY_VALUE to indicator buffer when needed, use 0.0 instead.

 
joshatt # :

too many failure.....at the end of the day, I got two things:

1, do not add new buffers/plots after the no-drawing buffers, always before them.

2, do not asign EMPTY_VALUE to indicator buffer when needed, use 0.0 instead.

You will avoid many mistakes if you create a template using the 'MQL Wizard'.

 
Vladimir Karputov #:

You will avoid many mistakes if you create a template using the 'MQL Wizard'.

Thanks, I'll remember that.