HistoryDealsTotal() - Bug in build 5200?

 

All of a sudden an EA that I have used for several months started to misbehave. I narrowed it down to HistoryDealsTotal(). As a simplified example, here is my OnTester() function:

double OnTester() {
   if (!HistorySelect(0, TimeCurrent())) Print("HistorySelect() failed!");
   else Print("HistorySelect() succeeded!");
   
   int dealCount = HistoryDealsTotal();
   Print("Deals Total: " + (string)dealCount);
   
   return(dealCount);
}

Since the dealCount is returned, we can see it on the test report.

The first time I run a test after having restarted MT5 or recompiled the code, it works correctly. We can see in the report that the OnTester Result matches the expected number of deals (plus one for the initial balance).

The log file after this successful run looks like this:


But if I now re-run the same test, I get exactly the same trades, but HistoryDealsTotal() doesn't find any deals except the one for initial balance, which means that the OnTester result is now 1.

The log looks like this:


The code has been the same for months, but today was the first time I encountered this issue.

Any ideas what it could be or what could be done about it?