Problem with CustomRatesUpdate (Metatrader 5)

 

Hi,

   I'm experiencing a problem with the CustomRatesUpdate function.
The custom chart "breaks" and I get undocumented error messages in the "Journal" tab.
The problem surfaces very often (not always) when the server time goes from one day to the next.

Here are the error messages:

2021.01.22 01:00:03.545 HistoryCache    'CustomENQH21' invalid container header [3]
2021.01.22 01:00:03.546 HistoryBase     'CustomENQH21' invalid container (1970.01.01) found (off: 883540262, size: 38469, file: 5178546525)
2021.01.22 01:00:04.053 HistoryCache    'CustomMNQH21' invalid container header [3]
2021.01.22 01:00:04.053 HistoryBase     'CustomMNQH21' invalid container (1970.01.01) found (off: 2338691591, size: 38469, file: 6633697605)

2021.01.21 23:00:02.768 HistoryCache    'CustomNZDJPY' invalid container header [0]
2021.01.21 23:00:02.768 HistoryBase     'CustomNZDJPY' invalid container (1970.01.01) found (off: 726806312, size: 86589, file: 5021860446)
2021.01.21 23:00:02.776 HistoryCache    'CustomGBPUSD' invalid container header [0]
2021.01.21 23:00:02.776 HistoryBase     'CustomGBPUSD' invalid container (1970.01.01) found (off: 1385209444, size: 86589, file: 9975230874)
2021.01.21 23:00:02.946 HistoryCache    'CustomEURGBP' invalid container header [0]
2021.01.21 23:00:02.946 HistoryBase     'CustomEURGBP' invalid container (1970.01.01) found (off: 677093279, size: 86589, file: 4972147413)
2021.01.21 23:00:03.157 HistoryCache    'CustomEURUSD' invalid container header [0]
2021.01.21 23:00:03.157 HistoryBase     'CustomEURUSD' invalid container (1970.01.01) found (off: 1744488308, size: 86589, file: 6039542442)
2021.01.21 23:00:03.328 HistoryCache    'CustomUSDJPY' invalid container header [0]
2021.01.21 23:00:03.328 HistoryBase     'CustomUSDJPY' invalid container (1970.01.01) found (off: 2266203305, size: 86589, file: 6561257439)


Here is a test EA code that will generate these errors:

static string _CustomSymbol = "Custom"+_Symbol;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   ResetLastError();
   
   if(!CustomSymbolCreate(_CustomSymbol, "", _Symbol))
   {
      Print("Failed creating custom chart, error #"+(string)GetLastError());
      ResetLastError();
   }
   else
   {
      Print("Created "+_CustomSymbol+" chart");   
   }
   
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   MqlRates ratesArr[];

   if(CopyRates(_Symbol, PERIOD_M1, 0, 1, ratesArr) == -1)
   {
      Print("Error on CopyRates #"+(string)GetLastError());
      ResetLastError();
   }
   else
   {
      if(CustomRatesUpdate(_CustomSymbol, ratesArr) == -1)
      {
         Print("Error on CustomRatesUpdate #"+(string)GetLastError());
         ResetLastError();
         
         // this error surfaces when a new day starts
         // Error on CustomRatesUpdate #5304
         // 5304 -> A custom symbol with the same name already exists 
         // or
         // Error on CustomRatesUpdate #0
         
         // Messages in the Journal
         // HistoryCache        'CustomSymbol' invalid container header [2]
         // HistoryBase 'CustomSymbol' invalid container (1970.01.01) found (off: 2683897016, size: 86589, file: 6978951150)
         
      }
   }

}



Any idea what is causing this? The code is very simple so I'm guessing the problem lies in the CustomRatesUpdate function. To replicate the problem, please attach the EA to 5 or more symbols. Let it run for several hours before the server date changes. The error will trigger, sooner or later. Always around the same time (server time going from one day to the next).

Reason: