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 · MT5 · v1.0 · Free

About MFE Giveback Guard

MFE Giveback Guard is an expert advisor (trading robot) for MetaTrader 5. It has 9 settings, such as Min mfe pips, Giveback pct and Magic filter. MQL source code included.

Files in the download: MfeGivebackGuard.ex5, MfeGivebackGuard.mq5, MfeGivebackGuard.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

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 retries5Close 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trailing Stop & Break-even · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria