The short answer
MetaTrader reports a failed trade with a number. MT4 uses error codes such as 130 (invalid stops), 131 (invalid trade volume), 134 (not enough money), 138 (requote) and 146 (trade context is busy). MT5 returns trade server codes in the 10004–10046 range, such as 10016 (invalid stops), 10019 (not enough money) and 10030 (invalid filling type). The tables below give every trade code with MetaQuotes’ own wording, the usual cause on gold, and the fix.
If you trade by hand and saw a sentence rather than a number, our plain-English guide to MT5 gold errors is the faster read.
Where to find the code
- MT4: Terminal window → Journal tab (manual trades) or Experts tab (EAs and scripts). An EA reads it with
GetLastError(). - MT5: Toolbox → Journal or Experts. An EA reads
result.retcodeafterOrderSend().
Before fixing anything, open the gold symbol’s Specification (right-click in Market Watch). Most errors are a mismatch with one of its lines: contract size, minimum volume, volume step, stops level, freeze level, trade mode, filling modes or sessions.
MT4 trade error codes
| Code | MetaQuotes description | Usual cause on gold | Fix |
|---|---|---|---|
| 1 | No error returned, but the result is unknown | OrderModify sent the same SL/TP already set | Only modify when a value changes |
| 2 | Common error | Generic rejection | Check the Journal text; retry once |
| 3 | Invalid trade parameters | Wrong function arguments in the EA | Fix the code |
| 4 | Trade server is busy | Server load | Wait and retry |
| 5 | Old version of the client terminal | Outdated terminal build | Update MT4 |
| 6 | No connection with trade server | Connection lost | Check the status bar and login |
| 7 | Not enough rights | Login lacks trading permission | Check you used the master password; ask the provider |
| 8 | Too frequent requests | EA sending orders in a loop | Add delays; send only on new conditions |
| 9 | Malfunctional trade operation | Request the server could not process | Check the Journal; contact the provider if it repeats |
| 64 | Account disabled | Account blocked | Contact the provider |
| 65 | Invalid account | Wrong account or server | Check login details |
| 128 | Trade timeout | Server did not answer in time | Check open positions before retrying, to avoid a duplicate |
| 129 | Invalid price | Price outdated or wrong side for a pending order | Refresh rates; use Ask for buys, Bid for sells |
| 130 | Invalid stops | SL/TP too close or wrong side | See invalid stops on gold |
| 131 | Invalid trade volume | Lot not a multiple of the step, or outside min/max | Round to the volume step (often 0.01) |
| 132 | Market is closed | Weekend, daily break, holiday | Check gold market hours |
| 133 | Trade is disabled | Investor login, wrong symbol, close-only | Master password; correct symbol; check Trade mode |
| 134 | Not enough money | Free margin too low | Smaller lot; gold margin calculator |
| 135 | Price changed | Price moved before execution | Refresh and resend |
| 136 | Off quotes | No price available (news, thin market) | Wait; avoid the seconds around releases |
| 137 | Broker is busy | Dealer queue | Wait and retry |
| 138 | Requote | Price moved beyond allowed slippage (instant execution) | Retry; widen the slippage parameter sensibly |
| 139 | Order is locked | Order being processed | Wait |
| 140 | Buy orders only allowed | Symbol set to long only | Check Trade mode |
| 141 | Too many requests | Request flood | Throttle the EA |
| 145 | Modification denied because order is too close to market | Inside the freeze level | Wait until price moves away |
| 146 | Trade context is busy | Another order is being processed in the terminal | See below |
| 147 | Expirations are denied by broker | Pending order sent with an expiry time | Send with no expiration |
| 148 | The amount of open and pending orders has reached the limit set by the broker | Order cap reached | Close or delete orders |
| 149 | An attempt to open an order opposite to the existing one when hedging is disabled | No-hedging account | Close the existing position instead |
| 150 | An attempt to close an order contravening the FIFO rule | FIFO account | Close the oldest position first |
Runtime codes EA users meet most:
| Code | MetaQuotes description (short) | Fix |
|---|---|---|
| 4108 | Invalid ticket | The order no longer exists; refresh your order list |
| 4109 | Trade is not allowed (enable “Allow live trading” in the EA properties) | Tick it and turn on AutoTrading |
| 4110 | Longs are not allowed | Check the EA’s Common tab position setting |
| 4111 | Shorts are not allowed | Same as above |
| 4112 | Automated trading by Expert Advisors/Scripts disabled by trade server | Provider has switched off EAs for the account; ask it |
MT5 trade server return codes
| Code | MetaQuotes description | Usual cause on gold | Fix |
|---|---|---|---|
| 10004 | Requote | Price moved (instant or request execution) | Retry; set a sensible deviation |
| 10006 | Request rejected | Server refused it | Check the Journal text |
| 10007 | Request canceled by trader | You or the EA cancelled | None |
| 10008 / 10009 | Order placed / Request completed | Success | None |
| 10010 | Only part of the request was completed | Partial fill | Check the filled volume |
| 10011 | Request processing error | Generic | Retry once, then check logs |
| 10012 | Request canceled by timeout | Slow response | Check positions before resending |
| 10013 | Invalid request | Malformed request | Fix the code |
| 10014 | Invalid volume in the request | Volume step or limits | Round to the step |
| 10015 | Invalid price in the request | Stale or wrong-side price | Use current Ask/Bid |
| 10016 | Invalid stops in the request | SL/TP wrong side or inside stops level | See invalid stops on gold |
| 10017 | Trade is disabled | Investor login, symbol disabled | Master password; check Trade mode |
| 10018 | Market is closed | Outside sessions | Check sessions |
| 10019 | There is not enough money to complete the request | Free margin | Smaller lot |
| 10020 | Prices changed | Fast market | Resend with fresh prices |
| 10021 | There are no quotes to process the request | No price (news, open, break) | Wait |
| 10022 | Invalid order expiration date in the request | Expiry type not allowed | Use an allowed expiration mode |
| 10023 | Order state changed | Order already modified or filled | Refresh |
| 10024 | Too frequent requests | Request flood | Throttle |
| 10025 | No changes in request | Same SL/TP resent | Modify only on change |
| 10026 | Autotrading disabled by server | Provider blocks EAs | Ask the provider |
| 10027 | Autotrading disabled by client terminal | Algo Trading button off | Turn it on; check EA settings |
| 10028 | Request locked for processing | Being processed | Wait |
| 10029 | Order or position frozen | Inside the freeze level | Wait until price moves away |
| 10030 | Invalid order filling type | Filling mode not allowed | Use an allowed mode (see below) |
| 10031 | No connection with the trade server | Connection | Reconnect |
| 10032 | Operation is allowed only for live accounts | Demo restriction | None on demo |
| 10033 | The number of pending orders has reached the limit | Order cap | Delete orders |
| 10034 | The volume of orders and positions for the symbol has reached the limit | Volume cap on gold | Reduce size |
| 10035 | Incorrect or prohibited order type | Type not allowed on the symbol | Use another order type |
| 10036 | Position with the specified POSITION_IDENTIFIER has already been closed | Closing twice | Refresh positions |
| 10038 | A close volume exceeds the current position volume | Partial close too big | Close up to the open volume |
| 10039 | A close order already exists for a specified position | Duplicate close | Wait for the first close |
| 10040 | Positions limit reached (server setting) | Too many open positions | Close some |
| 10041 | The pending order activation request is rejected, the order is canceled | Activation failed (often margin) | Check margin; re-place |
| 10042 | Only long positions are allowed for the symbol | Long-only mode | Check Trade mode |
| 10043 | Only short positions are allowed for the symbol | Short-only mode | Check Trade mode |
| 10044 | Only position closing is allowed for the symbol | Close-only mode | You can only close; ask why (often a contract change) |
| 10045 | Position closing is allowed only by FIFO rule | FIFO account | Close the oldest first |
| 10046 | Opposite positions on a single symbol are disabled | Hedging prohibited | Close instead of opening the opposite side |
Some long descriptions above are shortened; the full wording is in the MQL5 documentation linked under Sources.
“Trade context is busy” (MT4 error 146)
MT4 processes one trade request at a time from a terminal. When two EAs, or an EA and a script, try to send, modify or close orders at the same moment, one gets 146. On gold this often shows up at the open of a new candle, when several EAs on different timeframes act together, or around news when requests take longer.
Fix it in this order:
- Check before sending: in the EA, test
IsTradeContextBusy()and wait (for example 100–500 ms) while it returns true, with a maximum number of attempts. - Don’t loop blindly: after a 146, refresh rates with
RefreshRates()before retrying, because the price may have moved. - Spread the load: run fewer trading EAs per terminal, or separate terminals for EAs that trade at the same moment.
- Check for duplicates after any retry, especially after a 128 timeout.
MT5 handles requests differently and does not use this error.
Filling type errors (MT5 10030)
Every MT5 symbol allows certain filling policies: Fill or Kill (the whole volume or nothing), Immediate or Cancel (fill what you can, cancel the rest), and Return (for exchange-style execution). Gold symbols on different servers allow different ones. In MT5 the allowed modes are shown in the Specification and can be read in code with SymbolInfoInteger(_Symbol, SYMBOL_FILLING_MODE). Set request.type_filling to an allowed value. Our glossary has a short note on fill policy.
Close-only, FIFO and hedging codes
- Close-only (10044, also 133 in MT4): the provider has stopped new positions on that symbol, often while a futures-based gold CFD rolls to a new contract or before a symbol is retired. Existing positions can be closed.
- FIFO (150 / 10045): accounts where the oldest position must be closed first. Close in opening order, or use one position per direction.
- Hedging prohibited (149 / 10046): a buy and a sell on the same symbol can’t coexist. On MT5 netting accounts, a sell simply reduces the buy; see netting mode and hedging mode.
Prevent errors before they happen
- Read the gold Specification once per account and store min lot, step, stops level, freeze level, filling modes and sessions in the EA’s settings or your notes.
- Size with the position size calculator and round down to the step.
- Keep free margin high, so 134/10019 never appear.
- Give EAs a pause around scheduled releases and the 5 pm New York break.
- Before running any EA live, read our EA and bots checklist.
More fixes: gold trading problems solved.
Sources
- MetaQuotes, MQL4 documentation: Error codes
- MetaQuotes, MQL5 documentation: Trade server return codes
- MetaQuotes, MQL4 book: Requirements and limitations in making trades
Educational content only, not financial advice. Platform messages can differ slightly by build and provider. Trading gold with leverage carries a high risk of loss.
Frequently asked questions
What does 'trade context is busy' (error 146) mean in MT4?
MT4 lets only one trade request be processed at a time from the terminal. If an expert advisor or script sends an order while another one is still being processed, MT4 returns error 146, ‘Trade context is busy’. Check IsTradeContextBusy() before sending, wait briefly and retry, and avoid running many EAs that trade at the same instant in one terminal.
What is MT5 error 10016?
TRADE_RETCODE_INVALID_STOPS, ‘Invalid stops in the request’. The stop-loss or take-profit is on the wrong side of the price or closer than the symbol’s stops level. It is the MT5 equivalent of MT4 error 130.
What does MT5 error 10030 'Invalid order filling type' mean?
The order asked for a filling policy (such as Fill or Kill, Immediate or Cancel, or Return) that the symbol does not allow on your server. In an EA, read the symbol’s allowed filling modes and set the request’s type_filling to one of them.
What do error 4109 in MT4 and 10027 in MT5 mean?
Automated trading is switched off on your side. In MT4, 4109 means live trading is not allowed for the EA: tick ‘Allow live trading’ in the EA’s properties and turn on the AutoTrading button. In MT5, 10027 ‘Autotrading disabled by client terminal’ means the Algo Trading button is off or the EA’s settings block trading.
Why does my EA get 'trade is disabled' (133 / 10017) on gold?
Trading is switched off for that symbol or that login: you may be logged in with the investor password, using a symbol that belongs to another account type, or the symbol may be in close-only mode around a contract change. Check the symbol’s Specification (Trade mode) and log in with the master password.
Comments
No comments yet.