Should return the current bar open time, but I have an issue where it sometimes returns the previous bar time.
I didn't think it was possible.
Maybe if I RefreshRates() ? Edit: Nope. Still happenning.
Maybe this is the case. Sometimes there is no new tick arrived and it has to return the previous bar value.
- 2023.08.08
- www.mql5.com
Should return the current bar open time, but I have an issue where it sometimes returns the previous bar time.
I didn't think it was possible.
Maybe if I RefreshRates() ? Edit: Nope. Still happenning.
Yashar is right , the bar you want may not have formed yet because there are no ticks .
It should not affect operations however unless you are deploying a multi pair expert advisor . In that case prefer OnTimer() , store each symbol's latest formed bar time and that way whenever a new bar opens for one of the symbols you will know.
Should return the current bar open time, but I have an issue where it sometimes returns the previous bar time.
I didn't think it was possible.
Maybe if I RefreshRates() ? Edit: Nope. Still happenning.
- What is the value of Time[0]?
- From which event handling function are you calling iTime()?
- What does GetLastError() return after calling iTime()?
If GetLastError() returns an error, then you should not use the data that iTime() returned and you need to wait some time while the data is loading.
What are these difficulties for? You are calling this for the current symbol and timeframe.
From OnCalculate() use time[]
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[])
In other cases (not from OnCalculate) use Time[].
Using time[] and Time[] does not require error checking
Yashar is right , the bar you want may not have formed yet because there are no ticks .
It should not affect operations however unless you are deploying a multi pair expert advisor . In that case prefer OnTimer() , store each symbol's latest formed bar time and that way whenever a new bar opens for one of the symbols you will know.
You quoted an older message. Things have changed since then. Updating at each symbol's first tick is an improvement I intend to implement but like I said it was not always the cause of my issue:
iTime(_Symbol,_Period,0); just returned the fourth newest bar open time, so a no new tick situation is clearly not the case.
Vladislav Boyko #:
- What is the value of Time[0]?
- From which event handling function are you calling iTime()?
- What does GetLastError() return after calling iTime()?
If GetLastError() returns an error, then you should not use the data that iTime() returned and you need to wait some time while the data is loading.
What are these difficulties for? You are calling this for the current symbol and timeframe.
From OnCalculate() use time[]
In other cases (not from OnCalculate) use Time[].
Using time[] and Time[] does not require error checking
The problem didn't happen again, but if it does I will try GetLastError().
I'm using iTime because I'm not only working with the current chart.
You quoted an older message. Things have changed since then. Updating at each symbol's first tick is an improvement I intend to implement but like I said it was not always the cause of my issue:
The problem didn't happen again, but if it does I will try GetLastError().
I'm using iTime because I'm not only working with the current chart.
The problem didn't happen again, but if it does I will try GetLastError().
It will definitely occur when requesting data of another symbol/timeframe if it has not been used for some time.
"has not been used" - means that the chart window of this symbol/timeframe is not open and its data (rates) were not requested from MQL programs. In this case, the terminal stops updating this chart, and when requested (using iTime(), for example), it may take some time to update the chart. During this time (while the requested historical data is being updated), you will receive incorrect values.
Therefore, when working with iXXX() functions, it is always necessary to check GetLastError()
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Should return the current bar open time, but I have an issue where it sometimes returns the previous bar time.
I didn't think it was possible.
Maybe if I RefreshRates() ? Edit: Nope. Still happenning.