Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
Yang Zhang Expansion Momentum is a volatility-regime trend-initiation strategy for MetaTrader 5. It is built around the Yang-Zhang realized volatility estimator — a drift-independent, gap-inclusive way of measuring how energetic a market is — and it trades in the momentum style, aiming to step into young trends at the moment volatility ignites. Rather than reacting to price crossing a level, it reacts to a shift in market character: a quiet market waking up.
The core idea rests on a well-documented market behaviour called volatility clustering — periods of calm tend to be followed by more calm, and bursts of activity tend to cluster together. The strategy watches for the transition from calm to active. It measures current Yang-Zhang volatility (abbreviated "YZ") each bar and compares it to a slow baseline of its own recent history. When YZ makes a fresh expansion above that baseline, the market is treated as igniting. Critically, the strategy only acts on the single bar that crosses — it never chases a regime that is already hot.
This makes Yang Zhang Expansion Momentum a useful learning tool for traders who want to understand realized-volatility estimators and regime-detection logic rather than the classic oscillators most beginner strategies use. It is designed for markets that alternate between compression and expansion, and it is best studied by those already comfortable with the basics of moving averages, ATR-based stops, and how an Expert Advisor (EA) processes completed bars. It is presented here as a strategy analysis, not a shortcut — the goal is to understand why each rule exists.
How It Works
The strategy operates once per completed bar on a single timeframe (the chart's own period). Each new bar, it recalculates volatility, updates its baseline, and checks its rules in a fixed order.
Volatility measurement (the engine):
- Yang-Zhang volatility blends three variance sources over a rolling window: the overnight return variance (bar-to-bar gaps), the open-to-close variance, and the Rogers-Satchell intrabar term that uses the high, low, open, and close. This blend stays honest even when the market is drifting, which is why it is preferred over a simple close-to-close standard deviation.
- A slow baseline is computed as the simple moving average (SMA) of the recent YZ history, excluding the current value.
Entry conditions — the strategy signals a trade only when all of the following align:
- Regime ignition: YZ crosses from below to above
baseline × ExpansionFactor. This must be a fresh cross on the current bar — the previous YZ value was at or under the threshold and the current value is above it. An already-elevated regime does not qualify. - Directional lean: Direction is not guessed after the fact — it comes from drift that is already present when volatility ignites. The strategy measures the cumulative log return over the window and normalizes it by the random-walk expectation,
YZ × √VolPeriod. This produces a dimensionless figure called driftZ. - Direction gate: A market that ignites with no lean is treated as noise and rejected. The strategy goes long when driftZ is greater than +MinDriftZ, and short when driftZ is less than −MinDriftZ. If the absolute lean is too small, no trade is taken.
- Only one position per strategy (magic number) is held at a time.
Exit conditions — the strategy manages a position with three separate exits:
- Stop-loss: An ATR-based protective stop. For a long, the stop is placed at
entry − (AtrStopMult × ATR); for a short, atentry + (AtrStopMult × ATR). ATR (Average True Range) measures recent price range, so the stop adapts to current volatility. - Take-profit: An ATR-based target, set with a separate multiplier —
entry ± (AtrTargetMult × ATR). Because the target and stop multipliers differ, the reward-to-risk profile is asymmetric by design. - Regime exit: Independent of price, if YZ collapses back below its baseline, the "fuel" for the move is considered spent and the position is flattened immediately. This can close a trade before either the stop or target is reached.
In plain terms: the strategy waits for a quiet market to wake up in a direction it is already leaning, rides that ignition with a volatility-scaled stop and target, and steps aside the moment the energy fades.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| VolPeriod | 20 | 10 | 50 | Window (in bars) for the Yang-Zhang volatility calculation and the drift measurement. Shorter reacts faster; longer is smoother. |
| BaselinePeriod | 50 | 20 | 150 | Number of prior YZ values averaged into the slow baseline that volatility must expand above. |
| ExpansionFactor | 1.15 | 1.0 | 1.6 | Multiplier applied to the baseline to form the ignition threshold. Higher values demand a stronger expansion before arming an entry. |
| MinDriftZ | 0.50 | 0.0 | 2.0 | Minimum absolute normalized drift (driftZ) required to define a tradable direction. Higher values reject weaker leans. |
| AtrPeriod | 14 | 7 | 30 | Lookback period for the ATR used to size the stop and target. |
| AtrStopMult | 2.0 | 1.0 | 4.0 | ATR multiple that sets the distance of the protective stop-loss from entry. |
| AtrTargetMult | 3.0 | 1.0 | 6.0 | ATR multiple that sets the distance of the take-profit target from entry. |
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots. Should be adjusted to your account size and risk tolerance. |

Recommended Chart Settings
Yang Zhang Expansion Momentum is a single-timeframe strategy — every calculation uses the chart's own period, so it runs on whichever timeframe you attach it to. Because the logic depends on volatility clustering and clean gap behaviour, it is generally most instructive on liquid instruments such as major forex pairs (for example EUR/USD or GBP/USD) on intraday timeframes like H1 or H4, where regime shifts are frequent enough to study but not dominated by microstructure noise.
There is no universally "correct" symbol or timeframe. Volatility behaviour differs across instruments and sessions, and the same parameter set can behave very differently on a fast index CFD versus a slow currency cross. Treat the defaults as a starting point for study, and expect results to vary considerably across different market conditions and periods.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Strengths of this approach. The Yang-Zhang estimator is one of the more statistically robust volatility measures available — it accounts for overnight gaps and stays unbiased even when price is drifting, which many simpler measures do not. By requiring a fresh expansion cross plus a pre-existing directional lean, the strategy filters out two common false-signal sources: chasing an already-extended move, and entering an expansion that has no direction. The independent regime exit is a thoughtful touch, since it can release a position when the underlying volatility condition disappears rather than waiting passively for a stop.
Known limitations. Regime-ignition systems are, by nature, reactive to a transition that may not persist. Volatility can expand and then immediately revert, producing a "false ignition" that stops the trade out. In choppy or range-bound markets, the strategy may take entries that reverse quickly, and the asymmetric target (wider than the stop) means winning trades must run to justify the losers. Parameters like ExpansionFactor and MinDriftZ are sensitive — set them too loose and noise slips through; too tight and genuine trends are missed. There is also a structural constraint: only one position is held at a time, so the strategy cannot scale into a strong move.
Where it may underperform. Persistently low-volatility, mean-reverting conditions rarely produce clean ignition crosses, and violently gapping or news-driven markets can trigger entries just before sharp reversals. As with any single-timeframe momentum system, whipsaw environments are its hardest test. Study its behaviour across several market regimes before drawing any conclusions.
Risk Management Tips
Sound risk management matters far more than any single strategy's rules. Consider the following general principles as you study this EA:
- Position sizing: Set the
Lotsparameter relative to your account balance, not to a return you hope to achieve. A common guideline is to risk no more than 1–2% of account equity per trade, and the ATR-based stop distance should factor into that calculation. - Test on a demo account first: Run the strategy on a demo or paper-trading account across a range of market conditions before committing any real capital. This lets you observe how the regime logic behaves in calm, trending, and choppy periods.
- Understand drawdown: Every strategy experiences losing streaks. Know the maximum drawdown you are willing to tolerate, and recognize that historical behaviour does not predict future outcomes.
- Never over-leverage: Leverage amplifies losses as much as gains. Keep total exposure conservative, especially while you are still learning how the strategy reacts.
- Keep a trading journal: Record why each trade was entered and exited. Understanding the why behind the strategy's signals is the real educational value here.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: YangZhangExpansionMomentum.ex5 (27 downloads)
- Source Code: YangZhangExpansionMomentum.mq5 (31 downloads)
- Documentation: YangZhangExpansionMomentum.pdf (34 downloads)