Naked Position Quarantine
A stop loss removed by accident, a manual trade opened without one, or an EA that failed partway through placing its protective order all leave the same hazard behind: a position with unlimited downside that nobody is watching. This EA scans every open position matching an optional magic number filter, flags any with OrderStopLoss() equal to zero, and starts a grace-period clock the moment each one is FIRST observed naked - not from the position's original open time, so a position that already had its stop removed by hand before this EA ever attached still gets the same fair warning window as one that just opened. That per-ticket clock also means a position which regains a stop and then loses it again restarts its own grace period, which is the correct behaviour: the risk genuinely reappeared, so the warning should too. Once the grace period elapses, one of three actions fires depending on how the EA is configured: keep alerting without touching the order, attach an emergency stop at a fixed pip distance (clamped to respect the broker's minimum stop and freeze levels so the modify is never rejected for being too close), or close the position outright. Notes and limitations The emergency stop distance is fixed in pips and is not derived from volatility or account risk - it exists to bound catastrophic loss, not to replace a properly sized stop chosen when the trade was planned. A position that closes and reopens with the same ticket-adjacent number is treated as new by the underlying ticket ID, so its grace period starts fresh, which is correct. The scan only covers positions visible in this terminal's account; it has no reach into other terminals or accounts.
Expert advisor · MT4 · v1.0 · Free
About Naked Position Quarantine
Naked Position Quarantine is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Grace minutes, Emergency stop pips and Action. MQL source code included.
Files in the download: NakedPositionQuarantine.ex4, NakedPositionQuarantine.mq4, NakedPositionQuarantine.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Grace minutes | 15 | Minutes a position may stay naked before the action fires |
| Emergency stop pips | 100 | Pip distance used when the action is ACTION_ATTACH_STOP |
| Action | ACTION_ATTACH_STOP | What happens once the grace period elapses |
| Magic filter | -1 | Magic number filter, -1 = every magic number |
| Alert repeat seconds | 300 | Minimum seconds between repeat alerts for the same ticket |
| Max retries | 5 | Attempts per action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
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 Expert Advisor · MQL4 Source Code