EA Doctor rule · Portability
Hard-coded symbol name
The code names a symbol such as "EURUSD" or "XAUUSD", which breaks on brokers that use another name or a suffix.
Why it matters
Symbol names differ between brokers: EURUSD, EURUSD.m, EURUSDm, EURUSD.pro; gold is XAUUSD on one server and GOLD on the next. A name written into the code works on the account it was written for.
Elsewhere the EA meets "unknown symbol" (4301) or "symbol not selected" (4302) and does not trade. Use _Symbol for the chart's symbol, or an input the trader sets.
When the rule fires
A string that looks like a symbol (two currency or metal codes such as "EURUSD" or "XAUUSD", optionally with a suffix, or a common index name such as "US30" or "NAS100") is used in code. Strings in input declarations and in Print(), Comment(), Alert() and similar output calls are not flagged.
When it stays quiet
The symbol comes from _Symbol, Symbol() or an input.
How to fix it
- Use
_Symbolwhen the EA trades its chart's symbol. - For other symbols, make each one an input and call
SymbolSelect(name, true)inOnInit(); stop with a clear message when it fails.
Code that fires it
void OpenGold()
{
trade.SetExpertMagicNumber(InpMagic);
if(!trade.Buy(InpLots, "XAUUSD"))
Print("Buy failed: ", trade.ResultRetcodeDescription());
}Fixed code
input string InpSymbol = "XAUUSD"; // the broker's name for gold
void OpenGold()
{
if(!SymbolSelect(InpSymbol, true))
{
Print("Symbol ", InpSymbol, " is not available on this account");
return;
}
trade.SetExpertMagicNumber(InpMagic);
if(!trade.Buy(InpLots, InpSymbol))
Print("Buy failed: ", trade.ResultRetcodeDescription());
}The fixed code shows this rule’s fix and compiles in MetaEditor for MetaTrader 5 (with CTrade trade, InpLots and InpMagic declared, as in a typical EA). Other rules may still apply to it as a fragment: check your whole EA.
Related MQL5 errors
More rules on portability
- HighMQL4 functions in an MQL5 fileThe file uses MQL4's order functions and variables (OP_BUY, OrderSelect by position, Bid, Ask, Close[]), which MQL5 does not have.
Sources
Get your EA fixed
Check a whole EA for this and 29 other mistakes with EA Doctor, free and in your browser. Or send it to us: we confirm the price in writing, then fix it.