Question about bar close time

 

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.

 

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.

 
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
 
Keith Watford:

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!

 
whroeder1:
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 !

 
William Roeder:
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).

 
hdemarco: 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.

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.

Reason: