Help with coloring some candles

To add comments, please log in or register
fernandoac
7
fernandoac  

Hi!


I'm trying to get some candle colors, if there is any gap higher or lower, the candle shows up as red or blue, but the chart are not coloring all the candle body, instead there are creating a new candle next to the original.

The idea is just get differente between open/close values and color these candles.


//+------------------------------------------------------------------+
//|                                                       OCDiff.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 1
#property indicator_type1 DRAW_COLOR_CANDLES    //Drawing style - color candles
#property indicator_color1  clrBlue,clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

  
double buffer_open[],buffer_close[],buffer_high[],buffer_low[]; //Buffers for data
double buffer_color_line[];    //Buffer for color indexes

string symbol;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping


  SetIndexBuffer(0,buffer_open,INDICATOR_DATA);
  SetIndexBuffer(1,buffer_close,INDICATOR_DATA);
  SetIndexBuffer(2,buffer_high,INDICATOR_DATA);
  SetIndexBuffer(3,buffer_low,INDICATOR_DATA);
  SetIndexBuffer(4,buffer_color_line,INDICATOR_COLOR_INDEX);

  PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);
  PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,Blue);  
  PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,Red); 
  
//---
   return(INIT_SUCCEEDED);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
  
//---
 
 int start, i;
 
 ArrayInitialize(buffer_open,0.0);
 ArrayInitialize(buffer_high,0.0);
 ArrayInitialize(buffer_low,0.0);
 ArrayInitialize(buffer_close,0.0);
 
 if(prev_calculated == 0)
  {
    start = 1;
  }
  else
  {
    start = prev_calculated - 1;
  }
  
 for(i=start;i<rates_total-1;i++)
   {
     
     buffer_open[i]=open[i];  
     buffer_close[i]=close[i];
     buffer_high[i]=high[i];
     buffer_low[i]=low[i];
     
         
     if(buffer_open[i]<buffer_close[i-1]) 
        { buffer_color_line[i]=0; }
        
     //if(buffer_close[i-1]=open[i] && buffer_close[i-1]>buffer_close[i])
         //{ buffer_color_line[i]=2; }
         
     //if(buffer_close[i-1]==close[i] && buffer_close[i-1]<buffer_close[i])
         //{ buffer_color_line[i]=3; }
       
     if(buffer_close[i-1]<open[i])
        { buffer_color_line[i]=1; }
     
        
      } 
 
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+


That's what I'm getting:




Not the full candle colored, but the difference between.

Anyone knows what I am missing?

Thanks in advance.

To add comments, please log in or register