MqlRates and CopyRates timing issues?

 

Hi,

I coded a small indicator that uses not only OHLC of the symbol where the indicator is placed, but it also uses OHLC from other symbols to generate signals.

At the very first tick of a new candle I try to get the OHLC from the symbols with CopyRates into a MqlRates struct.

MqlRates firstRates[];
MqlRates secondRates[];
// ...
MqlRates nthRates[];

// use 1 as copyFrom index because we need the rates from the 
// previous (finished) candle, not from the current not-yet-closed candle 
int copyFrom = 1;  
CopyRates("EURUSD", PERIOD_CURRENT, copyFrom, 10, firstRates);
CopyRates("AUDUSD", PERIOD_CURRENT, copyFrom, 10, secondRates);
// ...
CopyRates("GBPUSD", PERIOD_CURRENT, copyFrom, 10, nthRates);

// do secret holy grail things with that data

The thing is:
If I insert the indicator for the first time on a chart everything is fine, signals are shown where they should (I draw arrows) but when the indicator is on a chart with ticking data it sometimes misses a signal. If I re-insert the indicator the missed signals appear like normal, so I think it is a timing problem that occurs when the market gets faster.

Are there known timing problems with CopyRates()? How can I avoid this?

Best regards, Alex

 
Have you taken into account that a new bar will not appear on several symbols at the same time? It may well be that a new bar has already appeared on one symbol, but not on another.
 
Vladislav Boyko #:
Have you taken into account that a new bar will not appear on several symbols at the same time? It may well be that a new bar has already appeared on one symbol, but not on another.

Hmm ok could be. Is there a way to sync multiple symbols?

 
Alex #:

Hmm ok could be. Is there a way to sync multiple symbols?

No, the bars on each symbol will only form once there is a new tick after the start time of the bar. So it will vary from symbol to symbol.    
You must code knowing this and check the data you are getting before you use it, and wait if required until you have the data you need available.  

 
Yes, you are right: not having a finished candle on the first tick on other symbols from time to time was the problem. Now I'm waiting the ticks until all candles are available.

Thank you both!