quentinS: The problem is that very often the iBarShift returns -1 meaning that the candlestick is not available yet (5 hours later...), I find it a bit surprising ...
Am i doing something wrong, or is there any way to refresh the data before ? |
|
|
Thank you for your answer
But Im not sure you understood what i meant, i meant that i want to retrieve the candlestick from 6pm when it is 11pm,
im not asking for any future candlestick, i'm looking for an existing one.
Here is my code so it will be easier:
double calcHigh(datetime dpDate=NULL) { if(dpDate == NULL) dpDate = TimeLocal(); MqlDateTime date; TimeToStruct(dpDate, date); date.hour = 18; date.min = 0; date.sec = 0; double high = 0; // This datetime means today at 6pm datetime dt = StructToTime(date); int shift = iBarShift(NULL, PERIOD_H1, dt, true); // if we can retrieve data if (shift > 0) { high = iHigh(Symbol(), PERIOD_H1, shift); } return high; }This function is being called at 11pm by an EA, the problem is that i often get -1 for the shift
Thank you for your help, i got my answer!
I just didnt want to depend on the timeframe associated with the chart but there is a function (ChartSetSymbolPeriod)
that allows me to control it from the EA
I think you missed the key element from what whroeder1 recommended. You have to use TimeCurrent() and NOT TimeLocal(). What you're trying to do is take the time from your computer - in your time-zone - and ask for a bar of a different time-zone. You have to keep everything you do with regard to this procedure on server time using TimeCurrent()
I think you missed the key element from what whroeder1 recommended. You have to use TimeCurrent() and NOT TimeLocal(). What you're trying to do is take the time from your computer - in your time-zone - and ask for a bar of a different time-zone. You have to keep everything you do with regard to this procedure on server time using TimeCurrent()
Yes i changed TimeLocal() to TimeCurrent() in my code, its more reliable i agree with that
But it wasn't my problem since i made sure to synchronize the time of the computer i trade on with the broker server time.
I dont know exactly how it works internally, but it seems to be easier to retrieve past data when the timeframe of the data we are looking for is the one set on the chart (at least with my broker)
Thanks for pointing it out though
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am trying to get the high value at a certain period of the day.
For example, when it is 11 pm, I want to retrieve the high value at 6 pm
To do so, I use iBarShift() to get the shift and then apply iHigh() to this shift
The problem is that very often the iBarShift returns -1 meaning that the candlestick is not available yet (5 hours later...),
I find it a bit surprising ...
Am i doing something wrong, or is there any way to refresh the data before ?
Note that i dont want to use High because i want to keep control over the timeframe
thank you for your help