This code works.
I follow these steps:
- I have to put the iATR first.
- force the CheckLoadHistory (in this case, the history was preloaded, but I like to be redundant)
- I did a while loop for the first attempts with a very long sleep between each iteraction.
- After some attempts, the data was loaded.
I think that now I can do some improvements, like use only one sleep after try recovery data from all symbols, use sleep with ms instead of seconds, and remove the excessive code to turn this solution more elegant...
I think that is it. If anyone of you think about an improvement or a easy way, you are welcome to comment.
Code:
string symbol = "PETR4"; ResetLastError(); if(!SymbolInfoInteger(symbol,SYMBOL_SELECT)){ PrintFormat("ERROR: symbol not selected %s: %d", symbol, _LastError); SymbolSelect(symbol,true); } int hATR = iATR(symbol, PERIOD_D1, 14); if(INVALID_HANDLE == hATR){ PrintFormat("ERROR: Unable to load ATR for %s: %d", symbol, _LastError); } datetime first_date; SeriesInfoInteger(symbol,PERIOD_D1,SERIES_FIRSTDATE,first_date); int res1 = CheckLoadHistory(symbol, PERIOD_D1, first_date); PrintFormat("CheckLoadHistory res: %d", res1); SeriesInfoInteger(symbol,PERIOD_D1,SERIES_FIRSTDATE,first_date); int bars=Bars(symbol,PERIOD_D1); Print("First date ",first_date," - ",bars," bars"); datetime times[]; int countTime1=CopyTime(symbol,PERIOD_D1,TimeCurrent(),1000,times); PrintFormat("Downloaded %d %s history bars for %s", countTime1, EnumToString(PERIOD_D1), symbol); double values[3]; int attempts = 0; while(attempts < 10){ ResetLastError(); int res = CopyBuffer(hATR,0,0,3,values); if(res != ArraySize(values)){ PrintFormat("%s: ERROR: Can't copy indicator buffer properly! handler=%d res=%d ERROR=%d", __FUNCTION__, hATR, res, _LastError); attempts++; } else { PrintFormat("Loaded ATR with %d values after %d attempts", res, attempts); attempts = 10; ArrayPrint(values); } Sleep(2000); }
Log:

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I Known that is a lot of information about the thema in this forum... some useful, some no so useful... but after some hours trying, I had to post my problem and my analisys here to better understand the problem and help so many poor souls like me...
I have a multicurrency EA that uses the iATR indicator. I load this indicator insite OnInit() and I use CopyBuffer() inside de OnTimer() to get the indicator values. On strategy tester, the CopyBuffer starts running with error, but after some days, the copybuffer starts to work and the EA finish with success.
My objective is to do some mechanism to force the preload and sincronization of all symbols BEFORE start the EA (inside OnInit). Does not matter if I'll lose some secs or minutes to do this load. I only want a deterministic behavior to my EA.
I read several docs that the moderators shared with others. The docs that help me more are https://www.mql5.com/en/docs/series/timeseries_access#synchronized and https://www.mql5.com/en/forum/321459#comment_13079471. But no signal to solve this puzzle... Can anyone help me to undestand what I'm missing to do it works well?
Thanks by advance and sorry by the long text.
Analysis:
I copy/paste the CheckLoadHistory from metaquote article and used it in the OnInit(), with the CopyTime() and others validations. All seems working (at least on sight), but When I tried to recovery the iATR data, copyBuffer returns -1 with the error: 4806=Requested data not found. Notice that the log before this errors shows that the symbol loaded enough bars on the cache.
Note: I run the test on WIN$N M1 but I'm getting data from PETR4 D1. This is part of the test, I want to handle distint symbols on distint timeframes.
[UPDATE]
I read the https://www.mql5.com/en/forum/322393 and tested some itens that the Alain said.
- I put the creation of the indicator before all, run the CheckLoadHistory and after run the copyBuffer. Same error... :(
This sentence worry me:
Seems like this can be the case here... But I'm not sure if I did some great failure in my code (I know that is wrong initiate the indicator and get the values in the same method, I put it in this example to simplificate).
Code:
The strategy tester log:

Test configuration:
