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
You should not check the bar opening time, but the number of bars using iBars.
If the number of bars has changed by 1, it means a new bar has opened.
If the number of bars has changed by more than 1, it means MT has loaded quotes and formed new bars in history. This means you need to recalculate everything again (update all indicator data or EA).
https://www.mql5.com/en/docs/series/ibars
That is totally incorrect. NEVER use the bar count for detecting new bar. Bar count can change for various reasons and have nothing to do with a new bar.
The CORRECT procedure is to check the bar's open time.
That is totally incorrect. NEVER use the bar count for detecting new bar. Bar count can change for various reasons and have nothing to do with a new bar.
Well, if you want your indicator (or EA) to make calculations with leaky history then yes.
The bar count can be used for detecting history changes where you may need to recalculate everything, but it should NEVER be user for detecting a new bar.
The correct way is the open time and that has been discussed in the forum countless times.
The bar count can be used for detecting history changes where you may need to recalculate everything, but it should NEVER be user for detecting a new bar.
The correct way is the open time and that has been discussed in the forum countless times.
It's the same thing, you can't expect one bar to appear and not expect many bars to appear.
Moreover, almost all indicators check not the bar time but the number of bars, even variables have been created for this: rates_total and prev_calculated.
But for some reason there is no last time variable)
"rates_total" and "prev_calculated" serve a different purpose and not for new-bar detection.
Ever since the old MQL4 (and probably before), it has been repeated time and time again, that using the bar count for detecting a new bar is unreliable and only the open time can be relied on.
There is a caveat, however, and that is when using a non standard custom symbol which can have consecutive bars with the same timestamp. In these cases we have to use multiple conditions to check for a new bar. For example, for a Renko one would need to check the Open Time and the Open Price.
Using the "bars" method will inevitably fail especially when you have set a limit on the maximum number of bars for charts and history, where data is shifted in and out to maintain that bar limit. It is even mentioned in the documentation for iBars in MQL5 (same applies in MQL4, as it states "Returns the number of bars on the specified chart.").
"rates_total" and "prev_calculated" serve a different purpose and not for new-bar detection.
Ok, all indicators can work with rates_total but user should NEVER do that.
Using the "bars" method will inevitably fail especially when you have set a limit on the maximum number of bars for charts and history, where data is shifted in and out to maintain that bar limit. It is even mentioned in the documentation for iBars.
It is the number of bars that matters, not the limitation of that number.
It seems you refuse to acknowledge the obvious. The limitation affects the bar count, so your bar detection will fail when the history is greater than the limit.
Feel free to ignore the advice for yourself, but just don't incentivise others to do it incorrectly.
It seems you refuse to acknowledge the obvious. The limitation affects the bar count, so your bar detection will fail when the history is greater than the limit.
Feel free to ignore the advice for yourself, but just don't incentivise others to do it incorrectly.
It seems you don't understand how it works.
Feel free to check it)The number of bars always increases, but does not decrease and does not remain constant.
Very well, I will do so! I will run tests and check it. If you are correct and if the bars count does in fact overflow the max limit, then that will mean that the documentation is incorrect.
I will do a full test on both MQL4 and MQL5 and post the results with log output here later on.
In a follow-up question and irrespective of the test results, what is your reasoning for considering the "Open Time" method as incorrect? Where does it fail?
If you are correct about the "bar" method, what is preventing the "open time" method from also being a valid method?