How does CopyTime work? - MT5

 

Hello all;

I switched to MT5 a few days ago - so apologies in advance for my ignorance.

My focus  is on multi-pairs (hence the switch to MT5). However I am struggling to get things to work the way I would expect them (probably my lack of understanding about MT5).

I am trying to check that a new bar has opened for all symbols in the selected time frame, before taking further action. To do this, I am trying to use CopyTime for all the relevant symbols (28 of them).

The documentation states that" If you need to return value corresponding to the current uncompleted bar, you can use the first form of call specifying start_pos=0 and count=1.

However that does not seem to work (at least the way I'm doing it).

I've written two simple indicators to test CopyTime across 5 symbols, using both the bars and date version of CopyRates. In both cases, Time[0] for the symbols is either the same as time[0] (chart symbol) or 1 bar behind. THis persists even when using a significnat sleep command (say 10 seconds).


Does anyone have any comments? including pointing out if I'm totally on the wrong track?


thanks all.


ps:


By way of further explanation, here are some typical results (with the time option, although the same thing occurs with the Bars option)

TimeStamp Current Chart = 2017.07.31 12:08:00 

AUDCAD: tm[0] =           2017.07.31 12:07:00

AUDCHF: tm[0] =           2017.07.31 12:07:00

AUDJPY: tm[0] =           2017.07.31 12:08:00

AUDNZD: tm[0] =           2017.07.31 12:08:00

EURAUD: tm[0] =           2017.07.31 12:07:00

GBPAUD: tm[0] =           2017.07.31 12:07:00

-----------------------------------

TimeStamp Current Chart = 2017.07.31 12:09:00

AUDCAD: tm[0] =           2017.07.31 12:09:00

AUDCHF: tm[0] =           2017.07.31 12:08:00

AUDJPY: tm[0] =           2017.07.31 12:09:00

AUDNZD: tm[0] =           2017.07.31 12:08:00

EURAUD: tm[0] =           2017.07.31 12:08:00

GBPAUD: tm[0] =           2017.07.31 12:09:00

-----------------------------------

TimeStamp Current Chart = 2017.07.31 12:10:00

AUDCAD: tm[0] =           2017.07.31 12:09:00

AUDCHF: tm[0] =           2017.07.31 12:10:00

AUDJPY: tm[0] =           2017.07.31 12:09:00

AUDNZD: tm[0] =           2017.07.31 12:09:00

EURAUD: tm[0] =           2017.07.31 12:10:00

GBPAUD: tm[0] =           2017.07.31 12:10:00

pss:

I've just realised that the Sleep command does not work in an Indicator - so ignore that bit of commentary!

 

That's perfectly normal results. A new bar only occurs at first tick of a given period, not at the start of the period.

So for example, at 12:10, new 1 minute period, you can have a new bar on current symbol (first tick after 12:10:00) but not yet on some other symbols.

 

OK. I think I've solved it.

The results above seem to mean that at the time of the CopyTime function call, Bar[0] for the particular symbol is not yet formed.

I am dealing with this in an Expert by using the Sleep() function. However, not sure how this can be solved in an Indicator (i tried a while loop but it seems to stop tick flow).


Here is my testing Expert if anyone finds it useful.


cheers

 
Torinex:

OK. I think I've solved it.

The results above seem to mean that at the time of the CopyTime function call, Bar[0] for the particular symbol is not yet formed.

I am dealing with this in an Expert by using the Sleep() function. However, not sure how this can be solved in an Indicator (i tried a while loop but it seems to stop tick flow).


Here is my testing Expert if anyone finds it useful.


cheers


Thanks Alain. I got to the same conclusion just now.

 
Torinex:

Thanks Alain. I got to the same conclusion just now.

Welcome

Always better to find by yourself.

Reason: