detecting a new bar without removing ability to detect tick in multiple timeframe - Easy Trading Strategy - MQL4 programming forum #8 (2021.08)
Short and concise but not easy to understand though. Thanks! But why not test it. It says not tested. Also, does the one I posted remove the ability to detect ticks?
I think the below code for IsNewBarOnTimeframes() might be useful for anyone who wishes to monitor the end of a bar from any time frame whatsoever in MT4. Hence, I decided to share it for perusal. Happy using:
I think it's easier to use through a class. In this case, the symbol can be considered, and not just the timeframe. But you need to create instances of the class for the necessary symbols and timeframes.
class CIsNewBar { private: datetime last_bar_time_open; ENUM_TIMEFRAMES tf; string symbol; public: CIsNewBar(ENUM_TIMEFRAMES _tf = 0, string _symbol = NULL) { symbol = _symbol; tf = _tf; last_bar_time_open = iTime(symbol, tf, 0); }; ~CIsNewBar(); bool IsNewBar() { datetime cur_bar_time_open = iTime(symbol, tf, 0); bool result = cur_bar_time_open != last_bar_time_open; last_bar_time_open = cur_bar_time_open; return result; } };
But only works with one timeframe. If you need more, then you need the code in #1.
Really? I have not tested this example but assumed as timeframe is passed as an argument and used in the iTime functions it would be multi-timeframe.
I had written a similar one which works the same way - that does work across all timeframes, but as we already have so many examples I refrained from posting it
Perhaps if it said it could be fine... just guessing
CIsNewBar(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, string _symbol = NULL) {
But only works with one timeframe. If you need more, then you need the code in #1.

- 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 think the below code for IsNewBarOnTimeframes() might be useful for anyone who wishes to monitor the end of a bar from any time frame whatsoever in MT4. Hence, I decided to share it for perusal. Happy using: