Loading…

Stale Pending Age Report

A pending order left over from a setup that never developed does not go away on its own. It sits on the server, waiting, and the longer a market sits dead the more likely that price eventually drifts into it anyway - firing a trade against a plan that was abandoned weeks ago and would not be taken today. This script scans every matching pending order, computes its age from OrderOpenTime() and its distance from the live market in pips, sorts the list, and prints it to the Experts tab with anything older than InpStaleAfterHours marked [STALE]. It changes nothing - no order is modified, cancelled or deleted. The point is to surface what has gone quiet so a human can decide what to do about it, not to act on that judgement automatically. Distance is measured against the price the order would actually fill against (Ask for a buy-side pending, Bid for a sell-side one), so the number shown is the real gap to trigger, not an approximation. Notes and limitations - Read-only by design. It reports on stale pendings; it does not cancel, modify or expire them - pair it with a manual review or a separate tool if automatic cleanup is wanted. - "Distance from price" is measured at the moment the script runs, not tracked over time - it does not show whether an order has been getting closer to triggering or further away. - Age is measured from OrderOpenTime(), which is when the pending order itself was placed, not from any earlier idea or chart mark that may have preceded it. - Sorting uses a simple insertion sort, which is efficient enough for the handful to few dozen pendings a typical account carries but is not intended for accounts with unusually large pending books.

Script · MT5 · v1.0 · Free

About Stale Pending Age Report

Stale Pending Age Report is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Current symbol only, Magic filter and Stale after hours. MQL source code included.

Files in the download: StalePendingAgeReport.ex5, StalePendingAgeReport.mq5, StalePendingAgeReport.txt.

Settings

SettingDefaultWhat it does
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Only report orders with this magic (-1 = every magic)
Stale after hours72.0Age (hours) at which an order is flagged STALE
Oldest firsttrueSort the report oldest to newest (false = newest first)

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Pending Orders · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria