Download MetaTrader 5

Print seconds remaining in bar

To add comments, please log in or register
brettosm8
241
brettosm8  

Hi there,

I want to print how much time is left remaining for a bar to close, so I can open an order just before the bar closes.

Print("Time left: ",PeriodSeconds()-TimeSeconds(Time[0]));

But on the M1 chart "60" prints out for every tick.

On the D1 chart "86400" prints out for every tick. 

It should print numbers approaching 0.

Can you please advise?

Thanks again. 

honest_knave
Moderator
2423
honest_knave  

Bars open on round minutes, so the seconds will always be 0 when you call Time[]... remember that Time[] gives you the bar open time.

Try using TimeCurrent() instead. 

Keith Watford
Moderator
9641
Keith Watford  
  datetime bar_start_time=Time[0];
  datetime bar_end_time=bar_start_time+PeriodSeconds();
  int seconds_remaining=bar_end_time-TimeCurrent();
.
whroeder1
14780
whroeder1  
brad: I want to print how much time is left remaining for a bar to close, so I can open an order just before the bar closes.
  1. TimeCurrent() exactly as GumRai posted.
  2. Also remember the bar doesn't close until a new tick is received, therefor seconds_remaining can go negative.
  3. If you had used this you would have found Free download of the 'Candle Closing Time Remaining - CCTR - Version 3' indicator by 'Arshen' for MetaTrader 4 in the MQL5 Code Base.
To add comments, please log in or register