Z-Regime Switch | Adaptive Z-Score Reversion and Trend Strategy by blitz_locked

By blitz_locked

Performance Metrics

Description

Z-Regime Switch (ZRS) is a Z-score strategy that adapts to market conditions. Most Z-score systems either fade every extreme or chase every breakout. ZRS measures the volatility regime first, then picks the playbook that fits it.How it works1. Price Z-Score. Measures how many standard deviations the close sits from its rolling mean.2. Regime Z-Score. Takes ATR as a percent of price and standardizes it against its own history. This sorts the market into two states:Calm regime: volatility is at or below its norm, so the strategy looks for mean reversion.Hot regime: volatility is elevated, so the strategy looks for trend continuation.3. Z Velocity. A smoothed rate of change of the Price Z-score. It confirms that momentum is turning (reversion) or accelerating (trend) before an entry.4. Efficiency Ratio filter. Reversion trades are only allowed when the market is choppy (low ER). Trend trades are only allowed when the market is directional (high ER). This separates a violent trend from a violent whipsaw, which volatility alone cannot do.5. Long-term bias filter. Longs are only taken above a slow EMA and shorts only below it, in both modes.Entry logicReversion Long: calm regime, low ER, price above the bias EMA, Z crosses back above the lower extreme band, Z velocity positive.Reversion Short: the mirror image.Trend Long: hot regime, high ER, price above the bias EMA, Z breaks above the trend band, Z velocity positive.Trend Short: the mirror image.The strategy waits for Z to reject the extreme before fading it, rather than catching the knife on the first touch.Exit logicExits depend on the mode that opened the trade:Reversion trades exit when Z returns to the mean zone.Trend trades exit when Z fades back toward zero.ATR stop-loss is set at entry on every trade.Time stop closes any trade that has run too long.FeaturesTwo strategies in one, selected automatically by regimeEach mode can be enabled or disabled separatelyLong and short togglesEfficiency ratio and long-term bias filters, each with its own on/off switchZ-score pane colored by regime, with entry bands and a regime background tintData Window readouts for Regime Z, Z velocity, Efficiency Ratio and active modeEntry and exit labels on trades showing the mode (REV, TREND, MEAN, ZFADE, TIME)Commission and slippage included in the defaultsTipsTest the modes separately first. Disable trend mode and test reversion alone, then swap. Whichever loses in your market can be turned off or tightened.Match the Z window to your timeframe. The default of 60 bars is a starting point. Shorter windows react faster but produce more noise.If trades are too rare, loosen the ER thresholds, lower the regime threshold, or widen the Z bands.If results are poor, try a longer ER window, a tighter ATR stop, or a shorter time stop.On intraday charts, increase the bias EMA length (500 or more), since 200 bars is very short-term there.Test across several symbols and timeframes instead of tuning to one chart.Use realistic costs. Set commission and slippage to match your broker and instrument.WarningsThis is not financial advice. It is an educational tool and a research template.Past performance does not guarantee future results. Backtests are hypothetical and cannot capture real-world execution, liquidity, spreads, or gaps.Overfitting risk. With many adjustable parameters, it is easy to find settings that look great on history and fail live. Prefer settings that work across a range of values and markets.Small samples mislead. Results from fewer than about 100 trades are not statistically meaningful.Z-scores assume a stable distribution. Price returns are fat-tailed and change over time, so extreme Z readings can persist or grow instead of reverting.Position sizing: the default is 25% of equity per trade. Adjust it to your own risk tolerance, since risk per trade also depends on the ATR stop distance.Orders fill on the next bar’s open in backtests. Live fills may differ.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView