Stop-Out Distance Estimator
A margin level percentage tells a trader how much room the whole account has left, but not which single symbol will run out of that room first. On a book with five open symbols, the one nearest to trouble is rarely the one carrying the most lots - it depends on that symbol's pip value and how far it has already moved. This script converts the account's total money headroom before stop-out into a per-symbol pip distance. For each symbol with a net open position, it asks: if every OTHER open position's floating result stayed exactly where it is right now, how many pips would THIS symbol have to move against the net position before the account hit its stop-out level? That "holding everything else constant" framing is a deliberate simplification and the script says so plainly. A real adverse move rarely hits one symbol in isolation - correlated pairs tend to move together, which exhausts the headroom faster than any single row in this table implies. What the table is good for is a fast comparison: which symbol has the LEAST room, so that one gets attention first. Flat net exposure on a symbol - equal buy and sell volume - has no single direction to test and is reported as such rather than silently given a distance of zero, which would read as "already at the edge" when it means the opposite. Notes and limitations - Assumes today's margin usage stays constant as price moves. True for ordinary forex margin over the pip ranges this script deals with; less true for symbols whose margin requirement itself is highly price-sensitive. - Each row is independent of the others. It does not model a correlated, whole-book shock - see a dedicated stress-test script for that question. - Money-mode stop-out is treated as triggering when free margin (equity minus margin) falls to the configured level, the common convention but not universally documented identically by every broker. - Pending orders carry no margin in MT4 and are not part of this estimate.
Script · MT4 · v1.0 · Free
About Stop-Out Distance Estimator
Stop-Out Distance Estimator is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Magic filter, Warn pips threshold and Export csv. MQL source code included.
Files in the download: StopOutDistanceEstimator.ex4, StopOutDistanceEstimator.mq4, StopOutDistanceEstimator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| Warn pips threshold | 50.0 | Flag symbols with less than this many pips of room |
| Export csv | false | Also write the table to a CSV file |
| Csv delimiter | , | CSV delimiter (first character is used) |
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: Alerts · MT4 Script · MQL4 Source Code