MQL5 trade server return code

MQL5 Error 10017: Trading disabled by the server

MQL5 error 10017 is TRADE_RETCODE_TRADE_DISABLED, the official trade server return code for trading disabled by the server. Confirm that the account and server allow trading, then check the symbol trade mode and session. Code cannot override a broker or account restriction; use an account and symbol for which the server permits the requested operation. Read MqlTradeResult.retcode after OrderSend because a successful function return does not by itself mean that the order was executed.

Open the Coding Agent and choose MQL5 from the language menu.

Check retcode 10017.mq5
bool TradingContextAllowsEA(const string symbol)
  {
   bool account_allowed=(bool)AccountInfoInteger(ACCOUNT_TRADE_ALLOWED);
   bool expert_allowed=(bool)AccountInfoInteger(ACCOUNT_TRADE_EXPERT);
   long symbol_mode=SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE);

   PrintFormat("account=%s expert=%s symbol_mode=%d",
               account_allowed ? "on" : "off",
               expert_allowed ? "on" : "off",
               symbol_mode);
   return account_allowed && expert_allowed &&
          symbol_mode!=SYMBOL_TRADE_MODE_DISABLED;
  }
  • Official code: TRADE_RETCODE_TRADE_DISABLED
  • Meaning: Trading disabled by the server
  • Layer: trade server response
  • Verify: MqlTradeResult.retcode

What error 10017 actually reports

The code belongs to MqlTradeResult.retcode, not to the compiler error list and not necessarily to GetLastError. The trade server uses 10017 to report trading disabled by the server.

Keep the request, the boolean returned by OrderSend, result.retcode, result.comment, and the symbol properties in the same log record. That separates a client-side request failure from a server-side rejection.

Inspect the request before changing the strategy

Use the smallest failing order and compare every broker-sensitive value with the current symbol and account. Do not hide the error by retrying unchanged input.

  • Check ACCOUNT_TRADE_ALLOWED and ACCOUNT_TRADE_EXPERT.
  • Read SYMBOL_TRADE_MODE for the exact broker symbol.
  • Confirm the login is a trading account rather than an investor or read-only login.
  • Ask the broker about account, instrument, or regulatory restrictions if the flags disagree with the rejection.

Repair and verify

Confirm that the account and server allow trading, then check the symbol trade mode and session. Code cannot override a broker or account restriction; use an account and symbol for which the server permits the requested operation.

Run OrderCheck with the completed request, log its retcode and comment, then send only if the check is acceptable. OrderCheck improves diagnostics but does not guarantee execution.

Use a focused diagnostic

This guard records account and symbol permissions before the request. A server can still reject trading for a condition not represented by these local flags.

A valid request can still be rejected or filled differently by the trade server. Check the returned retcode, test with the broker symbol and account, and review risk before any live order.

Check retcode 10017.mq5
bool TradingContextAllowsEA(const string symbol)
  {
   bool account_allowed=(bool)AccountInfoInteger(ACCOUNT_TRADE_ALLOWED);
   bool expert_allowed=(bool)AccountInfoInteger(ACCOUNT_TRADE_EXPERT);
   long symbol_mode=SymbolInfoInteger(symbol,SYMBOL_TRADE_MODE);

   PrintFormat("account=%s expert=%s symbol_mode=%d",
               account_allowed ? "on" : "off",
               expert_allowed ? "on" : "off",
               symbol_mode);
   return account_allowed && expert_allowed &&
          symbol_mode!=SYMBOL_TRADE_MODE_DISABLED;
  }
Where Pineify fits

Repair editable MQL5 source with compiler feedback

Pineify can generate or revise MQL5 source and use MQL5 compilation diagnostics during the coding workflow. Keep the exact error, source location, program type, and intended behavior in the request so the change remains reviewable.

Open MQL5 Coding Agent

Pineify does not run your broker terminal, Strategy Tester, market data, or live orders. Validate the final program in your own MetaTrader 5 environment.

Review MQL5 AI Coding Agent capabilities
Pineify MQL5 AI Coding Agent with an editable MetaTrader 5 code artifact

A practical verification workflow

  1. 1

    Capture the complete result

    Log the OrderSend return value, result.retcode, result.comment, symbol, order type, volume, price, stops, and filling mode. Confirm that the retcode is 10017.

  2. 2

    Read current constraints

    Query the symbol and account immediately before building the request. Broker constraints can differ between symbols and sessions.

  3. 3

    Change the invalid field

    Confirm that the account and server allow trading, then check the symbol trade mode and session. Code cannot override a broker or account restriction; use an account and symbol for which the server permits the requested operation.

  4. 4

    Check, send, and retest

    Call OrderCheck, submit the corrected request, then reproduce it in Strategy Tester and a demo account before considering live use.

Frequently asked questions

What does MQL5 error 10017 mean?

It is TRADE_RETCODE_TRADE_DISABLED, the official MQL5 trade server return code for trading disabled by the server.

Is 10017 a GetLastError code?

Treat it as a trade server return code when it appears in MqlTradeResult.retcode. GetLastError reports the terminal runtime error layer, which is a separate diagnostic channel.

Does OrderSend returning true mean the trade executed?

No. The official OrderSend reference says true means the request passed basic checks and was accepted for processing. Inspect result.retcode and subsequent trade events to determine the outcome.

Last verified against the linked official references on . Compile and test the final source in the MetaTrader 5 build, broker, symbol, and account environment you plan to use.

Continue with reviewable MQL5 source

Provide the exact diagnostic and intended behavior, inspect the generated change, compile it, and verify it in your MT5 test environment.

Open MQL5 Coding Agent