Loading…

MFE Giveback Guard

A fixed trailing stop approximates giveback badly at both ends: wide enough to let a small winner ride comfortably, and it lets a large winner surrender far more than it should before closing; tight enough to protect the large winner properly, and it clips the small winner's normal wiggle room long before it has a chance to develop. This EA tracks each position's maximum favourable excursion (MFE) - the best profit, in pips, it has ever shown - and closes it once current profit falls to InpGivebackPct percent of that peak, so the exit distance scales with how far the trade actually ran rather than sitting at one fixed number. The rule only arms once a trade has reached InpMinMfePips of profit, so a trade still near breakeven is not closed on its first small pullback. Once armed, giveback is judged purely against the trade's own peak, which is persisted per ticket in a terminal global variable rather than kept only in memory - a chart reload or EA restart does not forget how high a trade had climbed and briefly treat a battle-tested winner as fresh. Notes and limitations - If InpUseGlobalVars is off and the terminal or EA restarts mid-trade, the peak resets to whatever profit the trade shows at that moment, which can understate a genuinely larger prior peak. - This EA only ever closes a trade outright; it never partially closes or adjusts a stop or target. - Persisted global variables are named with an "MfeGivebackGuard_" prefix and cleaned up automatically once their ticket closes, so they do not accumulate indefinitely. - Uses live Bid/Ask to judge profit, so both the peak and the giveback comparison are read against real-time price. - This EA never opens a new position; it only manages trades already open that match its filters.

Expert advisor · MT4 · v1.0 · Free

About MFE Giveback Guard

MFE Giveback Guard is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 9 settings, such as Min mfe pips, Giveback pct and Magic filter. MQL source code included.

Files in the download: MfeGivebackGuard.ex4, MfeGivebackGuard.mq4, MfeGivebackGuard.txt.

Settings

SettingDefaultWhat it does
Min mfe pips15MFE must reach at least this many pips before the rule arms
Giveback pct50Percent of peak profit surrendered that triggers a close
Magic filter-1Magic number filter (-1 = every magic)
Current symbol onlytrueRestrict to this chart's symbol
Use global varstruePersist each ticket's MFE across restarts via global variables
Slippage points30Slippage tolerance for the guard exit
Max retries5OrderClose attempts before giving up
Retry wait ms500Pause between attempts, milliseconds
Check interval sec1Seconds between guard scans

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 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: Trailing Stop & Break-even · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria