Trade server return code
10021 TRADE_ RETCODE_ PRICE_ OFF
Off quotes: no current price for the symbol
What it means
The server had no current quote to fill the request against. It happens when a symbol has not ticked yet, its feed is paused, or the dealer is not quoting it at that moment.
Common causes
- Trading a symbol at the weekly open before its first tick of the week.
- A multi-symbol EA trading a thin cross or an exotic pair with long gaps between ticks.
- A symbol just added to Market Watch whose prices have not arrived yet.
- Requests sent during a feed interruption on the broker's side.
A real scenario
A multi-symbol EA scans 20 pairs on a timer and sends its Monday entries at the weekly open. Some exotic crosses have not ticked yet, so those orders fail with 10021 while the majors fill. The EA now waits until each symbol has a recent tick.
How to fix it
- Read the tick with
SymbolInfoTick()and check its time and that Bid and Ask are above zero. - Skip symbols whose last tick is older than a limit you choose, and try again later.
- Make sure each symbol is selected in Market Watch (see 4302) so its quotes update.
Fixed MQL5 code
bool HasFreshQuote(const string symbol, const int maxAgeSeconds = 60)
{
MqlTick t;
if(!SymbolInfoTick(symbol, t) || t.bid <= 0.0 || t.ask <= 0.0)
return false;
return (TimeCurrent() - t.time) <= maxAgeSeconds; // skip symbols that have not ticked recently
}
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
- 10018Market ClosedTRADE_RETCODE_MARKET_CLOSEDMarket is closed: the request was sent outside a trading session
- 10020Prices ChangedTRADE_RETCODE_PRICE_CHANGEDPrices changed while the request was processed
- 4302Symbol Not SelectedERR_MARKET_NOT_SELECTEDSymbol not selected in Market Watch
Sources
Get your EA fixed
Still failing with 10021? 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.