Stop Widening Prevention Sentinel
The single most common way a disciplined plan turns into an account-ending loss is not a bad entry - it is a stop quietly dragged further away, one "just a little more room" click at a time, on a trade that is going wrong. This EA is a sentinel against exactly that. It remembers the tightest stop distance it has ever seen for each tracked position and, the moment a check finds the current stop further from price than that remembered value - or removed entirely - it puts the stop straight back, then logs and optionally alerts about the revert. A stop is free to move closer to price at any time - that is normal trade management, and this EA updates its remembered baseline the moment a tighter stop appears. It is only ever a widened or missing stop that gets overwritten. The remembered baseline is persisted per ticket in a terminal global variable rather than kept only in memory, so a chart reload does not forget how tight the stop had already become and briefly treat a widened stop as if it were the new normal. Notes and limitations - A position with no stop loss at all when this EA first notices it is accepted as having "no baseline yet" - it does not force a stop onto a trade that never had one. Protection begins once a real stop first appears on the ticket. - Removing a stop entirely on a ticket that already had a real baseline is treated as the worst case of widening and is reverted the same way a widened price would be. - Only ever restores the stop loss; it does not touch take profit, lot size, or open/close the trade itself. - If the remembered baseline stop now sits inside the broker's stop or freeze level, the revert is skipped for that pass and logged rather than sent and rejected. - Persisted global variables are named with a "StopWideningPrevention_" prefix and cleaned up automatically once their ticket closes. - This EA never opens a new position; it only guards trades already open that match its filters.
Expert advisor · MT4 · v1.0 · Free
About Stop Widening Prevention Sentinel
Stop Widening Prevention Sentinel is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Magic filter, Current symbol only and Check interval sec. MQL source code included.
Files in the download: StopWideningPrevention.ex4, StopWideningPrevention.mq4, StopWideningPrevention.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Magic number filter (-1 = every magic) |
| Current symbol only | true | Restrict to this chart's symbol |
| Check interval sec | 1 | Seconds between checks - kept short to revert widening quickly |
| Alert on revert | true | Alert() (not just Print) when a widened stop is reverted |
| Max retries | 5 | OrderModify attempts 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