Delete Pendings Beyond N Pips
Ladders accumulate stale rungs. Price runs three hundred pips in a session and the far end of the grid is now a set of orders that will only fill if the whole move reverses - which is not the trade you were in, and is often a trade you would refuse if someone offered it. The near rungs are still valid. Deleting the whole ladder is wrong and deleting nothing is worse, so people prune by hand, reading prices off the Trade tab and doing the subtraction in their head. This script does the subtraction. Give it a distance in pips; anything further than that from the current market goes, per symbol, and everything inside the band stays. Three decisions separate it from a naive distance loop, and all three change which orders get deleted. Distance is measured against the side of the quote the order would actually fill on. A buy fills at the ask and a sell fills at the bid. Measuring every order against the bid - which is what almost every version of this does, because Bid is the variable that is sitting right there - reports every buy order wrong by one full spread. On EURUSD that is a rounding error. On an index, a metal, or anything during a thin session, one spread is comfortably more than the gap between two rungs, and the script prunes the wrong one. The distance is measured again immediately before each delete. Price moves while a script runs, and an order that came back inside the band between the list being built and its turn arriving is no longer stale. It is left alone and reported as skipped. Deleting it would mean deleting an order that satisfies the rule you typed, on the grounds that it did not satisfy it half a second ago. And the default run does not delete anything. A selection rule you cannot inspect is a selection rule that should not be allowed to delete anything, and unlike a symbol or a type filter, "further than 80 pips" is not something you can verify by looking at the Trade tab. So the first run lists every candidate with its symbol, type, volume, price and measured distance, and stops. Untick the dry run to arm it. The candidate list is identical either way, so what you read in the dry run is exactly what the live run acts on. The usual pending-order care is present too. Pips are converted to points, so 80 pips means the same distance on a 4 digit and a 5 digit quote and the script does not have to be re-tuned per broker. A symbol with no quote yet - dropped out of Market Watch, never synchronised - is put back into Market Watch and, if it still has no price, reported and left alone, because a missing price must never be read as "far away". Tickets are collected before the first delete, since the pool re-indexes the instant an order leaves it. Every result is checked. Temporary refusals are retried, permanent ones are not. Open positions are never touched. Notes and limitations - Distance is absolute. An order 200 pips above the market and an order 200 pips below it are treated the same. If you only want one side cleared, run Delete Pendings By Type first or use the symbol filter. - Distance says nothing about intent. A deliberately far limit - a crash bid, a weekly-level order you placed on purpose - looks exactly like a stale rung to this script. Read the dry run. - The measurement is a snapshot. On a fast market the re-check before each delete will sometimes disagree with the list built two seconds earlier, and the summary will show skips that the dry run did not predict. That is the script being correct, not inconsistent. - Orders on symbols with no quote are never deleted. If a whole symbol is missing from the run, check it is in Market Watch. - Weekend and out-of-session prices are the last quote received. Distances measured then are as stale as the quote is. - There is no undo, and no record beyond the Experts log. The dry run is the record - screenshot it if the ladder was expensive to build. - Expiry times, comments and attached stop levels go with the order.
Script · MT4 · v1.0 · Free
About Delete Pendings Beyond N Pips
Delete Pendings Beyond N Pips is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Distance pips, Dry run and Current symbol only. MQL source code included.
Files in the download: DeleteDistantPendings.ex4, DeleteDistantPendings.mq4, DeleteDistantPendings.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Distance pips | 100 | Delete pendings further than this from the market, in pips |
| Dry run | true | Dry run: list what would go, delete nothing |
| Current symbol only | false | Restrict to this chart's symbol |
| Magic filter | -1 | Magic number (-1 deletes every magic) |
| Max retries | 5 | Attempts per order before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Confirm first | true | Ask for confirmation before deleting |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Grid · Trading Sessions · Pending Orders · Alerts · MT4 Script · MQL4 Source Code