Keep track of Time[0] in a static variable.
When it changes then you know it is a new bar. Remember to update the static variable when a new bar.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 and MetaTrader 4 - MQL4 programming forum
Keep track of Time[0] in a static variable.
When it changes then you know it is a new bar. Remember to update the static variable when a new bar.
Ah.. Thank you very much!
The current bar is closed when a tick arrives outside the current bar's duration.
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 and MetaTrader 4 - MQL4 programming forum
Thank you for your answer !
The current bar is closed when a tick arrives outside the current bar's duration.
Disagree. Your sentence is not true if period is daily and market is already closed.
This means current bar will not receive a new tick, no matter next bar already received or not a new tick.
Usefull for those who plan next day operations at night, while local market is closed (and so last bar).
If the market is closed, there is no tick. There will be no new bar started, until a new tick is received. The current bar isn't closed until a new bar starts.
- 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'm beginner.
I want to give an event when Current bar is closed and create next bar.
How do I know when the current bar is closed ?
Thank you.