Order Expiry Manager
MetaTrader lets a pending order carry an expiration time, but plenty of brokers ignore it on non-ECN account types, and plenty of traders never set one at all. The result is a breakout order placed for a setup that stopped being relevant days ago, still sitting live and waiting to fill into whatever the market happens to be doing now. This EA is a management utility, not a signal generator. It never opens a position. Every tick it scans the pending order pool, and any order that is older than InpMaxAgeMinutes - measured from the order's own setup time, independent of whatever expiration value the order was sent with - gets deleted with the same retry-on-transient-error handling used for trading actions throughout this catalogue. By default it manages every pending order on the chart it is attached to, regardless of which EA or which hand placed them. Setting InpMagicNumber narrows it to one system's orders, and InpManageAllSymbols widens it from one chart to the whole account, so a single instance can act as an account-wide sweep if that is what is wanted. Notes and limitations - Deletes pending orders only. It never touches an open position and never places a trade of its own. - Age is measured from the order's own setup time, not from the broker's expiration field, so it works even on orders sent with no expiration set at all. - Requires AutoTrading enabled and trading permitted at the terminal, account and expert level; if trading is disabled the EA logs it and skips the sweep rather than silently doing nothing. - With InpManageAllSymbols on and InpMagicNumber at 0, this will delete pending orders placed by hand or by any other EA on the account - narrow the filters before relying on it unattended.
Expert advisor · MT5 · v1.0 · Free
About Order Expiry Manager
Order Expiry Manager is an expert advisor (trading robot) for MetaTrader 5. It places pending buy/sell stop or limit orders. It has 6 settings, such as Max age minutes, Magic number and Manage all symbols. MQL source code included.
Files in the download: ExpiryManager.ex5, ExpiryManager.mq5, ExpiryManager.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 |
|---|---|---|
| Max age minutes | 120 | Maximum pending-order age before deletion, in minutes |
| Magic number | 0 | Magic number to manage (0 = manage every pending order in scope) |
| Manage all symbols | false | Manage pending orders on every symbol, not just this chart's |
| Check interval seconds | 30 | Minimum seconds between expiry sweeps |
| Max retries | 5 | Attempts per deletion 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: Breakout · Buy/Sell Arrows · Pending Orders · MT5 Expert Advisor · MQL5 Source Code