Loading…

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

SettingDefaultWhat it does
KindPENDING_BUY_STOPPending order type to place
Distance pips10.0Distance from current price, in pips
Expiry modeEXPIRY_SESSION_CLOSEHow to compute the expiry
Session close hour21Session close hour, server time (0-23) - used when mode is session close
Session close minute0Session close minute, server time (0-59) - used when mode is session close
Boundary minutes60Bar period in minutes to align expiry to - used when mode is bar boundary
Stop loss pips0.0Stop loss distance in pips (0 = none)
Take profit pips0.0Take profit distance in pips (0 = none)
Lots0.10Lot size (normalised to the symbol's step/min/max)
Slippage points30Allowed slippage in points
Magic910001Magic number stamped on the order

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trading Sessions · Pending Orders · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria