Bug in bar shift for multi-currency EA - page 2

 
alphatrading:

Internally the MetaTrader protocol to the quote server is a FIX dialect (google that). It means you have to subscribe/unsubscribe to symbols you want to get quotes for. As an end user you have to select/unselect symbols you are interested in in the "Market Watch" window (the UI for quote subscription managment). Adding a symbol to the "Market Watch" window subscribes, removing it unsubscribes from the quote feed (in reality it's a bit more complicated but for a general understanding this picture is enough).

The process of subscribing/unsubscribing to quotes is what causes the infamous error ERR_HISTORY_WILL_UPDATED. At the time you request bar data with iClose() etc. there are no current quotes in the terminal, only the previous ones which can be hours or even days old. Now this is what you see in your Debug EA. The missing bars are loading but haven't been received the moment you execute your debug statement.

Imagine the consequences if you'd like to always have current quotes. The terminal had to pull quotes for all available symbols and all the time. This would exceed every available bandwidth on the broker side, and on your own side too. That's why you get everywhere the advice to "remove unneeded symbols from the Market Watch window to save resources" (i.e. bandwidth) if you run an EA.

What you'r experiencing is just the way the terminal handles the underlying quote feed, and not a bug.

I have written strategies in java for FIX API myself, so no need for googling. :) 

The symbols were of cause added to the Market Watch before the EA was started. So from your understanding this should not happen if the symbol is subscribed? 

I have switch to use this instead of iClose() but I still get inconsistent bars sometimes. I think I will probably just store the bid/ask in an array myself every hour to be sure to have the correct data. 

double close(int shift) {
   int barShift = iBarShift(symbol, timeFrame, Time[shift]);
   if (barShift < 0) return -1;
   return iClose(symbol, timeFrame, shift);
}