What it means
Trading isn't allowed for this request: the broker has disabled trading on the symbol, or the account can't trade. Unlike 10027, it isn't a switch in your terminal.
Usual causes
- The symbol's trade mode is "disabled".
SYMBOL_TRADE_MODEisSYMBOL_TRADE_MODE_DISABLED: you can see the symbol's quotes but not trade it on this account. A multi-symbol EA that trades everything in Market Watch runs into it. - The account can't trade.
AccountInfoInteger(ACCOUNT_TRADE_ALLOWED)isfalsewhen the terminal is connected with the investor (read-only) password, when the account was archived or switched to read-only, or when the broker disabled trading on it.
Partial restrictions have their own codes: long only (10042), short only (10043) and close only (10044), matching SYMBOL_TRADE_MODE_LONGONLY, SYMBOL_TRADE_MODE_SHORTONLY and SYMBOL_TRADE_MODE_CLOSEONLY.
How to detect it
result.retcode(ortrade.ResultRetcode()) is10017; the Experts tab shows[trade disabled]after the request.- Print
EnumToString((ENUM_SYMBOL_TRADE_MODE)SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE))for the symbol, andAccountInfoInteger(ACCOUNT_TRADE_ALLOWED)for the account.
Broken code
This script compiles. Every symbol whose trade mode is disabled on the account fails with 10017.
#include <Trade/Trade.mqh>
CTrade trade;
void OnStart()
{
// Buys every symbol in Market Watch, tradable or not
for(int i = 0; i < SymbolsTotal(true); i++)
{
string symbol = SymbolName(i, true);
trade.Buy(SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN), symbol);
}
}Fixed code
The same program with the check that prevents the error. It compiles in MetaEditor with 0 errors and 0 warnings.
#include <Trade/Trade.mqh>
CTrade trade;
// Empty string if a new buy may be opened on this symbol, otherwise why not
string BuyBlockedReason(const string symbol)
{
if(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
return "the account can't trade (investor password, read-only or disabled by the broker)";
ENUM_SYMBOL_TRADE_MODE mode = (ENUM_SYMBOL_TRADE_MODE)SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE);
if(mode == SYMBOL_TRADE_MODE_DISABLED)
return "trading is disabled for this symbol";
if(mode == SYMBOL_TRADE_MODE_CLOSEONLY)
return "the symbol only allows closing positions";
if(mode == SYMBOL_TRADE_MODE_SHORTONLY)
return "the symbol only allows sell positions";
return "";
}
void OnStart()
{
for(int i = 0; i < SymbolsTotal(true); i++)
{
string symbol = SymbolName(i, true);
string reason = BuyBlockedReason(symbol);
if(reason != "")
{
PrintFormat("%s skipped: %s", symbol, reason);
continue;
}
if(!trade.Buy(SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN), symbol))
PrintFormat("%s: buy failed, retcode %u (%s)", symbol, trade.ResultRetcode(), trade.ResultRetcodeDescription());
}
}Why the fix works
The script checks, before each order, the two things that make a server answer "trade is disabled": the account's permission and the symbol's trade mode. It also skips the partial modes that would refuse a buy. Symbols that can't be traded are listed with a reason instead of producing a failed request each.
Questions
Why is trading disabled on only one symbol?
Because the trade mode is set per symbol. A broker can show a symbol for quotes only, or switch a symbol to close-only, while the rest of the account trades normally. SYMBOL_TRADE_MODE tells you which.
Why can't my EA trade when I log in with the investor password?
The investor password gives read-only access: AccountInfoInteger(ACCOUNT_TRADE_ALLOWED) is false and no orders go through, manual or automated. Log in with the trading password.
Is MT5 error 10017 the same as MT4 error 133?
Yes. MQL4's error 133 (ERR_TRADE_DISABLED) is trade server return code 10017 in MQL5.
The programs on this page are minimal examples written to show the error and its fix, not trading systems. Some of them send orders when they run: try them on a demo account. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.