Batch Expiry Setter
Setting the same expiration on a dozen pending orders by hand means opening each one's Modify dialog in turn. This script does it in one run: pick a date and time, and every matching pending order on the account is updated to expire at that moment. The detail that makes a batch job like this actually reliable is what happens when one broker-side rule rejects the request. Some brokers enforce an unpublished minimum look-ahead on ORDER_TIME_SPECIFIED expirations - reject anything too close to now - and MQL4 exposes no function to query that minimum in advance. A naive batch script either fails the whole run on the first rejection, or silently skips the order and says nothing. This one instead detects that specific error code, nudges just that order's expiry forward in small steps, and keeps retrying until the broker accepts it or a bounded number of nudges is exhausted, then reports plainly if it had to. Every order is modified independently, so one broker-side rejection never blocks the rest of the batch, and the final summary states exactly how many orders needed nudging and how many failed outright. Notes and limitations - Only pending orders are touched. Open market positions have no expiration and are ignored. - The nudge loop only fires on the specific error a broker returns for a rejected expiration - other errors (busy trade context, requote, and so on) go through the ordinary retry path instead, without changing the requested time. - If a broker does not support expiring pending orders at all, every order in the batch will exhaust its nudge attempts and be reported as failed - this script cannot add a capability the broker does not offer. - Runs once per invocation. It does not watch for new pending orders placed after it finishes.
Script · MT5 · v1.0 · Free
About Batch Expiry Setter
Batch Expiry Setter is an expert advisor (trading robot) for MetaTrader 5. It places pending buy/sell stop or limit orders. It has 9 settings, such as Expiration, Current symbol only and Magic filter. MQL source code included.
Files in the download: BatchExpirySetter.ex5, BatchExpirySetter.mq5, BatchExpirySetter.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 |
|---|---|---|
| Expiration | 0 | Expiration to apply to every pending order (0 = today 23:59:59 server time) |
| Current symbol only | false | Restrict to this chart's symbol |
| Magic filter | -1 | Only orders with this magic (-1 = ignore magic) |
| Auto nudge | true | Nudge expiry forward automatically if the broker rejects it as too close |
| Nudge step min | 5 | Nudge step, minutes |
| Max nudges | 12 | Maximum nudge attempts per order (12 x 5 min = 1 hour) |
| Max retries | 5 | Retries per order on a temporary error |
| Retry wait ms | 500 | Pause between retries, milliseconds |
| Confirm first | true | Ask for confirmation before touching any order |
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: Pending Orders · MT5 Script · MQL5 Source Code