historic data and ERR_HISTORY_WILL_UPDATED

 

Hi,

The following is an excerpt from the EA log:

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on M1 up to date (0 bars, first on 1970.01.01 00:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on M5 up to date (0 bars, first on 1970.01.01 00:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on M15 up to date (1536 bars, first on 2011.11.02 14:15)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on H1 up to date (1024 bars, first on 2011.09.26 18:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on H4 up to date (0 bars, first on 1970.01.01 00:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on D1 up to date (0 bars, first on 1970.01.01 00:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on W1 up to date (1027 bars, first on 1992.03.22 00:00)

2011.11.24 18:09:13 ADB-EA EURCHF,H1: Historic data on MN1 up to date (256 bars, first on 1990.08.01 00:00)

How do I tell in MT4 that historic data has actually been loaded from the server? I already have code that is supposed to do that and checks for ERR_HISTORY_WILL_UPDATED, but apparently MT4 doesn't return this code EVEN if there is NO backdata loaded from the server, as is the case when starting the EA for the first time at a broker for example, or if the the client hasn't connected to the server for a while (incomplete data). When I restart/reload the charts the data is there, but that's not good enough as the EA *MUST* know whether it has all the relevant data or not. For reference here is the part of the code that checks this:

for(int p=PERIOD_MN1; p>0; p=PeriodLower(p)) {
  GetLastError();
  ArrayCopyRates(data,symbol,p);
  if(GetLastError()!=ERR_HISTORY_WILL_UPDATED) Print("Historic data on ",PeriodToString(p)," up to date (",iBars(symbol,p)," bars, first on ",TimeToStr(iTime(symbol,p,iBars(symbol,p)-1)),")");
  else {
    addComment(PrintLog("Updating historic data on "+PeriodToString(p)));
    hist_updating++;
  }
}

As I said, for some reason even if there is no data loaded from the server, ArrayCopyRates doesn't report ERR_HISTORY_WILL_UPDATED.

So, to repeat the question, how EXACTLY to tell whether historical data for a particular symbol and timeframe has been loaded or not from the server AND potentially force an update?


 

As a second, and somewhat related question, is there also a way to force loading of backdata in MT4? For example, initially MT4 only loads a small subset of available data, and iBars() reports this subset as the whole that is available. But if I manually scroll the chart, MT4 loads more data from the server (and iBars() then reports more data as well). Is there a way to force this loading of data in an EA without the manual intervention?

Reason: