Question about bar close time

To add comments, please log in or register
Par duck
90
Par duck  

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.

Keith Watford
Moderator
20526
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.

William Roeder
20233
William Roeder  
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
Par duck
90
Par duck  
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!

Par duck
90
Par duck  
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 !

To add comments, please log in or register