cm Universal Trailing Stop Hedge
This is a universal trailing stop utility for MetaTrader 5 that manages existing positions using seven different trailing algorithms: fixed points, fractals, ATR, Parabolic SAR, Moving Average, percentage of profit, and fixed pips. It supports both real SL modification and virtual trailing stop that closes positions when price hits the computed level, and provides visual chart labels and arrows for no-loss levels and stop levels.
Open the interactive view (equity curve, symbol switch)Key facts
Backtest results (H1, about 1 year)
Not backtested yet — this EA could not be converted automatically.
Strategy analysis
This EA is a pure utility that does not open its own positions; it only manages stop loss levels for existing positions. The strategy concept is based on seven selectable algorithms for dynamically adjusting stop loss levels: 1) by candle extremes (low/high) plus a delta offset; 2) by Bill Williams fractal structures plus delta; 3) by ATR indicator value retraced from current price; 4) by Parabolic SAR value plus delta; 5) by Moving Average value plus delta; 6) by a percentage of current profit; 7) by a fixed pip distance from current price. Entry conditions: none — the EA does not handle entries, it only manages existing positions. Exit conditions: when price hits the trailing stop level, positions are closed (virtual mode) or SL is modified to the trailing level (normal mode). Position management: supports filtering positions by magic number; in virtual trailing mode, it calculates the weighted average price (no-loss level) for all buy and sell positions separately. Money management: no independent money management logic; trailing distance is controlled by the delta, StepTrall, and StartTrall parameters.
Strengths
- Offers seven different trailing stop algorithms, providing extremely high flexibility for various trading styles
- Virtual trailing stop mode works when brokers restrict SL modification, and calculates overall position stop based on weighted average price
- Provides rich visual chart feedback (stop level lines, arrows, labels) for real-time monitoring of stop loss status
- Supports position filtering by magic number, allowing conflict-free coexistence with other EAs
Weaknesses
- Critical bug on line 125: uses OrderGetInteger(ORDER_MAGIC) while iterating positions, should use PositionGetInteger(POSITION_MAGIC) — this causes magic number filtering to fail entirely
- Enum variable names (b,c,d,e,f,g,i) are extremely non-semantic, making the code nearly unreadable and hard to maintain
- StrPer function has multiple timeframe mapping errors (e.g. H3 maps to M3, H4 maps to M4, etc.)
- Virtual trailing stop mode lacks STOPS_LEVEL validation for the computed stop level, which may cause issues in live trading
- The candle extreme search loop (500 bars) in SlLastBar is inefficient and lacks boundary protection
Possible improvements
- Fix the magic number retrieval bug: change OrderGetInteger(ORDER_MAGIC) to PositionGetInteger(POSITION_MAGIC) — this is a critical error that breaks magic number filtering
- Rename enum values from single letters to semantic names (e.g. FIXED_POINTS, FRACTAL, ATR, PARABOLIC, MA, PERCENT_PROFIT, PIP_FIXED)
- Add new bar detection logic to avoid executing all calculations and SL modifications on every tick, reducing resource consumption and trading server load
- Fix the timeframe mapping errors in StrPer function and add correct mappings for H3, H4, H6, H8, H12 timeframes
Risk assessment
Overall risk: Medium
- Magic number filtering bug causes all positions to be managed instead of only those with the specified magic number, potentially modifying other EAs' stop losses unintentionally
- Virtual trailing stop mode lacks OrderCheck validation on the buy side before sending orders, which may result in invalid order requests
- No new bar detection mechanism — every tick attempts SL modification, which may trigger broker restrictions or be flagged as abuse under high-frequency market conditions
- Stop loss levels do not account for spread and STOPS_LEVEL limitations, and virtual mode may close positions under unfavorable conditions
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
VirtualTrailingStop | false | Enable virtual trailing stop (close on touch, no real SL modification) |
parameters_trailing | 1 | Trailing stop algorithm: 1=Bar extrema 2=Fractals 3=ATR 4=Parabolic SAR 5=MA 6=Profit% 7=Fixed points |
delta | 0 | Stop loss offset in points, added to indicator value |
TF_Tralling | 0 | Trailing stop timeframe (0=current) |
StepTrall | 1 | Minimum step for SL modification in points |
StartTrall | 1 | Profit in points to start trailing stop |
text_color | clrGreen | Chart label text color |
period_ATR | 14 | ATR indicator period (used by algorithm 3) |
Step | 0.02 | Parabolic SAR step parameter (used by algorithm 4) |
Maximum | 0.2 | Parabolic SAR maximum parameter (used by algorithm 4) |
Magic | -1 | Position magic number filter (-1=manage all positions) |
GeneralNoLoss | true | Allow moving SL to breakeven (no-loss protection) |
DrawArrow | false | Draw stop loss level arrows on chart |
ma_period | 34 | Moving average period |
ma_method | MODE_SMA | Moving average calculation method (used by algorithm 5) |
applied_price | PRICE_CLOSE | Moving average applied price type (used by algorithm 5) |
PercetnProfit | 50 | Profit percentage trailing stop value (used by algorithm 6) |
Similar Utility EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.