Delete Pendings Inside Stop Zone
MetaTrader does not reject an order for merely sitting near the current price - only for being SENT or MODIFIED that close. A grid, ladder, or manually placed pending order can drift into the stop or freeze zone simply because price moved toward it, and it will keep showing normally in the Terminal even though it is now effectively frozen: any attempt to modify it will be rejected, and on some brokers even the trigger behaviour near the freeze boundary is unreliable. This script scans every pending order, computes its distance in points from the relevant side of the current market (Ask for buy-side pendings, Bid for sell-side pendings - the same reference MetaTrader itself uses when it rejects a too-close send), and compares that distance to MAX(stop level, freeze level) for that order's OWN symbol. Both figures are read per symbol rather than assumed, since a JPY cross, a gold contract, and a 5-digit FX pair can all carry different point-distance minimums on the same account. Anything found inside its own zone is listed and, after confirmation, deleted. Nothing outside the zone is touched. Notes and limitations - Only pending limit and stop orders are considered. Open market positions have no stop-level restriction of this kind and are ignored. - A symbol reporting a stop/freeze level of zero is treated as having no minimum published and is skipped entirely for that symbol - the script does not invent a minimum. - Distance is measured against the CURRENT market price at the moment the script runs. An order just outside the zone when the scan runs can still drift inside it moments later; this is a one-shot check, not a running monitor. - Deleting an order inside its stop/freeze zone is intentional and irreversible - it removes the resting instruction rather than trying to move it, since MQL4 cannot modify an order that close either.
Script · MT5 · v1.0 · Free
About Delete Pendings Inside Stop Zone
Delete Pendings Inside Stop Zone is an expert advisor (trading robot) for MetaTrader 5. It places pending buy/sell stop or limit orders. It has 5 settings, such as Current symbol only, Magic filter and Confirm first. MQL source code included.
Files in the download: DeletePendingsInStopZone.ex5, DeletePendingsInStopZone.mq5, DeletePendingsInStopZone.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Current symbol only | false | Restrict to this chart's symbol |
| Magic filter | -1 | Only orders with this magic (-1 = ignore magic) |
| Confirm first | true | Ask for confirmation before deleting anything |
| Max retries | 5 | Attempts per order before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Grid · Pending Orders · MT5 Script · MQL5 Source Code