Issue with delayed chart rendering using "DRAW_COLOR_CANDLES" indicator

 

Hello everyone,

I would like to post about an issue I encountered with the "DRAW_COLOR_CANDLES" indicator in MQL5. Depending on the values set, there can be significant delays in chart rendering.


#property indicator_chart_window

#property indicator_buffers 9
#property indicator_plots   1

double buffer_low[];
double buffer_high[];
double buffer_open[];
double buffer_close[];

double buffer_color_line[];

double chart_low[];
double chart_high[];
double chart_open[];
double chart_close[];


input bool   in_on = false;
input uint   in_repaint_num  = 1;
input color  in_color_bear   = clrBlue;
input color  in_color_bull   = clrRed;
input color  in_color_even   = clrBlack;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
//--- indicator buffers mapping
   SetIndexBuffer(0, buffer_open,      INDICATOR_DATA);
   SetIndexBuffer(1, buffer_high,      INDICATOR_DATA);
   SetIndexBuffer(2, buffer_low,       INDICATOR_DATA);
   SetIndexBuffer(3, buffer_close,     INDICATOR_DATA);
   SetIndexBuffer(4, buffer_color_line, INDICATOR_COLOR_INDEX);
   SetIndexBuffer(5, chart_low,        INDICATOR_CALCULATIONS);
   SetIndexBuffer(6, chart_high,       INDICATOR_CALCULATIONS);
   SetIndexBuffer(7, chart_open,       INDICATOR_CALCULATIONS);
   SetIndexBuffer(8, chart_close,      INDICATOR_CALCULATIONS);
   PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(2, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetDouble(3, PLOT_EMPTY_VALUE, EMPTY_VALUE);
   PlotIndexSetInteger(0, PLOT_DRAW_TYPE, DRAW_COLOR_CANDLES);
   PlotIndexSetInteger(0, PLOT_LINE_STYLE, STYLE_SOLID);
   PlotIndexSetInteger(0, PLOT_LINE_WIDTH, 1);
   PlotIndexSetInteger(0, PLOT_COLOR_INDEXES, 4);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 0, in_color_bear);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 1, in_color_bull);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 2, in_color_even);
   PlotIndexSetInteger(0, PLOT_LINE_COLOR, 3, clrGreen);
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0);
//---
   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 limit = rates_total - prev_calculated;
   if(limit < 0) {
      return prev_calculated;
   }
   if(prev_calculated == 0) {
      limit = rates_total - 1;
   }
   ArraySetAsSeries(time, true);
   ArraySetAsSeries(open, true);
   ArraySetAsSeries(high, true);
   ArraySetAsSeries(low, true);
   ArraySetAsSeries(close, true);
   ArraySetAsSeries(chart_low,        true);
   ArraySetAsSeries(chart_high,       true);
   ArraySetAsSeries(chart_open,       true);
   ArraySetAsSeries(chart_close,      true);
   for(int i = limit; i >= 0; i--) {
      chart_open[i]  = open[i];
      chart_high[i]  = high[i];
      chart_low[i]   = low[i];
      chart_close[i] = close[i];
   }
   if(limit == 0) {
      return  rates_total;
   }
   ArraySetAsSeries(buffer_low,        true);
   ArraySetAsSeries(buffer_high,       true);
   ArraySetAsSeries(buffer_open,       true);
   ArraySetAsSeries(buffer_close,      true);
   ArraySetAsSeries(buffer_color_line, true);
   for(int i = limit; i >= 0; i--) {
      buffer_low   [i] = low[i];
      buffer_high  [i] = high[i];
      buffer_open  [i] = open[i];
      buffer_close [i] = close[i];
      if(open[i] == close[i]) {
         buffer_color_line[i] = 2;
      } else if(open[i] < close[i]) {
         buffer_color_line[i] = 1;
      } else {
         buffer_color_line[i] = 0;
      }
   }
//--- return value of prev_calculated for next call
   return(rates_total);
}

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
//---
   if(id == CHARTEVENT_CLICK) {
      Print("-- " + TimeToString(TimeLocal(), TIME_DATE | TIME_MINUTES | TIME_SECONDS) + " --");
      for(int i = 0; i < in_repaint_num; i++) {
         if(in_on) {
            buffer_low   [i] = buffer_open  [i] = 0;
            buffer_high  [i] = buffer_close [i] = chart_high[i]  + 100;
         } else {
            buffer_low   [i] = buffer_open  [i] = 0;
            buffer_high  [i] = buffer_close [i] = chart_high[i];
         }
         buffer_color_line[i] = 3;
      }
      ChartRedraw();
   }
}
//+------------------------------------------------------------------+

Here are the test conditions:

  • Currency pair: "AUDUSD"
  • Bar width set to maximum
  • After executing the indicator with default settings, do the following:
    1. Click on the chart
    2. Change the window size using the mouse
  • Change the "in_on" parameter to [true] and the "in_repaint_num" parameter to a small value such as [3].
  • Do the following:
    1. Click on the chart
    2. Change the window size using the mouse

In the above test, there was a clear delay in chart rendering during step 2. This delay may be due to the fact that an obvious abnormal value (High + 100) was set for the currency pair price.

However, to resolve this issue, it may be necessary to improve the internal processing of the Terminal. I would appreciate any feedback on this matter.

Thank you for your assistance.

Best regards,

 

Confirmed.

Reported to Metaquotes developer attention.

 
Alain Verleyen #:

Confirmed.

Reported to Metaquotes developer attention.

Thank you for confirming the issue and for reporting it to the MetaQuotes developer team.

I appreciate your prompt response and attention to this matter.

Please let me know if there are any further updates or information regarding the resolution of this issue.

Thank you again for your assistance.

 

Thank you for the report

Fixed

 
Ilyas #:

Thank you for the report

Fixed

I have confirmed that this issue has been resolved in build 3668.

Thank you.

 
Ilyas #:

Thank you for the report

Fixed

I have confirmed that the issue has been fixed in build 3668.

Is there any plan to release the fixed version to the public?

If possible, could you provide me with an estimated timeframe for the release?

Thank you.