Runtime error
4302 ERR_ MARKET_ NOT_ SELECTED
Symbol not selected in Market Watch
What it means
The symbol exists on the server but is not in the terminal's Market Watch, so its current prices are not available to the program. Multi-symbol EAs and indicators run into it when they read symbols other than the chart's.
Common causes
- A multi-symbol EA started on a fresh terminal whose Market Watch shows only a few symbols.
- A symbol removed from Market Watch by the user (possible when no chart and no position uses it).
- Reading prices or history of a symbol right after selecting it, before its data arrived.
A real scenario
A currency-strength EA reads 28 pairs, but on a new VPS the terminal's Market Watch lists only the majors. The crosses fail with 4302 and their strength is computed as zero, which turns into false signals. Selecting every symbol in OnInit() and refusing to start when one cannot be selected removed the problem.
How to fix it
- Call
SymbolSelect(name, true)for every symbol the program uses, inOnInit(), and check the result. - Wait for the first ticks of a newly selected symbol before trusting its prices.
- Note from the reference: a symbol cannot be removed while a chart of it is open or it has open positions.
Fixed MQL5 code
input string InpSymbols = "EURUSD,GBPUSD,XAUUSD";
string g_symbols[];
int OnInit()
{
int n = StringSplit(InpSymbols, ',', g_symbols);
for(int i = 0; i < n; i++)
{
StringTrimLeft(g_symbols[i]);
StringTrimRight(g_symbols[i]);
if(!SymbolSelect(g_symbols[i], true)) // add it to Market Watch so its prices update
{
PrintFormat("%s: cannot select it in Market Watch (error %d)", g_symbols[i], GetLastError());
return INIT_PARAMETERS_INCORRECT;
}
}
return INIT_SUCCEEDED;
}
A focused example for MetaTrader 5: adapt names, magic number and limits to your EA, and test it on a demo account first.
Related codes
- 4301Unknown SymbolERR_MARKET_UNKNOWN_SYMBOLUnknown symbol: the broker has no symbol with that name
- 10021Off QuotesTRADE_RETCODE_PRICE_OFFOff quotes: no current price for the symbol
EA Doctor rules that catch it
- MediumHard-coded symbol nameThe code names a symbol such as "EURUSD" or "XAUUSD", which breaks on brokers that use another name or a suffix.
Sources
Get your EA fixed
Still failing with 4302? Send us the EA and the journal lines: we find the cause in the code and fix it. Or check it yourself first with the EA Doctor.