Trade server return code
10017 TRADE_ RETCODE_ TRADE_ DISABLED
Trade is disabled for the symbol or the account
What it means
The server does not allow trading in the request's context: the symbol is not tradable right now, or the account cannot trade. It is a state on the broker's side, not a mistake in the request, so resending it does not help.
Common causes
- The symbol's trade mode is
SYMBOL_TRADE_MODE_DISABLED("Trade is disabled for the symbol"), for example a contract around expiry or rollover. - The terminal is signed in with the investor (read-only) password, so
ACCOUNT_TRADE_ALLOWEDis false. - The broker has switched trading off for the account.
- A quotes-only symbol: some brokers show a reference symbol next to the tradable one with a suffix.
A real scenario
A trader watches a funded account from a second terminal signed in with the investor password and attaches the same EA there. The EA's signals fire, every order fails, and the journal fills up. A check of ACCOUNT_TRADE_ALLOWED in OnInit() now stops the EA with a clear message on the read-only terminal.
How to fix it
- Check
ACCOUNT_TRADE_ALLOWEDand the symbol'sSYMBOL_TRADE_MODEbefore trading, and say which one blocks it. - Handle the restricted modes too: long only, short only and close only have their own codes (10042, 10043, 10044).
- Stop retrying until the state changes; check again on the next bar or in
OnTimer().
Fixed MQL5 code
bool TradingAllowedFor(const string symbol)
{
if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
{
Print("This account cannot trade (for example, signed in with the investor password)");
return false;
}
ENUM_SYMBOL_TRADE_MODE mode = (ENUM_SYMBOL_TRADE_MODE)SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE);
if(mode == SYMBOL_TRADE_MODE_DISABLED)
{
PrintFormat("%s: trading is disabled for this symbol", symbol);
return false;
}
if(mode == SYMBOL_TRADE_MODE_CLOSEONLY)
PrintFormat("%s: only closing is allowed right now", symbol);
return mode != SYMBOL_TRADE_MODE_CLOSEONLY;
}
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
- 4752Trading by EAs ProhibitedERR_TRADE_DISABLEDTrading by Expert Advisors prohibited
- 10027Algo Trading DisabledTRADE_RETCODE_CLIENT_DISABLES_ATAlgo trading is switched off in the terminal
EA Doctor rules that catch it
- LowAlgo trading permission not checkedThe EA sends orders without checking that algo trading is allowed in the terminal, for the EA and on the account, so every order fails when one is off.
Sources
Get your EA fixed
Still failing with 10017? 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.