Scripts: Simple Bar Timer

 

Simple Bar Timer:

It is a script to display the time remaining until next bar arrives.

Simple Bar Timer

Author: Conor Mcnamara

 
Automated-Trading:

Simple Bar Timer:

Author: Conor Mcnamara

It works as intended, but when I switch the time frame (HTF or LTF, doesn`t matter), it dissapears and has to be reattached. 

Any advice?

 
Alex Stefanescu #:

It works as intended, but when I switch the time frame (HTF or LTF, doesn`t matter), it dissapears and has to be reattached. 

Any advice?

Convert the Script into an Indicator, and put the timeframes switch inside the OnInit() event handler.

As alternatives, 2 indicators are attached.

 

Strictly speaking this script will not work correctly depending on the symbols selected in the Market Watch.

TimeCurrent() is returning the last update time of any symbol in the Market Watch, if they are a lot of symbols then fine, if there are only symbol(s) with low activity, your counter will not move.

Additionally, using sleep(1000), you can have a shift of almost 1 second in your counter.

 Exemple : it should be 00:37:05

 
Alain Verleyen # with low activity, your counter will not move.

My countdown timer (MT4) uses the timer to update.
          Indicators: Zero Lag Timer - Indices - Articles, Library comments - MQL5 programming forum #8 (2017)