Using two DRAW_COLOR_ARROW plots in the same indicator

 

Using 

#property indicator_type1 DRAW_COLOR_ARROW

the arrow symbol (https://www.mql5.com/en/docs/constants/objectconstants/wingdings) is specified via

PlotIndexSetInteger(0,PLOT_ARROW,arrow_code); //arrow_code != 159

However, this works only with a single plot.


Adding a second DRAW_COLOR_ARROW plot

#property indicator_type2 DRAW_COLOR_ARROW

the command

PlotIndexSetInteger(2,PLOT_ARROW,arrow_code);

remains ineffective and the plot will display the default (159) arrow symbol.


Is this a bug or a feature and any ideas how to override this behaviour?

.

.

.

 
timkrug:

Is this a bug or a feature and any ideas how to override this behaviour?


Yes a bug in your code. DRAW_ARROW_COLOR needs 2 buffers for 1 plot. Did you declare your buffers correctly ?

PlotIndexSetInteger(21,PLOT_ARROW,arrow_code);
 
Alain Verleyen:

Yes a bug in your code. DRAW_ARROW_COLOR needs 2 buffers for 1 plot. Did you declare your buffers correctly ?

Thanks, Alain, but I did declare my buffers correctly.

Buffer indices 0 and 1 are reserved for the first plot.

  SetIndexBuffer(0,Buff1,INDICATOR_DATA);
  SetIndexBuffer(1,Buff1_clr,INDICATOR_COLOR_INDEX);

Buffer indices 2 and 3 are assigned to the second plot, respectively. 

Besides, the indicator works flawlessly when changing the plots to DRAW_COLOR_LINE type (arrow_code ignored, of course).

 
timkrug:

Thanks, Alain, but I did declare my buffers correctly.

 Plot indices 0 and 1 are reserved for the first plot.

Plot indices 2 and 3 are assigned to the second plot, respectively. 

Besides, the indicator works flawlessly when changing the plots to DRAW_COLOR_LINE type (arrow_code ignored, of course).

Use the right words, it will help you to avoid bugs.

I showed you a bug in the posted code. Did you fix it ?

Please post a full code if you need coding help.

EDIT: I see you fixed your post.
 
Alain Verleyen:

Use the right words, it will help you to avoid bugs.

I showed you a bug in the posted code. Did you fix it ?

Please post a full code if you need coding help.

EDIT: I see you fixed your post.


There was no bug to fix, here is the full code.


#property indicator_chart_window
#property indicator_buffers 4
#property indicator_plots   2

#property indicator_type1 DRAW_COLOR_ARROW
#property indicator_width1 1
#property indicator_color1 clrRed,clrBlue

#property indicator_type2 DRAW_COLOR_ARROW
#property indicator_width2 1
#property indicator_color2 clrRed,clrBlue

const int arrow_code=75;

double Buff1[],Buff2[],
       Buff1_clr[],Buff2_clr[]; 


void OnInit()
  {
  SetIndexBuffer(0,Buff1,INDICATOR_DATA);
  SetIndexBuffer(1,Buff1_clr,INDICATOR_COLOR_INDEX);
  PlotIndexSetInteger(0,PLOT_ARROW,arrow_code);
  PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
  PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

  SetIndexBuffer(2,Buff2,INDICATOR_DATA);
  SetIndexBuffer(3,Buff2_clr,INDICATOR_COLOR_INDEX);
  PlotIndexSetInteger(2,PLOT_ARROW,arrow_code);
  PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0);
  PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);

  return;
  }//OnInit


void OnDeinit(const int reason)
  {

  return;
  }//OnDeinit


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])                
  {
  int bar,first;
  
  if(prev_calculated==0)
    first=0;
  else first=prev_calculated-1;

  for(bar=first; bar<rates_total; bar++)
    {
    Buff1[bar]=price[bar];
    Buff2[bar]=price[bar]-500*_Point;
    Buff1_clr[bar]=1;
    Buff2_clr[bar]=1;
    }
    
  return(rates_total);
  }//OnCalulate

 
timkrug:


There was no bug to fix, here is the full code.

As Alain showed you in post #1 you have to index your plots correctly. You have only two indicator plots and therefore you can't use 2 as an plot index.

  SetIndexBuffer(2,Buff2,INDICATOR_DATA);
  SetIndexBuffer(3,Buff2_clr,INDICATOR_COLOR_INDEX);
  PlotIndexSetInteger(1,PLOT_ARROW,arrow_code);
  PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
  PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2);
 
Petr Nosek:

As Alain showed you in post #1 you have to index your plots correctly. You have only two indicator plots and therefore you can't use 2 as an plot index.

Thank you, Alain and Petr.

I applied our modifications and yes, it works.

I have written many DRAW_COLOR_LINE indicators, but obviously still haven't understood the concept how to index multicolor plots correctly.

Alain or Petr, would you be so kind and explain it to me or refer to a source other than the mql5 reference?!


EDIT: Ok, I think I get it. ;-)

Plot counting is not to be mixed with buffer counting. 

 
timkrug:

EDIT: Ok, I think I get it. ;-)

Plot counting is not to be mixed with buffer counting. 

Is your background in MT4? There is different approach in MT5. Don't mix buffers and plots. But you've already got it. Have a nice day.

 
Petr Nosek:

Is your background in MT4? There is different approach in MT5. Don't mix buffers and plots. But you've already got it. Have a nice day.

No, MT5 only, for many years already. I'm glad that finally the penny dropped.

You wouldn't believe how many hours I spent on this issue, not only today. Thanks.

 
timkrug:

No, MT5 only, for many years already. I'm glad that finally the penny dropped.

You wouldn't believe how many hours I spent on this issue, not only today. Thanks.

You're welcome ;-)

Reason: