Multicolored candles MQL5

 

Hi,

is possible to draw with an indicator, candles with more than one color?

Like this



Is so, any piece of sample code?

Thank you !!

 
israelhernando: is possible to draw with an indicator, candles with more than one color? Like this. Is so, any piece of sample code?

Yes! Just plot two standard mono-colour histograms normally, one over the other. It would be two normal standard plots (buffers). Choose the order according to which one is always smaller so that it draws the smaller one over the larger one.

 
israelhernando :


Use two styles:

 

Ok !!

And is possible do it with candles? The candles, I'm seeing that need 4 buffers of data.

Then, how can I draw 2 series or more of candles?


Thanks

 

For color candles you can use "Draw Color Candles", but those actually need 5 buffers (Open, High, Low, Close AND Color)


This is for one series only:

#property indicator_buffers 5
#property indicator_plots   1

#property indicator_label1  "Open;High;Low;Close"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrGray, clrLime, clrRed //indexes in buffer = 0, 1, 2
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1


//--- Indicator buffers
double         OpenBuffer[];
double         HighBuffer[];
double         LowBuffer[];
double         CloseBuffer[];
double         ColorBuffer[];

//-----

int OnInit()
{
   SetIndexBuffer(0,OpenBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,HighBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,LowBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,CloseBuffer,INDICATOR_DATA);
   SetIndexBuffer(4,ColorBuffer,INDICATOR_COLOR_INDEX);

   return(INIT_SUCCEEDED);
}

For one more series, you would need to set 10 buffers and 2 plots, and set their label, type, color, etc. I'll leave that for you to work a bit heheh, but it's definitely possible

 

good !!  I'll try


Thanks

 
israelhernando:Ok!! And is possible do it with candles? The candles, I'm seeing that need 4 buffers of data. Then, how can I draw 2 series or more of candles?
Why do it with "candles" that requires so many more buffers when you can do it with histograms in a much simpler way? Why do you want to complicate things?
 
Fernando Carreiro:
Why do it with "candles" that requires so many more buffers when you can do it with histograms in a much simpler way? Why do you want to complicate things?

Because I'm thinking on color the candles of a chart, over the real candles