DRAW_COLORS_LINE issue

 

Dear developer, hope you doing well. I've started learning MQL5 a few weeks ago and I am practicing with a lot of examples. But there is something that is causing an issue and I have not identified the cause.


I have an indicator working very well:

 

So I am trying to add some new features to improve the code and practice with MQL5, so I have tried to colored the blue line adding some changes in the code:

#property indicator_type1   DRAW_COLOR_LINE
#property indicator_label1  "Linha Azul"
#property indicator_style1  STYLE_SOLID
#property indicator_color1  clrBlue,clrGreen,clrRed
#property indicator_width1  2
#property indicator_type2   DRAW_LINE
#property indicator_label2  "Linha Branca"
#property indicator_style2  STYLE_SOLID
#property indicator_color2  clrWhite
#property indicator_width2  1

Novo buffer para cores:

double bufferMAColors[];
SetIndexBuffer(4, bufferMAColors, INDICATOR_COLOR_INDEX);

Defini os indices:

PlotIndexSetInteger(0, PLOT_COLOR_INDEXES, 3);

E defini a condição de mudança de cor:

if (bufferMASa[i] > bufferSignal[i]) bufferMAColors[i] = 1;
else if (bufferMASa[i] < bufferSinal[i]) bufferMAColors[i] = 2;
else bufferMAColors[i] = 0;

When I define #property indicator_type1   DRAW_COLOR_LINE, now the indicator just plots totally wrong, like this:

 

The white line is not plotted anymore and the blue line was plotted with values completely different. If I change back the #property indicator_type1 to  DRAW_LINE, the indicator come back working normally.

   //--- indicator buffers mapping
   SetIndexBuffer(0, bufferMASa, INDICATOR_DATA);
   SetIndexBuffer(1, bufferMASa2, INDICATOR_DATA);
   SetIndexBuffer(2, bufferMA, INDICATOR_CALCULATIONS);
   SetIndexBuffer(3, bufferSignal, INDICATOR_CALCULATIONS);
   SetIndexBuffer(4, bufferMAColors, INDICATOR_COLOR_INDEX);

There are only two Plots, buffer 0 and buffer 1.

What am I doing wrong?

 
You can't mix the buffers. The color buffer needs to follow the data buffer.
 
b2tradingclub:

Dear developer, hope you doing well. I've started learning MQL5 a few weeks ago and I am practicing with a lot of examples. But there is something that is causing an issue and I have not identified the cause.


I have an indicator working very well:

 

So I am trying to add some new features to improve the code and practice with MQL5, so I have tried to colored the blue line adding some changes in the code:

When I define #property indicator_type1   DRAW_COLOR_LINE, now the indicator just plots totally wrong, like this:

 

The white line is not plotted anymore and the blue line was plotted with values completely different. If I change back the #property indicator_type1 to  DRAW_LINE, the indicator come back working normally.

There are only two Plots, buffer 0 and buffer 1.

What am I doing wrong?

Hello , back when i started with mt5 i built an indicator with all the draw styles for understanding them . 

I don't actually remember how the color lines works but maybe the source code can help you . (you are interested in all the sections gated by DRAW_COLOR_LINE)

Files:
 
Alain Verleyen #:
You can't mix the buffers. The color buffer needs to follow the data buffer.

Hello Alain, thanks. But could you explain that? I have to set the same buffer number for COLOR_INDEX? Is it right?

 
Lorentzos Roussos #:

Hello , back when i started with mt5 i built an indicator with all the draw styles for understanding them . 

I don't actually remember how the color lines works but maybe the source code can help you . (you are interested in all the sections gated by DRAW_COLOR_LINE)

Thank you so much!!!!

 
b2tradingclub #:

Hello Alain, thanks. But could you explain that? I have to set the same buffer number for COLOR_INDEX? Is it right?

COLOR_INDEX has nothing to do with the buffer index, you are confused.

The buffers for a given plot MUST BE consecutive.

   SetIndexBuffer(0, bufferMASa, INDICATOR_DATA);
   SetIndexBuffer(1, bufferMAColors, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2, bufferMASa2, INDICATOR_DATA);
   SetIndexBuffer(3, bufferMA, INDICATOR_CALCULATIONS);
   SetIndexBuffer(4, bufferSignal, INDICATOR_CALCULATIONS);
 
Alain Verleyen #:

COLOR_INDEX has nothing to do with the buffer index, you are confused.

The buffers for a given plot MUST BE consecutive.

Dear Alain, thank you so much for that teaching. You did it! Problem solved.