Download history in MQL4 EA - page 4

Derk Wehler
348
Derk Wehler  
William Roeder:

Any candle related function does that. The test is for the error and not to continue until download completes.

I came across this thread when I was trying to load TF data for a chart running an EA, so I could get iATR(100) on various TFs even if there was no data loaded.

bool DownloadHistory(int period=0, string symbol="")
{
        string fn = __FUNCTION__ + "()";

        if (symbol == "")       symbol = Symbol();
        if (period == 0)        period = Period();
        
        for (int i=0; i < 5; i++)
        {
                ResetLastError();
                datetime other = iTime(symbol, period, 0);
                if (_LastError == 0  &&  other != 0)
                        return(true);
                if (_LastError != ERR_HISTORY_WILL_UPDATED  &&  _LastError != ERR_NO_HISTORY_DATA)
                        Debug(1, fn, "iTime(" + symbol + ", " + period + ", 0) Failed. Error = " + _LastError);
                else    // we need to wait for it to load
                        Sleep(500);
        }
        return(false);
}

It seemed to work pretty well, running it on 28 charts, except I kept getting an error on AUDNZD only when it tried to load H4 data, which was odd because the chart was on H4.  Eventually I just used the home key to load more and it went away.

But using the iTime() function only loads the minimal which appears to be 120.1 KB.  I wondered if anyone had a method for MT4 to make it load all data (like holding the 'Home' key) or a certain amount of data.

Substituting a variuable 'bar' for zero, I tried this:

int bar = iBars(NULL, 30);
while (true)
{
        bar = bar + iBars(NULL, PERIOD_M30);
        DownloadHistory(PERIOD_M30 , Symbol(), bar);
}       

But it only resulted in a error 4051.  Anyone ever figure a way to load 'X' bars of data, or to load all?

Derk Wehler
348
Derk Wehler  
Derk Wehler:

I came across this thread when I was trying to load TF data for a chart running an EA, so I could get iATR(100) on various TFs even if there was no data loaded.

It seemed to work pretty well, running it on 28 charts, except I kept getting an error on AUDNZD only when it tried to load H4 data, which was odd because the chart was on H4.  Eventually I just used the home key to load more and it went away.

But using the iTime() function only loads the minimal which appears to be 120.1 KB.  I wondered if anyone had a method for MT4 to make it load all data (like holding the 'Home' key) or a certain amount of data.

Substituting a variuable 'bar' for zero, I tried this:

But it only resulted in a error 4051.  Anyone ever figure a way to load 'X' bars of data, or to load all?

Don't answer all-at-once.  I'm very patient.

William Roeder
24595
William Roeder  
Derk Wehler: Anyone ever figure a way to load 'X' bars of data, or to load all?
If you don't have any history, here's how you can get all available from your broker. Otherwise, you will have to download history from elsewhere.
Derk Wehler
348
Derk Wehler  
William Roeder:
If you don't have any history, here's how you can get all available from your broker. Otherwise, you will have to download history from elsewhere.

William:

Thank you for the response.  The link you sent seems to be a manual method.  I was attempting to find a way to do it programmatically.

But that's still a pretty good trick for manually getting it :-)