ZigZag MA Retracement
- Experts
- Version: 1.41
- Updated: 16 September 2026
Trade retracements with statistical precision — enter only when price pulls back exactly where trend continuation odds favor you.
Overview ZigZag MA Retracement is a trend-continuation Expert Advisor built for EURUSD on the H1 timeframe. It identifies the last confirmed ZigZag swing, waits for price to retrace 60% into that swing, and confirms direction with a moving average filter before entering. Exits are event-driven: the position closes automatically the moment price closes back on the wrong side of the moving average, instead of relying on a static target.
How It Works
- The EA computes ZigZag pivots natively (no external indicator dependency) using Depth and Deviation parameters.
- When the last swing retraces to 60% of its range (within a configurable tolerance band), a signal zone is armed.
- A moving average filter confirms the prevailing trend direction before any entry is allowed.
- On confirmation, the EA enters with an ATR-based stop loss and take profit, sized to a fixed percentage of account risk.
- Once in a trade, the position is monitored on every bar close: if price closes back across the moving average, the trade is exited immediately as a trend-reversal signal.
- Every order passes broker compliance checks (margin, volume limits, freeze/stop level, spread buffer) before being sent.
Inputs
- Magic_Number — unique identifier for this EA's trades
- Risk_Percent — percent of equity risked per trade
- ATR_SL_Mult — stop loss distance as a multiple of ATR
- ATR_TP_Mult — take profit distance as a multiple of ATR
- ATR_Period — ATR calculation period
- ZigZag_Depth — minimum bars between ZigZag pivots
- ZigZag_Deviation — minimum price deviation to confirm a pivot
- ZigZag_Backstep — minimum bars between reversal pivots
- Retracement_Pct — retracement level of the last swing that triggers a signal
- Retracement_Tol — tolerance band around the retracement level
- MA_Period — moving average period
- MA_Method — moving average calculation method
- MA_Price — price source used for the moving average
- Enable_MA_Exit — close the position on a moving average cross-back
- Score_MinProfitFactor — disqualifies optimization runs below this profit factor
- Score_MaxDrawdownPct — disqualifies optimization runs above this drawdown percentage
- Score_MinTrades — disqualifies optimization runs below this trade count
- Score_R2Weight — weight of equity curve smoothness in the score
- Score_SlopeWeight — weight of profit speed in the score
- Score_SplitPenalty — penalty for instability between the first and second half of the test
- Score_SkewPenalty — penalty for profit concentrated in a single trade
- Score_UlcerPenalty — penalty for depth and duration of drawdowns
- Score_MARWeight — weight of capital efficiency (return over max drawdown) in the score
- Score_TradeBonusWeight — weight of trade count reliability in the score
Optimizer Scoring System This EA includes a custom OnTester() scoring function designed to fight curve-fitting. Instead of ranking by raw net profit, it disqualifies any optimization run with insufficient profit factor, excessive drawdown, or too few trades — then ranks survivors by equity curve smoothness (R²), profit speed, and capital efficiency (MAR ratio), while penalizing instability between the first and second half of the test, single-trade profit concentration, and drawdown pain (Ulcer Index). The result favors robust, repeatable parameter sets over lucky spikes. Set Optimizer Criterion to Custom max before running an optimization.
Recommended Setup
- Symbol: EURUSD
- Timeframe: H1
- Broker type: ECN/Raw spread account recommended for tighter fills on retracement entries
- VPS: recommended for uninterrupted bar-close monitoring
Screenshots Live chart example showing a confirmed ZigZag swing with the 60% retracement zone and moving average filter; recommended input settings panel.
Disclaimer Past performance does not guarantee future results. Test on a demo account before live deployment. Trading involves risk of loss.
