vdemydiuk / mtapi

MetaTrader API (terminal bridge)
MIT License
530 stars 285 forks source link

[MT4] CopyRates function is not returning data for all the supported timeframes. #183

Open gonzsanc opened 5 years ago

gonzsanc commented 5 years ago

It is happening to me with two different brokers I have tested.

CopyRates does not return data for M30, M15, M5 and M1 periods very often.

As a workaround I am using the iOpen, iHigh, iLow, iClose, iVolume and iTime functions that seem to work fine.

vdemydiuk commented 4 years ago

Hi. @gonzsanc Can you check how is working CopyRates in original MQL (make small sample of adviser) ?

eabase commented 4 years ago

@gonzsanc

I noticed that if you haven't used that symbol/tf combo before, MT4 does not yet have the data downloaded. Once you ask for it, it will return 4073 error and download it. So just run it again, and it should probably work. (At least that's what happened in my Python client.)

If there is a problem, then the problem is more about returning an actual error code when this happens. I only found the error from Terminal when I had debug enabled in the EA. Python never received a thing...

eabase commented 3 years ago

Just for reference:

From here:

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 one will has to re-request

So:

ArrayCopyRates will return an error if there is no history at all (ERR_NO_HISTORY_DATA = 4073.) Repeated calls also fail until the download is complete. When there is history but not up to date, ArrayCopyRates returns valid AND also sets _LastError to ERR_HISTORY_WILL_UPDATED (= 4066.)