iClose(), iTime(), CopyRates() etc. takes seconds and crashes EA and MT4

 
To start I could find no reference to this error in the MT4 forum. The Closest thing to it is this post. https://www.mql5.com/en/forum/313720. I am removing my comments on the MT5 Thread and posting them here.  I am getting a failure at iTime. The code has been perfectly for a number of years. That is until Version Version 4: Build 1220 13 sept 2019.  MetaEditor Version 5.0 build 2143 sept 13 2019.  By the way  I do not allow upgrades until the build has been out for a while. 2 prevent a update. I run a app that removes any *.png file from webinstall. It replaces it with the build I am using. When I have time I run the new build on a testing pc. It is a windows Ten Pro. 32 GB Intel Xeon CPU E5450 @ 3.00GHZ 2 Processors. It is a older dell 2950 server. I have two other Identical servers that I trade off of. One is a back up. Those two pcs do not have this error. but occasionally lock up.  After reading This thread above  I am not sure it is the Build. I tried as suggested  EventVWR  
Faulting application name: terminal.exe, version: 4.0.0.1220, time stamp: 0x00cf8600
Faulting module name: combase.dll, version: 10.0.18362.356, time stamp: 0x3c1d04fa
Exception code: 0xc0000602
Fault offset: 0x00104baa
Faulting process id: 0x36a0
Faulting application start time: 0x01d59850779f8e69
Faulting application path: C:\Program Files (x86)\OANDA - MetaTrader\terminal.exe
Faulting module path: C:\WINDOWS\System32\combase.dll
Report Id: fcc251ad-d6e4-42b3-83af-a8a876d0afa5
Faulting package full name: 
Faulting package-relative application ID: 

The Code I am using Traps all errors in a central Place  I call GOD.  GOD Global Operation Debugger . It tracks the errors in every single function Just prior to this error I was using copy rates.I load Three time frames back to back to compare the oanda data to a Reuters data feed specifically Refinitiv eikon core feed .The failure is in the function that deals with error  4066 . I also Track every article I have read on these topics and store them in an array for  reference during debugging. in the code below is a reference to the article I based the coded on

datetime dtError4066()
{

   //+-------------------------------------------------------------------+      
   //|   Local Variables Initialization                                  |
   //+-------------------------------------------------------------------+
   RefreshRates();
   bool     bBreak	        = false; 
   datetime dtRetunThis         = 0;
   datetime dtCurrentTime       = TimeCurrent();
      
   datetime dtCurrentM1Time     = 0;
   datetime dtCurrentTimeFrame  = 0;
   int iError                   = 0;

   //+-------------------------------------------------------------------+      
   //|   Main body                                                       |
   //+-------------------------------------------------------------------+      
      while(!bBreak)
   {
    	dtCurrentM1Time     = iTime(msEASymbol, PERIOD_M1, 0);
	dtCurrentTimeFrame  = iTime(msEASymbol, miEATimeFrame, 0);

      if ( dtCurrentTime >= dtCurrentM1Time && 
dtCurrentTime >= dtCurrentTimeFrame )            dtRetunThis = 
dtCurrentTime;                 

else if ( dtCurrentM1Time >= dtCurrentTimeFrame && 
dtCurrentM1Time >= dtCurrentTime )           dtRetunThis = 
dtCurrentM1Time;                 

else if ( dtCurrentTimeFrame >= dtCurrentM1Time && 
dtCurrentTimeFrame >= dtCurrentTime )         dtRetunThis = dtCurrentTimeFrame; 
              

else  dtRetunThis = dtCurrentTime;       iError = GetLastError(); 
      if( iError == 4066 ) {ResetLastError(); Sleep(1000); RefreshRates(); } else break; 
    }      

//+-------------------------------------------------------------------+ 
//+  Deinitialization  of Function                                    |
//+-------------------------------------------------------------------+   
  mcaGOD[ piFunc  ].sDebuggerURL1 = " https://www.mql5.com/en/forum/143422";   
  return(bReturnThis); 
}

Any help I would be most grateful . Thanks PS the bolded section is the failure point. It was late for me last night I posted the code slightly wrong. It has been corrected

iClose(), iTime(), CopyRates() etc. takes seconds and crashes EA and MT5
iClose(), iTime(), CopyRates() etc. takes seconds and crashes EA and MT5
  • 2019.05.17
  • www.mql5.com
Hi, I reported this issue already one year ago to MetaQuotes but never got a helpful response...
 
On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
          Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4
Try updating all symbol/TF at the start of OnTick.