OPEN-SOURCE SCRIPT

Rolling Z-Score Trend [QuantAlgo]

480
๐ŸŸข Overview

The Rolling Z-Score Trend measures how far the current price deviates from its rolling mean in terms of standard deviations. It transforms price data into standardized scores to identify overbought and oversold conditions while tracking momentum shifts.
snapshot
The indicator displays a Z-Score line showing price deviation from statistical norms, with background momentum columns showing the rate of change in these deviations. This helps traders and investors identify mean reversion opportunities and momentum shifts across different asset classes and timeframes.

๐ŸŸข How It Works

The indicator uses the Z-Score formula: Z = (X - ฮผ) / ฯƒ, where X is the current closing price, ฮผ is the rolling mean, and ฯƒ is the rolling standard deviation over a user-defined lookback period. This creates a dynamic baseline that adapts to changing market conditions and standardizes price movements for interpretation across different assets and volatility conditions. The raw Z-Score undergoes 3-period EMA smoothing to reduce noise while maintaining responsiveness to market signals.
snapshot
Beyond the basic Z-Score calculation, the indicator measures the rate of change in Z-Score values between successive bars, displayed as background momentum columns. This momentum component shows acceleration and deceleration of statistical deviations. All calculations are processed through confirmation filters, displaying signals only on confirmed bars to reduce premature signals based on incomplete price action.
snapshot
๐ŸŸข How to Use

1. Z-Score Interpretation and Threshold Zones
  • Positive Values (Above Zero): Price trading above statistical mean, suggesting bullish momentum or potential overbought conditions
  • Negative Values (Below Zero): Price trading below statistical mean, suggesting bearish momentum or potential oversold conditions
  • Zero Line Crosses: Signal transitions between statistical regimes and potential trend changes
    snapshot
  • Upper Threshold Zone: Area above entry threshold (default 1.5) indicating potential overbought conditions
  • Lower Threshold Zone: Area below negative entry threshold (default -1.5) indicating potential oversold conditions
  • Extreme Values (ยฑ2.0 or higher): Statistically significant deviations that may indicate reversal opportunities

2. Momentum Background Analysis and Info Table
snapshot
  • Green Columns: Accelerating positive momentum in Z-Score values
  • Red Columns: Accelerating negative momentum in Z-Score values
  • Column Height: Magnitude of momentum change between bars
  • Momentum Divergence: When columns contradict primary Z-Score direction, often signals impending reversals
  • Info Table: Displays real-time numerical values for both Z-Score and momentum, including trend direction indicators and bar-to-bar change calculations for position management

3. Preconfigured Settings
  • Default: Balanced performance across multiple timeframes and asset classes for general trading and medium-term position management.
    snapshot
  • Scalping: Responsive setup for ultra-short-term trading on 1-15 minute charts with frequent signals and increased sensitivity to quick price movements.
    snapshot
  • Swing Trading: Optimized for multi-day positions with noise filtering, focusing on larger price swings. Most effective on 1-4 hour and daily timeframes.
    snapshot
  • Trend Following: Maximum smoothing that prioritizes established trends over short-term volatility. Generates fewer signals for daily and weekly charts.
    snapshot

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.