Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
Every EA eventually hits order errors, and a lot of EA problems come from handling them badly. The common response is to retry immediately, which can make things worse. Here are three I see often and how I think about them.
Error 130, invalid stops. Your stop loss or take profit is too close to the current price or on the wrong side of it. This often happens when the broker has a minimum stop level and the EA ignores it, or when price moves between calculating the stop and sending the order. The fix is to check the stop level from the symbol info before sending, and recalculate stops using a fresh price right before the order.
Error 134, not enough money. The account doesn't have the margin for the size. Retrying won't help. The EA should reduce size or skip, and log it so you notice.
Error 136, off quotes. The broker couldn't provide a price, often during fast markets or news. A short wait and a limited number of retries with a fresh price can make sense, but with a cap so the EA doesn't loop forever.
The general rule: separate errors that might clear on their own from errors that mean something is wrong with the order. Retry the first type a limited number of times. Stop and log the second type.
What does your EA do when an order fails?
Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
Re: Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
The error you get can depend on the execution mode. On instant execution accounts, a price change between your request and the server's check can return a requote. On market execution accounts you're more likely to get filled with slippage instead, and stops might have to be set after the trade opens rather than with the order. An EA written for one mode can behave badly on the other, so I'd check the execution mode of the account before trusting how it handles errors. If you ever move an EA between brokers, run it on a demo of the new one first and watch the journal for a day.
It’s Fairman 
Re: Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
I'd also log the full context with each error: the price the EA used, the current bid and ask, the stop level, the spread, and the time. A bare error number in the journal tells you something failed but not why. With the context you can see whether, for example, error 130 was caused by a stop that was too tight or by a spread spike right at that moment. That makes the difference between fixing the code and blaming the broker for something that was actually your own logic.
It’s Fairman 
Re: Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
Error 4108 and 4051 are two more I'd add to the list. 4108 is an invalid ticket, often when the EA tries to modify or close an order that's already closed. 4051 is an invalid function parameter, which can come from an unnormalised lot or price. Both are usually bugs in the EA rather than market conditions, so they should be logged loudly and investigated rather than retried automatically. In MT5, the equivalent errors have different codes, so if you move an EA between platforms, the error handling needs rewriting rather than copying across. A lookup table in the code for each platform helps keep that tidy.
It’s Fairman 
-
FXS Prop Desk
- Posts: 1689
- Joined: Wed Oct 07, 2026 9:52 am
Re: Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
One MT4 detail that catches people on the 136 retry: inside a loop, Bid and Ask are not updated by themselves. Without RefreshRates() before the second OrderSend, the EA resends the same stale price and gets rejected again, so the fresh price never actually arrives.
Two small additions to your list. Error 134 can be caught before sending by calling AccountFreeMarginCheck() for the planned lot size, which saves a pointless round trip to the server. And if several EAs share one terminal, error 146 (trade context busy) turns up more often than people expect; checking IsTradeContextBusy() with a short Sleep() in between handles it cleanly. It is also worth storing GetLastError() in a variable straight away, because a second call returns 0 and the log ends up showing no error at all.
Two small additions to your list. Error 134 can be caught before sending by calling AccountFreeMarginCheck() for the planned lot size, which saves a pointless round trip to the server. And if several EAs share one terminal, error 146 (trade context busy) turns up more often than people expect; checking IsTradeContextBusy() with a short Sleep() in between handles it cleanly. It is also worth storing GetLastError() in a variable straight away, because a second call returns 0 and the log ends up showing no error at all.
FXS Official Team | The Idea Lab & Strategy
Re: Handling OrderSend errors in MT4: 130, 134, 136 and what to do with each
I'd be careful with retries generally. Retrying on 136 (off quotes) or 138 (requote) with fresh prices is usually fine, but limit the number of attempts and the time. If the market is moving fast, retrying for a minute could fill you at a very different price from the signal. A rule like 'retry up to three times within ten seconds, then give up and log it' keeps the EA from chasing price. Has anyone found a better retry limit for fast markets? A short pause between retries helps too, so the EA isn't hammering the server.
It’s Fairman 