The Savitzky-Golay Z-Score [BackQuant] is a powerful trading indicator that combines the precision of the Savitzky-Golay filter with the statistical strength of the Z-Score. This advanced indicator is designed to detect trend shifts, identify overbought or oversold conditions, and highlight potential divergences in the market, providing traders with a unique edge in detecting momentum changes and trend reversals.
Core Concept: Savitzky-Golay Filter The Savitzky-Golay filter is a widely-used smoothing technique that preserves important signal features such as peak detection while filtering out noise. In this indicator, the filter is applied to price data (default set to HLC3) to smooth out volatility and produce a cleaner trend line. By specifying the window size and polynomial degree, traders can fine-tune the degree of smoothing to match their preferred trading style or market conditions.
Z-Score: Measuring Deviation The Z-Score is a statistical measure that indicates how far the current price is from its mean in terms of standard deviations. In trading, the Z-Score can be used to identify extreme price moves that are likely to revert or continue trending. A positive Z-Score means the price is above the mean, while a negative Z-Score indicates the price is below the mean.
This script calculates the Z-Score based on the Savitzky-Golay filtered price, enabling traders to detect moments when the price is diverging from its typical range and may present an opportunity for a trade.
Long and Short Conditions The Savitzky-Golay Z-Score generates clear long and short signals based on the Z-Score value:
Long Signals: When the Z-Score is positive, indicating the price is above its smoothed mean, a long signal is generated. The color of the bars turns green, signaling upward momentum. Short Signals: When the Z-Score is negative, indicating the price is below its smoothed mean, a short signal is generated. The bars turn red, signaling downward momentum. These signals allow traders to follow the prevailing trend with confidence, using statistical backing to avoid false signals from short-term volatility.
Standard Deviation Levels and Extreme Levels This indicator includes several features to help visualize overbought and oversold conditions: Standard Deviation Levels: The script plots horizontal lines at +1, +2, -1, and -2 standard deviations. These levels provide a reference for how far the current price is from the mean, allowing traders to quickly identify when the price is moving into extreme territory.
Extreme Levels: Additional extreme levels at +3 and +4 (and their negative counterparts) are plotted to highlight areas where the price is highly likely to revert. These extreme levels provide important insight into market conditions that are far outside the norm, signaling caution or potential reversal zones.
The indicator also adapts the color shading of these extreme zones based on the Z-Score’s strength. For example, the area between +3 and +4 is shaded with a stronger color when the Z-Score approaches these values, giving a visual representation of market pressure.
Divergences: Detecting Hidden and Regular Signals A key feature of the Savitzky-Golay Z-Score is its ability to detect bullish and bearish divergences, both regular and hidden: Regular Bullish Divergence: This occurs when the price makes a lower low while the Z-Score forms a higher low. It signals that bearish momentum is weakening, and a bullish reversal could be near. Hidden Bullish Divergence: This divergence occurs when the price makes a higher low while the Z-Score forms a lower low. It signals that bullish momentum may continue after a temporary pullback. Regular Bearish Divergence: This occurs when the price makes a higher high while the Z-Score forms a lower high, signaling that bullish momentum is weakening and a bearish reversal may be near. Hidden Bearish Divergence: This divergence occurs when the price makes a lower high while the Z-Score forms a higher high, indicating that bearish momentum may continue after a temporary rally. These divergences are plotted directly on the chart, making it easier for traders to spot when the price and momentum are out of sync and when a potential reversal may occur.
Customization and Visualization The Savitzky-Golay Z-Score offers a range of customization options to fit different trading styles: Window Size and Polynomial Degree: Adjust the window size and polynomial degree of the Savitzky-Golay filter to control how much smoothing is applied to the price data. Z-Score Lookback Period: Set the lookback period for calculating the Z-Score, allowing traders to fine-tune the sensitivity to short-term or long-term price movements. Display Options: Choose whether to display standard deviation levels, extreme levels, and divergence labels on the chart. Bar Color: Color the price bars based on trend direction, with green for bullish trends and red for bearish trends, allowing traders to easily visualize the current momentum. Divergences: Enable or disable divergence detection, and adjust the lookback periods for pivots used to detect regular and hidden divergences.
Alerts and Automation To ensure you never miss an important signal, the indicator includes built-in alert conditions for the following events: Positive Z-Score (Long Signal): Triggers an alert when the Z-Score crosses above zero, indicating a potential buying opportunity. Negative Z-Score (Short Signal): Triggers an alert when the Z-Score crosses below zero, signaling a potential short opportunity. Shifting Momentum: Alerts when the Z-Score is shifting up or down, providing early warning of changing market conditions. These alerts can be configured to notify you via email, SMS, or app notification, allowing you to stay on top of the market without having to constantly monitor the chart.
Trading Applications The Savitzky-Golay Z-Score is a versatile tool that can be applied across multiple trading strategies: Trend Following: By smoothing the price and calculating the Z-Score, this indicator helps traders follow the prevailing trend while avoiding false signals from short-term volatility. Mean Reversion: The Z-Score highlights moments when the price is far from its mean, helping traders identify overbought or oversold conditions and capitalize on potential reversals. Divergence Trading: Regular and hidden divergences between the Z-Score and price provide early warning of trend reversals, allowing traders to enter trades at opportune moments.
Final Thoughts The Savitzky-Golay Z-Score [BackQuant] is an advanced statistical tool designed to provide a clearer view of market trends and momentum. By applying the Savitzky-Golay filter and Z-Score analysis, this indicator reduces noise and highlights key areas where the market may reverse or accelerate, giving traders a significant edge in understanding price behavior.
Whether you’re a trend follower or a reversal trader, this indicator offers the flexibility and insights you need to navigate complex markets with confidence.
No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.
Check out whop.com/backquant for Access to Invite Only Scripts!
Também em:
Aviso legal
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.