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.

📖 15 min read

📝 3,000 words

🏷️ MQL5 & Expert Advisors

Share this article:

Try the workflow from this guide

Open the live demo first — no signup. Sign up later to save your strategy and export from Code Generator.


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) — including fixes for AI-generated code — not enough money (10019), trade disabled (10017, 10027), and why you should use OrderCheck() before sending.

Related guides: Can ChatGPT Write an MT5 EA? · EA Risk Management · Create and Edit an MT5 EA


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 too close to price or on the wrong side for Buy/Sell. Read SYMBOL_TRADE_STOPS_LEVEL with SymbolInfoInteger.

Quick fixes: widen SL/TP beyond the stop level (+ buffer), use NormalizeDouble, call OrderCheck() before OrderSend, or set SL/TP = 0 and manage exits in code.

Deep dive (step-by-step + full MQL5 patterns): MT5 Error 10016 — Invalid Stops Fix. Common with AI-generated EAs — see also EA risk management.


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 this EA in Strategy Builder

Start in the live demo — no signup required. Walk through signals, filters, and risk. Create a free account only when you want to save and export MQL5.

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. AI-generated EAs often miss this — see our ChatGPT MQL5 guide.

Backtests may use fixed spread and ignore some broker stop distances. Live servers enforce SYMBOL_TRADE_STOPS_LEVEL strictly. Add stops-level checks and NormalizeDouble before OrderSend. Full workflow: ChatGPT MQL5 EA guide and Invalid Stops section in this article.

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.

Try Strategy Builder — no signup

Try Strategy Builder — No Signup