On this page
Back to tutorials

Common MQL5 EA Errors (2026) | OrderSend, Invalid Stops, Runtime Fixes

Troubleshoot frequent MQL5 EA failures: compile errors, invalid stops (130), trade permissions, and runtime error handling with practical MT5 fixes.

📖 13 min read

📝 2,600 words

🏷️ MQL5 & Expert Advisors

Share this article:

Want to build a no-code strategy right now?

Create your free account in seconds and start building immediately.


Common MQL5 & EA Errors — From Compile to OrderSend

When your Expert Advisor won’t compile, or OrderSend fails with codes like 10016 (invalid stops) or 10019 (not enough money), you need a clear map of causes and fixes. The MQL5 Trade Server Return Codes describe every retcode returned in MqlTradeResult after OrderSend(). This guide covers compile errors, the most frequent trade return codes, invalid stops (10016), not enough money (10019), trade disabled (10017, 10027), and why you should use OrderCheck() before sending — with official references and quick solutions.


Compile Errors: Fix Before Running

Before your EA can run or send orders, it must compile in MetaEditor (F7). Common issues:

  • Undefined variable or function — Check spelling and that you included the right headers; MQL5 compilation errors list all codes.
  • Wrong types — e.g. passing int where long or double is required; fix types to match function signatures.
  • Missing semicolon or bracket — The compiler points to the line; fix the syntax and recompile.

Fix all errors (0 errors in the Build tab) before attaching the EA to a chart. Build your first EA and MQL5 programming reference help with structure and APIs.


Trade Server Return Codes (OrderSend)

OrderSend() sends a request to the trade server; the result is in MqlTradeResult. The retcode field is the server’s answer. Per MQL5: "All requests to execute trade operations are sent... using function OrderSend(). The function execution result is placed to structure MqlTradeResult, whose retcode field contains the trade server return code."

Important codes:

CodeConstantMeaning
10009TRADE_RETCODE_DONERequest completed
10008TRADE_RETCODE_PLACEDOrder placed
10016TRADE_RETCODE_INVALID_STOPSInvalid stops in the request
10017TRADE_RETCODE_TRADE_DISABLEDTrade is disabled
10019TRADE_RETCODE_NO_MONEYNot enough money
10027TRADE_RETCODE_CLIENT_DISABLES_ATAutotrading disabled by client
10031TRADE_RETCODE_CONNECTIONNo connection with the trade server

Always check result.retcode after OrderSend; do not assume true means the deal was executed.


Invalid Stops (10016)

TRADE_RETCODE_INVALID_STOPS (10016) means the broker rejected your Stop Loss or Take Profit — usually because they are too close to the current price. Each symbol has a minimum distance (in points) defined by the server. In MQL5 you can read it with SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL).

Fix:

  • Compute SL/TP so that |order_price - sl| and |order_price - tp| are at least SYMBOL_TRADE_STOPS_LEVEL points (use SymbolInfoDouble(symbol, SYMBOL_POINT) to convert).
  • Or set SL/TP to 0 and manage exits in code (e.g. close by market order later).

Not Enough Money (10019)

TRADE_RETCODE_NO_MONEY (10019) means margin or balance is insufficient for the requested volume. Check AccountInfoDouble(ACCOUNT_MARGIN_FREE) and required margin for the symbol/volume before sending.

Fix: Reduce lot size, or deposit more. Use EA risk management to size positions safely.


Trade Disabled (10017, 10027)

  • 10017 (TRADE_RETCODE_TRADE_DISABLED) — Trade disabled by the server (broker). Possible causes: symbol not tradeable, account restricted, or market closed.
  • 10027 (TRADE_RETCODE_CLIENT_DISABLES_AT)AutoTrading is off in the terminal. Press Ctrl+E or enable in Tools → Options → Expert Advisors.

Fix for 10027: Enable AutoTrading and ensure "Allow automated trading" is checked. For 10017, contact broker or try another symbol/account.


Use OrderCheck() Before OrderSend()

The OrderSend() docs recommend checking the request first: "It is recommended to check the request before sending it to a trade server. To check requests, use the OrderCheck() function." OrderCheck() returns whether the trade would be accepted and fills a structure with margin, free margin, and return code — so you can avoid sending orders that will fail with 10016 or 10019.


Quick Reference Table

Symptom / CodeCauseFix
Won’t compileSyntax/type errorsFix errors in MetaEditor; see errors compile.
10016 Invalid stopsSL/TP too close to priceRespect SYMBOL_TRADE_STOPS_LEVEL; or SL/TP = 0.
10019 No moneyInsufficient margin/balanceReduce lot; check margin before send.
10017 Trade disabledServer-side restrictionBroker/symbol/account; contact broker.
10027 Autotrading disabledClient terminalEnable AutoTrading (Ctrl+E), Options → EAs.
10031 No connectionNetwork / serverCheck connection; retry later.

Next Steps

References: MQL5 Trade Return Codes, OrderSend, OrderCheck, Compilation Errors, Runtime Errors.

Build your no-code trading strategy now — free

Create your account and start building a complete no-code strategy right now. Add indicators, filters, and risk rules, then export MQL5 in minutes.

Frequently Asked Questions

The broker rejected your SL/TP distance. Per MQL5 Trade Return Codes, TRADE_RETCODE_INVALID_STOPS (10016) means "Invalid stops in the request". Check SYMBOL_TRADE_STOPS_LEVEL with SymbolInfoInteger and place SL/TP at least that many points from the current price.

OrderSend() returns true when the request is accepted, not when the deal is executed. Always check result.retcode (e.g. 10009 = TRADE_RETCODE_DONE). For market orders, execution can complete after the function returns; use OnTradeTransaction to track fills.

Retcode 10017 = trade disabled by server; 10027 = Autotrading disabled by client. Enable the AutoTrading button (Ctrl+E) in MetaTrader 5 and, in Tools → Options → Expert Advisors, allow automated trading. For 10017, the broker may have restricted the symbol or account.

Build your no-code strategy now — free

Create Free Account