Page 1 of 1
Having an EA stop itself after three rejected orders in a row
Posted: Thu Oct 22, 2026 6:20 am
by Fairman
Having an EA stop itself after three rejected orders in a row
Most EAs I've seen handle a rejected order by retrying. Retry once, maybe twice with a short pause, then give up on that signal. That's reasonable for a one off rejection. What they usually don't handle is a run of rejections across several signals, which is often a sign that something bigger is wrong.
A single requote during news is normal. Three rejections in a row over twenty minutes in a quiet market is not. It could be the broker changing something on the account, a symbol going into close only mode, a margin problem, the server having issues, or the EA itself sending invalid prices or volumes after a change in the symbol specs.
So I added a simple counter. Every rejected order increments it, every successful order resets it to zero. If the counter reaches three, the EA stops opening new trades, sends a notification to my phone and writes the error codes to the log. Existing positions are still managed, stops and exits included. It just won't open anything new until I look at it and reset the flag.
This has the downside that it can pause during a genuinely busy period when requotes are frequent. I accept that. An EA that keeps firing orders into a broken setup is much worse than one that waits for me to check.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Wed Oct 28, 2026 2:58 pm
by FXS HongKong Scalper
A pause after repeated rejections is a good safety feature. I would also make the EA write the retcodes of those rejections into a single alert, so the reason is clear without digging through logs. A 10018 market closed means something very different from a 10019 no money or a 10027 autotrading disabled by the client. Some of these can resolve on their own, while others mean the account settings have changed. Sending that summary to a phone through push notifications lets you check the account quickly before the next session starts.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Thu Oct 29, 2026 4:05 pm
by Fairman
The error codes matter for deciding what to do next. In MQL4, codes like 134 for not enough money point to margin, 130 for invalid stops points to a stop level problem, and 133 for trade disabled points to the symbol or account. I store the code with each rejection so the notification tells me which kind of problem it is. Different codes need very different responses, and seeing them in the message saves time. Some brokers use different codes or add their own messages, so I'd check the exact text in the Experts tab as well. Mapping the common ones to plain words in the notification makes them readable at a glance on a phone. A short table in the code that turns each code into a few words is enough, and it can be extended whenever a new code shows up.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Thu Oct 29, 2026 6:30 pm
by Fairman
Some rejections should count differently. A requote during a scheduled news release is expected and probably shouldn't push the counter toward a pause. I give the EA a list of news times and skip counting rejections within a few minutes of them. Outside those windows every rejection counts. This keeps the pause from triggering on routine news volatility while still catching real problems. The news list can be a simple CSV the EA reads at startup. Updating it weekly from the calendar takes a minute, and the EA then knows when to be more tolerant of rejections and when to be strict.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Thu Oct 29, 2026 8:31 pm
by Fairman
When the EA pauses, it's tempting to just reset it and carry on. I try to always find the reason first. Most of the time it's something mundane, like the broker changing the minimum stop distance or the account running low on margin after other positions. Occasionally it's a sign the broker is having serious issues, and that's exactly the time you don't want an EA sending more orders. It's useful to log what the fix was each time, too. After a while you build a short list of the usual causes, and the next pause takes a minute to resolve instead of an hour of digging through settings.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Fri Oct 30, 2026 6:30 am
by Fairman
Persist the counter to a file or a global variable so it survives a terminal restart. Otherwise a restart, which might happen automatically on some VPS setups, resets it to zero and the EA starts trading again into the same problem. The paused state should only clear when you deliberately clear it, not because the platform reloaded the EA. Global variables in MetaTrader survive restarts for a few weeks by default, which is long enough for this purpose. A small file in the terminal's data folder is more permanent if you want it to persist indefinitely.
Re: Having an EA stop itself after three rejected orders in a row
Posted: Sat Oct 31, 2026 10:50 am
by Shadow Trader
Every platform logs rejections: off quotes, invalid price, market closed, no money, trade context busy. Most scalpers glance at the error and click again. The pile of rejected orders, though, is a free dataset about what the broker's server is doing.
Count them by hour. A cluster at the top of the hour or right after news says something about load. A cluster of "invalid price" errors on tight stops points at stop-level rules. A burst of requotes on one pair and none on another points at different liquidity behind each.
Look at what the market did next. If rejected buys tend to be followed by price rising, and rejected sells by price falling, the rejections are removing winners. That's the signature of last look or selective handling.
Few people ever export this. The journal shows only filled trades, and the picture looks cleaner than it really was.
Has anyone counted how many orders were rejected in a month, and what price did afterwards?
Re: Having an EA stop itself after three rejected orders in a row
Posted: Sat Oct 31, 2026 11:22 am
by GrahamW1972
Shadow Trader wrote:Has anyone counted how many orders were rejected in a month, and what price did afterwards?
shadow trader you're dead right about the journal only showing the fills, it flatters you something rotten. i did this for a couple of months on one pair, and the easy way is to have the EA write the requested price and a timestamp on every rejection, then log bid again a minute later, rather than trawling the Experts tab afterwards. my rejects bunched up around the top of the hour and news, but the price afterwards was a bit of a coin toss, so i couldnt pin it on last look... cant say it'll be the same for your broker though, fair play for asking.