Pending Margin If Triggered Report
The terminal's margin figures only ever describe what is open right now. A grid or ladder trader with a dozen pending orders resting below and above the market has no equivalent view of what happens the moment a fast move triggers several of them together - the margin call risk sits in a blind spot until it has already happened. This script closes that gap. It sums the margin requirement of every resting pending order, independently per order, and adds that to the account's currently used margin to produce a projected total and a projected margin level. It also reports, symbol by symbol, what the net lot exposure would become if every pending order on that symbol filled - so a symbol quietly building a large one-sided position through several small pending orders shows up before any of them trigger, not after. The projection deliberately does not assume any broker-side hedge margin netting between opposing pending orders on the same symbol - it sums margin independently, which is the pessimistic, worst-case figure that actually matters when several orders can trigger in a fast cascade. Notes and limitations - Margin per pending order comes from MarketInfo(symbol, MODE_MARGINREQUIRED) multiplied by the order's lot size - the broker's own current margin rate for that symbol, never a hardcoded figure, so it holds for forex, metals and indices alike. - Assumes no hedge margin netting between opposing pending orders on the same symbol. Some brokers reduce required margin when a hedge exists; this script always reports the pessimistic, independently-summed figure, which is deliberately the more conservative number to plan against. - The projected margin level does not attempt to re-price floating P&L at the price each pending order would actually trigger at - it holds equity constant and only changes the margin side of the ratio. A large adverse move that triggers several stops would also move equity, which this script does not simulate. - A symbol with no specification loaded (not tradable at this broker, or a typo) is skipped from the margin total with a note printed to the log rather than silently ignored.
Script · MT4 · v1.0 · Free
About Pending Margin If Triggered Report
Pending Margin If Triggered Report is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 3 settings, such as Magic filter, Symbol filter and Show per order. MQL source code included.
Files in the download: PendingMarginIfTriggered.mq4, PendingMarginIfTriggered.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| Symbol filter | Symbol filter ("" = every symbol in the book) | |
| Show per order | true | Print one line per pending order as well as the summary |
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 → Scripts.
- 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 script onto a chart to run it once.
Tags: Grid · Pending Orders · Alerts · MT4 Script · MQL4 Source Code