Timer that actually countsdown every second and doesn't pause and jump

 
I would love to find a candle time (for m1,m5,m15) that actually shows every second passing. The timer I use now pauses, and I never know exactly when the next candle is about to open. Thanks.
 

The timer you are using probably has time gaps between updating what it displays on screen because it is most likely an indicator which only updates every tick.

The start() function of indicators only runs once per tick. Depending on your broker, the currency and the volatility you can often wait several seconds between ticks.

One method to get around this is to use a cycle operator on an infinite loop, with a Sleep() of about 1000 milliseconds at the end of each loop. The clock timing can come from TimeLocal() or TimeCurrent(). The Sleep() only affects when the display gets updated.

The problem is that Sleep() cannot be used in an indicator. You will have to use this with either an EA or a script. Since you can only have one EA loaded per chart, it is probably better to use a script.

Another alternative is to continue to use the indicator you are currently using, and then add a script to the chart which sends a "fake tick" every 1000 milliseconds or so, which will cause the indicator to update every second. I do not recommend this for live trading though.

It is worth using this as an opportunity to explore using cycles and dealing with the various time functions. All the info you need is in the Documentation, Book and previously asked questions.

 
still don't really understand how to do it...
 
adevore:
still don't really understand how to do it...

Why is it so important to show every second passing if you want to know when the next candle is about to open ??

It can be that next candle is also not opened first second new bar

Look for first tick new bar. You don't need to watch every second if you look for first tick...

 
deVries:

Why is it so important to show every second passing if you want to know when the next candle is about to open ??

It can be that next candle is also not opened first second new bar

It can also be that the next candle does not open at all for the next expected time period . . . it is easily possible to have no ticks for 1 minute or even for 5 minutes on some instruments.
 

If you want to read and understand these, then it will be quite straight forward. They are pretty much essential for most useful programming in MT4 anyway, so they are good to go over.

I include both "while" and "for" so that you can chose which you prefer - because they basically perform the same function, but are written slightly differently.

https://docs.mql4.com/basis/operators/while

https://book.mql4.com/operators/while

https://docs.mql4.com/basis/operators/for

https://book.mql4.com/operators/for

https://docs.mql4.com/common/Sleep

https://docs.mql4.com/dateandtime/TimeCurrent

https://book.mql4.com/functions/datetime

https://docs.mql4.com/convert/TimeToStr

https://book.mql4.com/functions/strings

https://docs.mql4.com/common/Comment

https://book.mql4.com/functions/common

There are very few uses for a clock which actually updates every second, rather than every tick - but there are some uses.

Since you have this desire, then it is a good opportunity to motivate yourself to practice making the code yourself.

 
I have almost similar task to done. Is there any way to get Volume(indicator) value of almost 50 currency pairs through one Procedure (i.e. EA, Indicator or script).
 

I can see a clear question in the first post (show every second of candle), so I am placing a simple example.

We cannot use indicator - as stated above, indicators ignore Sleep().

Among scripts and EAs, it is definitely better to use the EA - unlike script it starts automatically when the MT4 starts up and does not break with every time frame change.

The EA should not be affected by the EA switch - so we need to lock it running in the init() function.

/** never triggers start */
int start() {
}

/** loops in init until removed */
int init() {

   // local and server time shift in seconds
   int severTimeShift = 0;

   // loop until removed   
   while (! IsStopped()) {

      datetime timeToUpdate = Time[0] + (Period() * 60) + severTimeShift;
      
      // waits for the next run
      while (! IsStopped() && (Time[0]+ severTimeShift) < timeToUpdate) {
         Comment("New candle in ", (timeToUpdate - TimeLocal()), " seconds." );
         Sleep(200);
         RefreshRates();         
      }
   }
   return(0);
}
  
int deinit() {
   Comment("");
}
 
Ovo:

I can see a clear question in the first post (show every second of candle), so I am placing a simple example.

We cannot use indicator - as stated above, indicators ignore Sleep().

Among scripts and EAs, it is definitely better to use the EA - unlike script it starts automatically when the MT4 starts up and does not break with every time frame change.

The EA should not be affected by the EA switch - so we need to lock it running in the init() function.

You do realise that init() is only supposed to run for a couple of seconds ?
 
Why do you suppose? Unlike an indicator, every EA has its own dedicated thread, so it does not interfere. I use this pattern frequently, and so far did not experience any trouble.
 
Ovo:
Why do you suppose? Unlike an indicator, every EA has its own dedicated thread, so it does not interfere. I use this pattern frequently, and so far did not experience any trouble.
From this: https://www.mql5.com/en/forum/128803/page2#373533
Reason: