Print seconds remaining in bar

Back to topics list To post a new topic, please log in or register
avatar
77
brad 2016.01.31 10: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. 

avatar
735
honest_knave 2016.01.31 11: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. 

avatar
Moderator
3407
GumRai 2016.01.31 11:19 #
 
  datetime bar_start_time=Time[0];
  datetime bar_end_time=bar_start_time+PeriodSeconds();
  int seconds_remaining=bar_end_time-TimeCurrent();
.
avatar
12985
WHRoeder 2016.01.31 15: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.
Back to topics list  

To add comments, please log in or register