Just look into the reference!
You'll find: ERR_HISTORY_NOT_FOUND which means that your terminal hasn't got all the quotes it has requested.-
Either: if (..) return() or if(..) sleep().
Good morning,
I had a strange behavior using the CopyRates function in MQL5. I tried to load some Rates using the CopyRates function for a specified Symbol (CustomSymbol). The requested data is on a PERIOD_M1 and represents two months of rates starting from the SERIES_TERMINAL_FIRSTDATE of the Symbol.
The first time I ran the script, the function always returns -1 with the error code 4401 (from GetLastError()). The second time I ran the script with the same set of parameters, it worked perfectly. It seems that MT5 loaded the data asynchronously between the two launches.
The source code:
1st launch: FAILED
SERIES_TERMINAL_FIRSTDATE = D'2003.03.24 00:00:00'
SERIES_FIRSTDATE = D'2003.03.24 09:15:00'
SERIES_LASTBAR_DATE = D'2018.02.08 21:45:00'
SERIES_BARS_COUNTS = 203018
SERIES_SYNCHRONIZED = TRUE
iCount = -1 and iError = 4401
2nd launch: SUCCESS with the same set of parameters
SERIES_TERMINAL_FIRSTDATE = D'2003.03.24 00:00:00'
SERIES_FIRSTDATE = D'2003.03.24 09:15:00'
SERIES_LASTBAR_DATE = D'2018.02.08 21:45:00'
SERIES_BARS_COUNTS = 203018
SERIES_SYNCHRONIZED = TRUE
iCount =
27427 (on the first while iteration).
Is there a solution to avoid this problem like?
Thanks
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
I don't understand why, when calling CopyRates for a different period in an OnCalculate of a custom indicator, the first time I always get -1 as results even if SERIES_SYNCHRONIZED do not return 0 (false).
This is inside of my OnCalculate function, at the first tick after indicator is attached to the chart I get CopyRates<0 with error 4401 but I do not see log "D1 prices not synched"
if( !(bool)SeriesInfoInteger(NULL,PERIOD_D1,SERIES_SYNCHRONIZED) ) { Print("D1 prices not synched"); return(0); } copied = CopyRates(NULL,PERIOD_D1,0,2,D1); if( copied<0 ) { Print("error in getting D1 prices"); return(0); }
At the second tick rates are successfully copied. It's not exactly I problem but I can't understand why it happens...
I don't understand why, when calling CopyRates for a different period in an OnCalculate of a custom indicator, the first time I always get -1 as results even if SERIES_SYNCHRONIZED do not return 0 (false).
This is inside of my OnCalculate function, at the first tick after indicator is attached to the chart I get CopyRates<0 with error 4401 but I do not see log "D1 prices not synched"
At the second tick rates are successfully copied. It's not exactly I problem but I can't understand why it happens...
Forum on trading, automated trading systems and testing trading strategies
attila.okcu, 2016.11.18 11:05
I've got the following reply from the service desk: "Actually, the SERIES_SYNCHRONIZED flag means that the local price history is synchronized with the server. It is not related to timeseries."
And, the service desk also said that the example code in the documentation will be checked and fixed if necessary.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning,
I had a strange behavior using the CopyRates function in MQL5. I tried to load some Rates using the CopyRates function for a specified Symbol (CustomSymbol). The requested data is on a PERIOD_M1 and represents two months of rates starting from the SERIES_TERMINAL_FIRSTDATE of the Symbol.
The first time I ran the script, the function always returns -1 with the error code 4401 (from GetLastError()). The second time I ran the script with the same set of parameters, it worked perfectly. It seems that MT5 loaded the data asynchronously between the two launches.
The source code:
1st launch: FAILED
SERIES_TERMINAL_FIRSTDATE = D'2003.03.24 00:00:00'
SERIES_FIRSTDATE = D'2003.03.24 09:15:00'
SERIES_LASTBAR_DATE = D'2018.02.08 21:45:00'
SERIES_BARS_COUNTS = 203018
SERIES_SYNCHRONIZED = TRUE
iCount = -1 and iError = 4401
2nd launch: SUCCESS with the same set of parameters
SERIES_TERMINAL_FIRSTDATE = D'2003.03.24 00:00:00'
SERIES_FIRSTDATE = D'2003.03.24 09:15:00'
SERIES_LASTBAR_DATE = D'2018.02.08 21:45:00'
SERIES_BARS_COUNTS = 203018
SERIES_SYNCHRONIZED = TRUE
iCount = 27427 (on the first while iteration).
Is there a solution to avoid this problem like?
Thanks