Scanning 28 symbols in 5 timeframes - page 3

 
William Roeder:
Both of those assumptions may be false. See The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles

I don't see anything in that article which unequivocally answers the fundamental question: "If TimeCurrent() updates, can there be any ticks dated earlier than TimeCurrent() which have not yet been processed into the bar history?"

As I said at the top of page 1, I'm not guaranteeing that this is a safe assumption. But it probably is. I think I'll check it on Monday when the markets re-open.

 
JC:

[...] assumption [...]

Returning to the original approach, a lesser optimisation is of course available provided that (a) the array of timeframes is in ascending order, and (b) we're not on MT5 which can potentially have timeframes which aren't multiples of each other. This will typically reduce the number of loop iterations from 140 to 28:

   for (int s=0; s<ArraySize(sym); s++) {   
      for (int t=0; t<ArraySize(tf); t++) {
         if (times[s][t]!=iTime(sym[s], tf[t], 0)) {
            times[s][t]=iTime(sym[s], tf[t], 0);
            if (iClose(sym[s], tf[t], 1)>iHigh(sym[s], tf[t], 2)) {
               Alert(sym[s]+" "+(string)tf[t]);
            }
         } else {
            // If e.g. M15 doesn't have a new candle, then e.g. H1 can't
            // have a new candle. Assumes that (a) the array of timeframes 
            // is in ascending order, and (b) that we're not on MT5 where 
            // the documentation allows for timeframes which aren't 
            // multiples of each other, such as M4 and M10

            t = 999; // Early exit from loop through timeframes; move to next symbol
         }
      }
   }

Strictly speaking, this also contains something of an assumption about the way that MT4 works internally: that updates of candles are tick-driven, and that the candle history for all timeframes is consistently updated before making it available to EAs and indicators. But that's an assumption so widely used and for so long that it must be correct. 

 
JC:

As I said at the top of page 1, I'm not guaranteeing that this is a safe assumption. But it probably is. I think I'll check it on Monday when the markets re-open.

It's impossible to disprove a negative, but everything which I'm seeing suggests that this is a safe assumption: if TimeCurrent() updates to a new minute, then all candle data on all markets for the previous minute will be final, and won't update further. (Obvious special exception for when MT4 is starting up, and receiving a combination of live data and old data to fill gaps in charts.)

Without intending to, I've even checked this on a terrible internet connection with slow speeds and lots of packet-loss. Remains the case that candle data which is grabbed when TimeCurrent() updates is consistent with a later check that those candles didn't receive further updates.

Reason: