Stale Pending Order Sweeper
- 유틸리티
-
AL MOOSAWI ABDULLAH JAFFER BAQER
To trade successfully we need to go through the proven path that others had gone and reached!
Here are 17 quotes from such successful investors:
1- Limit your size in any position so that fear does not become the prevailing instinct guiding your judgment.
Joe Vidich - 버전: 1.0
- 활성화: 10
FORGOTTEN PENDING ORDERS ARE TRADES YOU NEVER MEANT TO TAKE - THIS UTILITY CLEARS THEM AWAY
Stale Pending Order Sweeper is an order-housekeeping utility for MetaTrader 5. It never opens a trade and never touches an open position. It watches the limit, stop and stop-limit orders you choose and deletes the ones that have gone stale: too old, too far from the current price, still waiting when the Friday cutoff arrives, or left behind with no open position of their own.
Try it free before you decide: run it in the MetaTrader 5 Strategy Tester with visual mode ticked and TesterDemoOrders set to true. Inside the tester only, it then places a few minimum-size demonstration pending orders, so you can watch their age bars fill up, the NEXT SWEEP countdown tick down and each stale order disappear with a line in the journal. On a live or demo chart it never places anything.
- Four independent sweep rules: maximum age, distance from price (fixed pips or ATR multiple), Friday cutoff and orphan orders.
- DRY RUN mode: the utility only warns you what it would delete - perfect for checking the rules before trusting them.
- Exact filters: this chart symbol or the whole account, one magic number or every magic, with or without manual orders, and each order family on or off.
- Live panel: watched count, oldest age, farthest distance, orders swept today, a per-order age bar and a ticking NEXT SWEEP countdown.
- Safe on shared terminals: every saved key carries the account login, chart symbol and magic number, so several copies never mix their state.
WHY PENDING ORDERS GO STALE
A pending order is a promise you made to the market at one moment in time. The idea behind it - a breakout level, a pullback zone, a news setup - has a shelf life. Hours later the level may no longer matter, price may have drifted hundreds of pips away, or the weekend gap may be about to arrive. The order, however, is still sitting there, ready to fill at a price that now means nothing. Many traders discover this only when an old buy limit fills during a fast move on Monday morning, opening a position nobody planned.
Expert Advisors leave the same debris. A grid that was stopped, a breakout robot that was removed from its chart, a terminal restart at the wrong moment: each can strand pending orders with no position and no logic behind them. Stale Pending Order Sweeper is a quiet janitor for exactly this job. It does not judge entries, it does not move prices, it does not forecast anything. It checks every watched order against the rules you set, and removes what no longer belongs.
START HERE - FIVE MINUTES TO A CLEAN ORDER BOOK
- Attach: drop it on any chart and any timeframe. The chart symbol matters only when SymbolScope is set to this chart's symbol.
- Allow algo trading: deleting an order needs trading permission. If it is missing, the panel status line turns red and tells you.
- Choose the scope: keep MagicFilter at 0 to look after every order, or enter the magic number of one Expert Advisor to look after only its orders.
- Begin in DRY RUN: set DryRun to true. The panel marks every order that breaks a rule in amber and you receive one warning per order, but nothing is deleted.
- Go live: when the flagged orders look right to you, press the DRY RUN button on the panel to switch to LIVE, or set DryRun back to false.
THE FOUR SWEEP RULES
Rule one - maximum age. Every order carries its setup time. When an order has been waiting longer than MaxAgeMinutes, it is stale. Its age bar on the panel fills from green through amber to red, so you can see the moment coming long before it arrives.
Rule two - distance from price. An order that price has left far behind is unlikely to be the order you wanted. In pips mode the limit is a fixed number of pips. In ATR mode it breathes with the market: a multiple of the Average True Range on the timeframe you pick, so a quiet session and a volatile session are judged fairly. Buy orders are measured from the Ask, sell orders from the Bid; stop-limit orders are measured from their trigger price.
Rule three - Friday cutoff. Switch it on and every watched order is cleared from the cutoff time on Friday (broker server time) until the week closes, so no forgotten order is left to fill on a weekend gap.
Rule four - orphan orders. Switch it on and an order is stale when there is no open position with the same symbol and the same magic number. By default only orders without an expiry time (good-till-cancelled) are treated this way, and a short grace period protects orders that were placed a moment before their first position opens.
The first rule that matches is the reason shown in the STATE column: AGE, FAR, FRIDAY or ORPHAN. Orders that match nothing show "ok" and are left in peace.
THE PANEL
The panel sits on the left side of the chart and keeps the price scale and the right side clean. It is built on the same amber-on-ink chassis as the rest of the AJB utility family and measures its own text, shrinking its font on small charts instead of spilling off screen.
- Header: chart symbol, magic filter, account login and a status pill - LIVE, DRY RUN or PAUSED.
- scope: what is watched, including which order families (L = limits, S = stops, X = stop-limits).
- rules: the active age, distance, Friday and orphan settings in one line.
- pending: how many orders are watched and how many are stale right now.
- oldest: the age and ticket of the oldest watched order.
- farthest: the farthest order in pips, next to its distance limit.
- swept today: orders deleted today (resets at the server day change), the running total and server time.
- NEXT SWEEP: seconds until the next check, plus either the number of orders about to be deleted or the next order that will turn stale by age and how long it has left.
- Order table: ticket, symbol, type, lots, age, distance in pips and state for every watched order, each with its own age bar.
- Buttons: LIVE / DRY RUN, PAUSE / RESUME, ALERTS ON / OFF and DELETE ALL. DELETE ALL needs a second click within six seconds to confirm, and it removes only the orders in this copy's scope.
In a non-visual Strategy Tester run nothing is drawn, so optimisation stays fast.
SAFETY YOU CONTROL
- It never opens a position, never modifies an order and never closes a position. Its only action is deleting pending orders that match your rules.
- Market orders are never touched, and each order family can be excluded on its own.
- Every loop filters by symbol and by magic number exactly as configured, so it ignores orders that belong to other systems.
- A failed delete is retried a few times, then that order waits for a cooldown before another attempt, so a closed market or a busy server cannot cause a flood of requests.
- DRY RUN warns once per order instead of repeating the same alert every few seconds.
- All state (mode, pause, alert switch, swept counters) is stored in terminal global variables whose names include the login, chart symbol and magic number, and leftovers for orders that no longer exist are cleaned up automatically.
EVERY SETTING EXPLAINED
Scope
- SymbolScope - watch only this chart's symbol, or every symbol on the account.
- MagicFilter - the magic number to watch; 0 means every magic number.
- IncludeManual - include orders placed by hand (magic 0).
- SweepLimitOrders / SweepStopOrders / SweepStopLimitOrders - switch each order family in or out of the sweep.
- DryRun - true = warn only, never delete. When true it always starts in DRY RUN; the panel button can switch it for the session.
Rule 1 - maximum age
- MaxAgeMinutes - an order older than this is deleted; 0 switches the rule off and hides the age bars. Default 240.
Rule 2 - distance from price
- DistanceMode - off, fixed pips, or ATR multiple.
- MaxDistancePips - pips mode limit. Default 150.
- AtrPeriod / AtrTimeframe - the ATR used in ATR mode (closed bar). Defaults 14 and H1.
- AtrMultiple - ATR mode limit as a number of ATRs. Default 4.0.
Rule 3 - Friday cutoff
- FridaySweep - clear all watched orders from the Friday cutoff until the week ends.
- FridayCutoffTime - the cutoff in broker server time, HH:MM. Default 20:00.
Rule 4 - orphan orders
- OrphanSweep - delete orders with no open position of the same symbol and magic.
- OrphanOnlyNoExpiry - apply the orphan rule only to good-till-cancelled orders; orders with their own expiry are left to expire naturally.
- OrphanGraceMinutes - minimum order age before it can count as an orphan. Default 5.
Alerts
- AlertOnSweep - terminal alert for each deletion, or each dry-run warning.
- PushOnSweep - the same message as a push notification to the MetaTrader app on your phone.
- PrintToJournal - write every event to the Experts journal.
Execution
- SweepEverySeconds - how often the rules are checked; this drives the NEXT SWEEP countdown. Default 5.
- MaxRetries / RetryDelayMs - attempts per delete and the pause between them.
- FailCooldownSec - how long a failed order waits before it is tried again.
Strategy Tester
- TesterDemoOrders - off by default; when true and in the tester only, place a few minimum-lot demo pending orders so the sweep can be seen working.
Panel and chart
- ShowPanel - show or hide the panel.
- PanelX / PanelY - offset from the chart edges.
- PanelFontSize - starting font size; it shrinks automatically if the chart is too small.
- ShowArabic - add an Arabic line under the English labels.
- ShowAgeBars - draw an age bar beside every order.
- MaxTableRows - the most order rows listed; the rest are summarised in one line.
- PanelCorner - move the panel to another corner if you prefer.
GOOD PRACTICE
- Run one copy per Expert Advisor you want to clean up after, each with that EA's magic number, or one copy with MagicFilter 0 and SymbolScope set to all symbols for a whole-account sweep.
- Give the age limit some headroom over the longest time your own strategy expects an order to wait.
- Prefer ATR mode on symbols whose volatility changes a lot during the week, such as gold and indices.
- Keep the terminal running (a VPS is ideal): the utility can only sweep while it is attached to an open chart.
HONEST EXPECTATIONS
This is a tidy-up tool, not a trading system. It will not make a losing strategy profitable, and it cannot tell a good order from a bad one beyond the rules you give it. What it does is make sure that the orders sitting in your terminal are the ones you still mean, and that nothing you forgot fills at the worst possible moment. Works on any symbol and timeframe, on hedging and netting accounts, needs no DLLs and no extra files.
If it keeps your order book clean, an honest review on this page helps other traders decide - and if something could be better, the review is the place to say that too.
