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.
datetime bar_start_time=Time[0]; datetime bar_end_time=bar_start_time+PeriodSeconds(); int seconds_remaining=bar_end_time-TimeCurrent();.
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.
- TimeCurrent() exactly as GumRai posted.
- Also remember the bar doesn't close until a new tick is received, therefor seconds_remaining can go negative.
- 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.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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.
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.