Time Boxed Pending Setter
Most pending-order tools compute expiry as "now plus N hours", which drifts with whatever moment the script happened to run. A stop placed at 14:37 for a session ending at 21:00 does not need to live until 18:37 the next day - it needs to die at 21:00 tonight, when the setup it was based on stops being valid. This script computes the entry price the usual way - a chosen distance in pips from the current Bid/Ask, checked against the broker's stop and freeze levels - but computes expiry one of two ways. Session close mode rolls forward to the next occurrence of a fixed server-time clock value, so an order placed at any point in the day still expires at the same clock time. Bar boundary mode aligns to the next clean multiple of a chosen number of minutes counted from the epoch, so a 60-minute boundary always lands on the top of the hour, not one hour after the script ran. Stop loss and take profit are optional pip distances applied on the same side as the entry. The order is sent once per run with a distinct magic number so it can be found and managed afterwards. Notes and limitations - Expiry relies on the broker accepting order expiration at all. Some brokers only support GTC pendings; if expiration is rejected, the order is placed without an automatic expiry and the log says so via the returned error code. - Session Close mode uses server time, not the trader's local time zone - check the terminal clock before choosing the hour. - The script places exactly one order per run. Running it again places a second, independent order; it does not detect or replace an existing one. - Distance and stop/take-profit levels are validated against the broker's stop and freeze levels before sending, but market conditions can still change between the check and the send.
Script · MT4 · v1.0 · Free
About Time Boxed Pending Setter
Time Boxed Pending Setter is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders. It has 11 settings, such as Kind, Distance pips and Expiry mode. MQL source code included.
Files in the download: TimeBoxedPendingSetter.mq4, TimeBoxedPendingSetter.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 |
|---|---|---|
| Kind | PENDING_BUY_STOP | Pending order type to place |
| Distance pips | 10.0 | Distance from current price, in pips |
| Expiry mode | EXPIRY_SESSION_CLOSE | How to compute the expiry |
| Session close hour | 21 | Session close hour, server time (0-23) - used when mode is session close |
| Session close minute | 0 | Session close minute, server time (0-59) - used when mode is session close |
| Boundary minutes | 60 | Bar period in minutes to align expiry to - used when mode is bar boundary |
| Stop loss pips | 0.0 | Stop loss distance in pips (0 = none) |
| Take profit pips | 0.0 | Take profit distance in pips (0 = none) |
| Lots | 0.10 | Lot size (normalised to the symbol's step/min/max) |
| Slippage points | 30 | Allowed slippage in points |
| Magic | 910001 | Magic number stamped on the order |
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 → Experts.
- 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 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: Trading Sessions · Pending Orders · MT4 Script · MQL4 Source Code