Trailing Equity: Automating Global Profit Protection
The Logic of the Rising Floor: What is Trailing Equity?
A Trailing Stop-Loss protects a single trade. A Trailing Equity function protects your entire account balance. It acts as a moving 'Safety Floor' that follows your total account equity as it rises. If your account equity reaches a new high and then drops by a certain percentage, the EA immediately closes all trades and secures the remaining profit.
This is extremely powerful for traders who run multiple EAs simultaneously. It prevents a scenario where a few losing trades can erase a highly profitable day or week across all your other bots. It's the ultimate 'Greed Filter' that ensures you 'Bank' your gains when the market momentum starts to fade.
How it Works: The High-Water Mark
The Trailing Equity EA uses a High-Water Mark (HWM) algorithm. It records the highest point your equity has reached since the script was started. It then calculates a 'Trailing Gap' (e.g., 2% of equity). Example: If your account starts at $10,000 and goes up to $11,000, your HWM is $11,000. If your trailing gap is 2%, your 'Safety Exit' is set at $10,780. If your equity drops to that level, the EA closes everything. If the equity continues to rise to $12,000, the exit level rises to $11,760.
Trailing Equity Execution Rules
Primary: Record the highest equity point (High-Water Mark)
Constraint: Set a trailing gap (e.g., 1-2% of total equity)
Threshold: Monitor AccountEquity() with every single price tick
Market State: Use a 'Start Profit' level before the trail begins
Verified: Ensure the VPS latency is < 10ms for fast closing
Target: Never allow a 5% account gain to turn into a 2% loss
Coding the logic: The AccountEquity() Loop
To implement this in MQL4, you create a persistent variable to store the HWM. Inside the OnTick() loop, you check: if (AccountEquity() > HighWaterMark) HighWaterMark = AccountEquity();. Then you check: if (AccountEquity() < HighWaterMark - TrailingGap) CloseAllTrades();.
This logic works in the background of your terminal. It doesn't interfere with your other EAs' entry signals—it only acts as a 'Global Exit' trigger. For maximum safety, the EA should also disable 'AutoTrading' at the terminal level after it has executed the global close to prevent other bots from immediately reopening positions.
Strategy: Equity Trailing for Prop Firm Challenges
Trailing Equity is widely used by traders attempting Prop Firm Challenges. Since prop firms have strict 'Daily Drawdown' and 'Maximum Drawdown' rules, a trailing equity script can be set to 'Hard Close' all trades if the drawdown limit is approached. This protects the 'Locked-in' profits and ensures the trader stays within the firm's strict risk management parameters.