CopyTime returning -1 for data not ready - How can you wait for CopyX() Functions to fetch data first?
I am having some issues with the CopyX functions. CopyTime, CopyClose etc
It seems like when you call them, and the data is not there - the functions will return -1, and seem to asynchronously fetch the data you request.
So if you call CopyX a second time, the data will likely be there.
How can you wait for the functions to attempt to fetch data first before they return a failed result? Or give them time to...
My idea is pasted below, but it seems like Sleep() blocks the thread, and the CopyTime function still fails.
Any suggestions guys?
Seems like this problem needs to be solved with multi threading somehow.
Bad idea. Why do you want to wait ?
If the data are not there returns and try on next tick. If you can't wait next tick, use a timer.
Bad idea. Why do you want to wait ?
If the data are not there returns and try on next tick. If you can't wait next tick, use a timer.
Hi Alain
I needed the current candle timestamp for a login authentication in the OnInit() part of the code.
Hi Alain
I needed the current candle timestamp for a login authentication in the OnInit() part of the code.
Move your login authentication code outside OnInit(), and run it when you know you have data.
As @Alain Verleyen points out, use a timer.
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am having some issues with the CopyX functions. CopyTime, CopyClose etc
It seems like when you call them, and the data is not there - the functions will return -1, and seem to asynchronously fetch the data you request.
So if you call CopyX a second time, the data will likely be there.
How can you wait for the functions to attempt to fetch data first before they return a failed result? Or give them time to...
My idea is pasted below, but it seems like Sleep() blocks the thread, and the CopyTime function still fails.
Any suggestions guys?
Seems like this problem needs to be solved with multi threading somehow.