requesting previous values of bars

 
I need to load values of previous bars of several symbols and timeframes.

So I load the quotes and wait some time after the request.

My question is simply: is it enough to request just time and open like (simplified code):

int earliestBar = 500;
string sym[10] = {"EURUSD",...};
int tf[9] = {1,5,..}
for (int s=0;s<10;s++){
  for(m=0;m<9;m++) {
    datetime t = iTime(sym[s],tf[m], earliestBar);
    double   o = iOpen(sym[s],tf[m], earliestBar);
  }
}
Sleep(15000); // wait 15 seconds so that all the quotes can come in.

or do I have to request all what I will need:

int earliestBar = 500;
string sym[10] = {"EURUSD",...};
int tf[9] = {1,5,15,30,60,..}
for (int s=0;s<10;s++){
  for(m=0;m<9;m++) {
    datetime t =  iTime(sym[s],tf[m], earliestBar);
    double   o =  iOpen(sym[s],tf[m], earliestBar),
             h =  iHigh(sym[s],tf[m], earliestBar),
             l =   iLow(sym[s],tf[m], earliestBar),
             c = iClose(sym[s],tf[m], earliestBar),
             v = (double)iVolume(sym[s],tf[m], earliestBar);
   }
}
Sleep(15000); // wait 15 seconds so that all the quotes can come in.

To put in a different way, if I request one value of a bar (op) will all the others (hi,lo,cl,vo) come in too or are they sent by different streams?

 

iBars() is enough.

The trouble is that you have no control of how many bars it loads, sometimes it loads 256, or 512, or 2048 (this was the highest number I noticed)

 

iBars()?

It tells me how many Bars are already locally available.

But I need load the bars in beforehand as the historic-quote request is not thread-safe. That means the calculation goes on even though not all the bars are completely locally available!

 
gooly:

iBars()?

It tells me how many Bars are already locally available.

But I need load the bars in beforehand as the historic-quote request is not thread-safe. That means the calculation goes on even though not all the bars are completely locally available!


Why that exclamation mark. I am answering your query what is enough for starting the chart data download from the server.

From my experience, you have no easy tool to learn if the loading has completed. There are some advices in this forum about checking error codes, but you may easily test they do not work.

 
  1. You are waiting 15 seconds for all timeframes. If you don't have a large pipe, multiple concurrent downloads may take longer. I suggest waiting for each chart.
    void  DownloadHistory(ENUM_TIMEFRAMES aPeriod){
       ResetLastError(); (void) iOpen(_Symbol,aPeriod,0);
       if(_LastError != 0){
          if(_LastError != ERR_HISTORY_WILL_UPDATED){ Print(_LastError); return;
          Sleep(15000); RefreshRates();
    }  }
    
  2. You only have to wait if, and only if you get 4066. iOpen, iBars, ect. will all trigger the download start.
  3. Once started, you get all available OHLCV. One stream.
  4. Remember this 15 seconds is a one time wait, the first time EA requests other charts. After that you'll have history local and only new bars since last terminal shutdown will have to be sent.
 

ok, thank you, WHRoeder,

But unfortunately Error 4066 ("Requested history data is in updating state") is totally helpless as this error is set only the first time that the terminal is loading.

Every time after that _LastError signals no error even though the terminal is still loading and quotes locally aren't correct :(

So I have to assume that after the first call of your function DownloadHistory(..) I won't get the 4066 (ERR_HISTORY_WILL_UPDATED).

Or am I wrong?

 
Correct. The first time it sleeps. After that you have your history.
 

??

And the second time for the second timeframe and/or the next symbol on the same chart?

Do I get 

_LastError != ERR_HISTORY_WILL_UPDATED // this signals ready, all was loaded!!

despite the 'other' history is not loaded completely?

Reason: