Equity Ratchet Floor
A trailing stop that follows every tick of a new high is precise but noisy - it can force an exit on ordinary floating give-back between two points that were never going to be a real reversal. A step ratchet is coarser on purpose: the floor only moves up in fixed-size notches (a percent of the starting balance) once the equity high water mark has actually cleared the next notch level, and it never moves down. Between notches the floor sits still, so normal floating movement inside a notch does not trigger anything. At attach, the EA records the starting balance, sets an initial floor a configurable percent below it, and computes the fixed money size of one notch as a percent of that same starting balance. Every tick it updates the running equity high water mark and checks whether that high water mark has reached the next ratchet level; if it has, the floor steps up by exactly one notch, and the check repeats in a loop so a single large winning close that jumps equity past several notch levels at once still ratchets every notch it earned, not just one. If equity ever touches or drops through the current floor, the EA flattens every position matching its magic and symbol filters immediately, logging the exact floor level, the number of notches that had fired, and raising an alert. An optional setting keeps the account blocked after a floor breach until the chart is reattached, for a trader who wants the ratchet to be a hard stop for the run rather than a repeated protective flatten. Notes and limitations The starting balance and the floor are both fixed at the moment this EA is attached and are not preserved across a terminal restart or a chart recompile that forces reinitialisation - reattaching begins a new run with a new starting balance and a fresh floor at the initial gap below it. This is a protective flatten, not a partial-profit-taking mechanism: a breach closes everything matching the filters, not just enough to restore headroom.
Expert advisor · MT5 · v1.0 · Free
About Equity Ratchet Floor
Equity Ratchet Floor is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent. It has 7 settings, such as Initial floor percent, Step percent and Magic filter. MQL source code included.
Files in the download: EquityRatchetFloor.ex5, EquityRatchetFloor.mq5, EquityRatchetFloor.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Initial floor percent | 5.0 | Floor starts this many percent below the start-of-run balance |
| Step percent | 2.0 | Each ratchet notch is this many percent of the start-of-run balance |
| Magic filter | -1 | Magic number filter for the positions this EA closes (-1 = every magic) |
| Current symbol only | false | Restrict closing to this chart's symbol |
| Block after trigger | false | true = also refuse to consider new trades safe until the chart is reattached |
| Max retries | 5 | Attempts per close 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 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Trailing Stop & Break-even · Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code