Download MetaTrader 5
To add comments, please log in or register
Do you want to know about the MQL5.community development? Have a look at the Wall!
brettosm8
241
brettosm8 2016.01.31 09:28 

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
969
honest_knave 2016.01.31 10:09  

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
7990
Keith Watford 2016.01.31 10:19  
  datetime bar_start_time=Time[0];
  datetime bar_end_time=bar_start_time+PeriodSeconds();
  int seconds_remaining=bar_end_time-TimeCurrent();
.
whroeder1
13641
whroeder1 2016.01.31 14:47  
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