Let me tell you about something that drove me nuts for three days before I figured out what was going on. I had an EA that was supposed to scan exactly five currency pairs in Market Watch and trade based on their signals. But when I checked the logs, it was scanning eight pairs. Then twelve. Then the whole damn list.
I was sure my code was the problem. Rewrote the symbol enumeration three times. Checked the loop logic. Added print statements everywhere. Nothing made sense.
Then I stumbled onto an old MQL5 forum thread where a developer named stringo from MetaQuotes dropped a bombshell: "This is not a bug. It is specifically programmed behaviour" . He was responding to another trader who had the exact same problem.
Here's what's actually happening behind the scenes. The MQL4 documentation doesn't mention this anywhere. But when your EA calculates profit or margin requirements for open positions, MT4 automatically adds the symbols involved in those calculations to Market Watch. Even if you never added them yourself. The official line from MetaQuotes is that "implicit inclusion of pairs that participate in calculation of profits and margin requirements" is an intended design choice .
Why This Matters for Your EA
Let me walk through a real scenario. Say your EA has positions open on AUDCHF and NZDUSD. Your code loops through
SymbolsTotal() to scan Market Watch for trade signals. Before you know it, your EA is scanning 50 pairs instead of the 5 you actually want to watch. This can slow down execution, mess with your strategy logic, and cause unexpected behavior.The most frustrating part? There's no official function to check if a symbol was hidden versus explicitly added. According to the forum discussion, MetaQuotes acknowledged this limitation but never added a fix .
My Workaround
After banging my head against this for way too long, here's what I landed on:
SymbolsTotal() to tell you what's in Market Watch. Use a CSV file or input parameters with a fixed list of symbols.SymbolSelect() before scanning.</strong> This lets you explicitly add symbols you want without relying on auto-add behavior.SymbolSelect(symbol, false) function is your friend here.Here's the code snippet that saved my sanity:
``
mql4
// Instead of blindly looping through SymbolTotal()
string targetSymbols[5] = {"EURUSD", "GBPUSD", "USDJPY", "AUDUSD", "USDCAD"};
for(int i = 0; i < ArraySize(targetSymbols); i++) {
if(SymbolSelect(targetSymbols[i], true)) {
// Symbol is now in Market Watch, scan it
double bid = MarketInfo(targetSymbols[i], MODE_BID);
// ... your trading logic
}
}
``Reference
本文首发于FXEAR.com,原创内容,未经授权禁止转载