Download MetaTrader 5
To add comments, please log in or register
Track Market top sellers!
duzers 2015.05.28 18:57 


Is there any safe method to check if history is current after error 4066?.


whroeder1 2015.05.29 12:20  
ArrayCopySeries - MQL4 Documentation states
If data are copied from another chart with different symbol and/or timeframe, it is possible that the necessary data will lack. In this case, error ERR_HISTORY_WILL_UPDATED (4066 - requested history data under updating) will be placed into the last_error variable, and there will be necessary to retry copying after a certain period of time.
And shows an example.
So I wrote this.
/** Starts and waits for a download of chart history.
 * In Technical Indicator Functions - MQL4 Documentation][TIF3] it states:
 * > If data (symbol name and/or timeframe differ from the current ones) are
 * > requested from another chart, the situation is possible that the
 * > corresponding chart was not opened in the client terminal and the
 * > necessary data must be requested from the server. In this case, error
 * > `ERR_HISTORY_WILL_UPDATED` (4066 - the requested history data are under
 * > updating) will be placed in the last_error variable, and and there will
 * > be necessary to retry \[the operation] after a certain period of time.
 * The [ArrayCopySeries][ACS] example tests array[0] against server time.
 * [ACS]:
 * [TIF3]:
 * Note: you _only_ get 4066 once. Subsequent calls (\::ArrayCopyRates and
 * apparently \::ArrayCopySeries) silently succeed but the data is bogus
 * until the download completes. These calls should have been synchronous,
 * but then they couldn't be used in indicators.
bool  download_history(
         ENUM_TIMEFRAMES   period=PERIOD_CURRENT,  ///< The standard timeframe.
         string            msg=__FUNSIG__          ///< Debug.
         SYMBOL            symbol=THIS_SYMBOL      /**< The symbol required.*/){
   if(symbol == THIS_SYMBOL)     symbol = _Symbol;
   if(period == PERIOD_CURRENT)  period = _Period;
   datetime other = iTime(symbol, period, 0);
   if(_LastError == 0)  return true;
   if(_LastError != ERR_HISTORY_WILL_UPDATED){
      AssertFailure(StringFormat("%s: iTime(%s,%i) Failed: %i",
                                 msg, symbol, period, _LastError) );
      return false;
   datetime today = DateOfDay();
   for(int i = 0;i < 15; i++){
      other = iTime(symbol, period, 0);
      if(today == DateOfDay(other)){   RefreshRates();   return true;   }
   AssertFailure(StringFormat("%s: iTime(%s,%i) Failed: %i (15 secs)",
                              msg, symbol, period, _LastError) );
   return false;
To add comments, please log in or register