Is there a real bug in MT5? Bars() works fine in a script but not in an indicator...?!

 

Hey guys,

here you find a script and an indicator and both use Bars(). Please have a look at the attached screenshot.

The first 10 values are from the script and below them you see the same 10 values but from the indicator.

Do I miss something or is this a bug within MT5?

Here is the script where everything works fine:

void OnStart()
  {
//---

   for (int i=0; i<10; i++) {
      string symbol=SymbolName(i,true);
      int bars=Bars(symbol,PERIOD_D1);
      Print(symbol+" daily bars: "+(string)bars);
   }
  }

And here the indicator:

#property indicator_chart_window
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   string objButton = "start";
   if (ObjectFind(0, objButton)==0) ObjectDelete(0, objButton);
   ObjectCreate(0, objButton, OBJ_BUTTON, 0, 0, 0);
   ObjectSetInteger(0, objButton, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, objButton, OBJPROP_XDISTANCE, 20);
   ObjectSetInteger(0, objButton, OBJPROP_YDISTANCE, 50);
   ObjectSetInteger(0, objButton, OBJPROP_XSIZE, 150);
   ObjectSetInteger(0, objButton, OBJPROP_YSIZE, 40);
   ObjectSetString(0, objButton, OBJPROP_TEXT, "START");
   ObjectSetString(0, objButton, OBJPROP_FONT, "Verdana");
   ObjectSetInteger(0, objButton, OBJPROP_COLOR, ChartGetInteger(0, CHART_COLOR_BACKGROUND, 0));
   ObjectSetInteger(0, objButton, OBJPROP_BGCOLOR, clrSilver);
   ObjectSetInteger(0, objButton, OBJPROP_BORDER_TYPE, BORDER_FLAT);
   ObjectSetInteger(0, objButton, OBJPROP_STATE, false);
   ObjectSetInteger(0, objButton, OBJPROP_FONTSIZE, 12);
//---
   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[])
  {
//---
   
//--- 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_OBJECT_CLICK) {
      if (sparam=="start") {
         for (int i=0; i<10; i++) {
            string symbol=SymbolName(i,true);
            int bars=Bars(symbol,PERIOD_D1);
            Print(symbol+" daily bars: "+(string)bars);
         }
      }
   }
  }
//+------------------------------------------------------------------+

The result can be seen in the screenshot.

Files:
Unbenannt.PNG  41 kb
 

From an indicator :

2021.02.12 21:44:56.175 362679 (EURUSD,D1)      EURUSD daily bars: 12925
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      GBPUSD daily bars: 2381
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      USDCHF daily bars: 2381
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      USDJPY daily bars: 2381
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      AUDCAD daily bars: 7152
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      AUDCHF daily bars: 7140
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      AUDJPY daily bars: 7170
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      AUDNZD daily bars: 7139
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      AUDUSD daily bars: 7062
2021.02.12 21:44:56.175 362679 (EURUSD,D1)      CADCHF daily bars: 7061
 
Alain Verleyen:

From an indicator :

How can that be possible?

Everytime I start the MT5 and run the indicator I only see these zeros... what's wrong here?