Troubleshooting
MT5 Order Filling Modes Explained: FOK, IOC and Return, and How to Fix an Invalid Fill Error
By Benjamin Lee · Updated · 7 min read
You attach an Expert Advisor, it tries to open a trade, and the journal fills with errors about an unsupported or invalid filling type. Nothing is wrong with the EA's strategy. The broker supports a different way of filling orders than the one the EA asks for. Filling modes are one of the most common causes of an EA that runs but never trades, and the fix is usually one input or one account choice. This guide explains the three modes, how they behave when the market is thin, and how to find the one your broker supports.
Key takeaways
- A filling mode tells the broker what to do if the full volume cannot be filled at the requested price.
- The three common modes are Fill or Kill, Immediate or Cancel and Return.
- Each symbol at each broker supports certain modes. Asking for one it does not support fails the order.
- The error code is usually 10030, an invalid filling type.
- The fix is to use the mode the symbol supports, often through an EA input.
What a filling mode is
When an order reaches the broker, the full volume may not be available at the price you asked for. The filling mode is an instruction that tells the server what to do about the part that cannot be filled. MetaTrader 5 defines the options in the order request, and the MQL5 documentation lists the constants and the return codes on the page about trade server return codes.
| Mode | Short name | What happens | Typical use |
|---|---|---|---|
| Fill or Kill | FOK | The whole volume is filled at once at the price, or the order is cancelled | Brokers that fill whole orders, common for forex market execution |
| Immediate or Cancel | IOC | The available volume is filled at once, and any remainder is cancelled | Markets with variable depth, common on gold and indices |
| Return | Return | The available volume is filled, and the rest stays in the market as an order | Exchange-style execution and many pending orders |
For a small retail order, the difference rarely matters in practice, because the full volume is almost always available. It matters in a fast market or with a large lot, when the best price can supply only part of the volume. In that case FOK rejects the order, IOC gives you a partial fill and Return leaves an order resting at the broker.
Execution type and why it matters
The filling mode works together with the symbol's execution type: market, instant, request or exchange. In market execution, the broker fills at the market price when the order arrives, and the filling mode controls partial fills. In instant execution, you send a price and a deviation, and the broker fills if the price is within it. You can read the execution type and the allowed filling modes in the symbol specification: right-click the symbol in Market Watch and choose Specification.
The invalid filling type error
If the EA asks for a mode that the symbol does not support, the server refuses the order and the terminal reports return code 10030, an unsupported filling type, with a message such as invalid fill. Because the symbol list and settings differ by broker and account type, an EA that works on one account can fail on another.
How to fix it
Step 1: Check the EA's inputs
Many EAs have a filling mode input, sometimes called filling type, order filling or type filling. Try the other values: FOK, IOC and Return.
Step 2: Read the symbol specification
In Market Watch, right-click the symbol, choose Specification, and read the execution mode and the filling modes allowed. Choose one from that list.
Step 3: Try an auto setting
Some EAs offer an automatic option that picks the mode from the symbol. Use it if the manual says it is supported.
Step 4: Check the symbol
A suffixed symbol such as XAUUSD.m can have a different execution mode from the plain one. Use the symbol your EA is meant for.
Step 5: Check the account type
Standard, raw-spread and cent accounts at the same broker can have different modes. Ask support if the specification is unclear. See account types for EAs.
Step 6: Contact the seller with the journal
If no input exists, send the seller the error text and the broker name. They may offer a build for your broker.
Which mode should you choose?
| Situation | Usual choice | Why |
|---|---|---|
| The broker allows only one mode for the symbol | That mode | No choice |
| Market execution, small lots, forex | FOK or IOC | Either works; follow the specification |
| Gold or indices with larger lots | IOC | Allows partial fills in thin moments |
| Pending orders | Return | Orders rest in the market until filled |
| EA offers an automatic mode | Auto | Selects what the symbol allows |
Be careful with IOC and Return in a strategy that depends on a full-size fill. A partial fill leaves you with a smaller position than the EA expected, and its stop and take profit logic may assume the full volume. Test on demo, then check the filled volume in the History tab.
Filling modes, slippage and news
In a fast market the price can move between sending the order and its arrival. The deviation setting tells the broker how far from the requested price you will accept a fill. A tight deviation with FOK can mean many rejected orders around news, while a loose one gives fills at poor prices. Our spread and slippage guide explains the trade-off, and the gold news guide covers what happens at releases.
A worked example: five lots, three available
Suppose an EA sends a market order to buy 5 lots of gold, and at the moment it arrives the broker can fill only 3 lots at your price or better. With Fill or Kill the whole order is cancelled and the EA receives a refusal; no position opens. With Immediate or Cancel the broker fills 3 lots and cancels the remaining 2, so you hold 3 lots and the EA must cope with a smaller position than it planned. With Return the broker fills 3 lots and leaves a pending order for the other 2 resting in the market, which can fill later at a worse price, or never.
For small lots this almost never happens, which is why most retail traders never notice. It matters in fast markets and with large sizes, and it matters for an EA that assumes each order is fully filled. A robust EA reads the filled volume after sending the order and sizes its stop and take profit to what it actually holds. If yours does not, prefer Fill or Kill where the broker allows it, and keep lot sizes small.
What a well-built EA does with filling modes
- Reads which modes the symbol allows and chooses one that is supported, instead of using a fixed default.
- Checks the result code of every order request, not only whether the call returned.
- Handles a partial fill by adjusting protective orders to the filled volume.
- Does not retry endlessly after a refusal, so it does not hit the broker's request limit.
- Logs the mode and result so you can see what happened.
Sources and further reading
- MQL5 Reference: Trade Server Return CodesWhat the codes returned for a refused trade request mean, including 10027.
- MQL5 Reference: Runtime ErrorsMeaning of terminal error codes such as 4752 and 4756.
- MQL5 Reference: Trade Request StructureThe magic field an Expert Advisor uses to tag its own orders.
Frequently asked questions
What is the invalid filling type error in MT5?
It is return code 10030. The EA asked for a filling mode that the symbol at your broker does not support, so the order was refused. Switch the EA's filling input to a mode the symbol allows.
What is the difference between FOK and IOC?
Fill or Kill fills the whole volume at once or cancels the order. Immediate or Cancel fills what is available at once and cancels the remainder, so you may get a partial fill.
Where do I find which filling modes my broker supports?
In Market Watch, right-click the symbol and choose Specification. It lists the execution mode and the allowed filling modes. If it is unclear, ask the broker's support.
Does the filling mode affect profit?
Indirectly. It decides whether orders are filled in full, in part or rejected, which changes the position you actually hold. In fast markets it can affect the fill price too.
My EA worked on one broker but not on another. Why?
Brokers support different filling modes, and a symbol can allow different ones by account type. Change the EA's filling input to match the new broker's specification.
Expert Advisors in these styles
Apply the checks above to any of these before you buy: read the manual, run your own backtest, and start on demo.
Keep reading
- Pillar guideMT5 Expert Advisors: The Complete Guide for BeginnersEverything about MetaTrader 5 Expert Advisors in one place: how they work, strategy types, risk, backtesting, buying safely, gold, EURUSD, prop firms and Europe.
- EA basicsHow to Install and Run an EA on MT5Install an Expert Advisor on MetaTrader 5, load a setfile, set safe risk limits, and run it on a VPS. A practical walkthrough with a pre-live checklist.
- Buying guideEA Buying Checklist: 15 Questions to Ask Before You Pay15 questions to ask before buying an MT5 Expert Advisor: who built it, licence terms, backtest proof, risk logic, support and refunds, with a printable checklist.
- Gold EAsXAUUSD EA Settings: Lot Size, Stop Loss, Spread, HoursWhat each XAUUSD Expert Advisor input does and how to size it: lot size, stop loss, spread filter, slippage, trading hours and magic number, with euro examples.


