OPEN-SOURCE SCRIPT
Обновлено Swing-Level Z-Score Oscillator

▶️Overview
The Swing-Level Z-Score Oscillator is an innovative indicator that bridges the gap between classic market structure and statistical probability. Instead of relying on traditional moving averages as a baseline, this oscillator evaluates price extremes relative to recent structural pivot levels (Swing Highs and Swing Lows).
By transforming these structural deviations into a standardized Z-Score, it provides a highly intuitive, context-aware perspective on Overbought (OB) and Oversold (OS) conditions.
▶️How It Works (The Logic)
Traditional oscillators often lag or provide false signals during strong trends. This script tackles that issue through a unique three-step process:
Dynamic Baseline : The algorithm constantly scans for recent Pivot Highs and Pivot Lows. It takes the average of the last N pivots to establish a dynamic "horizontal zone" of recent historical interest. This acts as our expected mean.
Error & Volatility: It measures the distance (error) between the current Close price and this expected mean. To understand the significance of this distance, it calculates the rolling standard deviation of these errors.
Z-Score Normalization: Finally, it divides the current error by the standard deviation. The result is a clean Z-Score that tells you exactly how many standard deviations the current price has stretched away from recent structural levels.
▶️Key Features
Actionable Market Context: Because the baseline is built on actual price pivots rather than arbitrary averages, the oscillator respects current market structure (support/resistance).
Intelligent Gradient UI: The indicator features a dynamic color-coding system.
The histogram and signal line smoothly fade based on the intensity of the momentum.
Vivid Extreme Alerts: When the Z-Score stretches beyond the critical ±2.0 Sigma threshold, the histogram flashes vivid Cyan (Overbought) or Neon Pink (Oversold), immediately catching your attention.
Plug-and-Play Presets: Don't want to mess with settings? Use the "Operating Mode" dropdown to quickly switch between Short-term, Standard, and Long-term presets tailored to different trading styles. Fully customizable options are also available.
▶️How to Trade with It
Mean Reversion (Fade the Extremes): When the histogram hits the vivid ±2.0 zones, the price is statistically overextended relative to recent swing levels. Look for exhaustion price action (like pin bars) combined with a hook back toward the center line to trade reversions.
Pullbacks in a Trend: During a clear trend, look for the oscillator to reset back to the Center Line (0) or the ±1 Sigma lines. These often represent optimal, low-risk entry points (buy the dip/sell the rally) before the trend resumes.
Momentum Breakouts: A sudden, aggressive spike that blasts through the ±2 Sigma line can indicate a genuine structural breakout with heavy momentum, rather than a mere overextension.
▶️Settings & Customization
If you select "Custom" in the Operating Mode, you can fine-tune:
Left/Right Bars: Adjusts the sensitivity of the pivot detection. Lower numbers catch micro-swings, while higher numbers catch major structural points.
StdDev Length: The lookback period for calculating the variance of the errors.
Past Pivots Count (N): Determines how many historical pivots are used to calculate the "Expected Value" baseline.
Disclaimer: This script is for educational and analytical purposes only. Always combine oscillator readings with broader price action analysis and proper risk management.
The Swing-Level Z-Score Oscillator is an innovative indicator that bridges the gap between classic market structure and statistical probability. Instead of relying on traditional moving averages as a baseline, this oscillator evaluates price extremes relative to recent structural pivot levels (Swing Highs and Swing Lows).
By transforming these structural deviations into a standardized Z-Score, it provides a highly intuitive, context-aware perspective on Overbought (OB) and Oversold (OS) conditions.
▶️How It Works (The Logic)
Traditional oscillators often lag or provide false signals during strong trends. This script tackles that issue through a unique three-step process:
Dynamic Baseline : The algorithm constantly scans for recent Pivot Highs and Pivot Lows. It takes the average of the last N pivots to establish a dynamic "horizontal zone" of recent historical interest. This acts as our expected mean.
Error & Volatility: It measures the distance (error) between the current Close price and this expected mean. To understand the significance of this distance, it calculates the rolling standard deviation of these errors.
Z-Score Normalization: Finally, it divides the current error by the standard deviation. The result is a clean Z-Score that tells you exactly how many standard deviations the current price has stretched away from recent structural levels.
▶️Key Features
Actionable Market Context: Because the baseline is built on actual price pivots rather than arbitrary averages, the oscillator respects current market structure (support/resistance).
Intelligent Gradient UI: The indicator features a dynamic color-coding system.
The histogram and signal line smoothly fade based on the intensity of the momentum.
Vivid Extreme Alerts: When the Z-Score stretches beyond the critical ±2.0 Sigma threshold, the histogram flashes vivid Cyan (Overbought) or Neon Pink (Oversold), immediately catching your attention.
Plug-and-Play Presets: Don't want to mess with settings? Use the "Operating Mode" dropdown to quickly switch between Short-term, Standard, and Long-term presets tailored to different trading styles. Fully customizable options are also available.
▶️How to Trade with It
Mean Reversion (Fade the Extremes): When the histogram hits the vivid ±2.0 zones, the price is statistically overextended relative to recent swing levels. Look for exhaustion price action (like pin bars) combined with a hook back toward the center line to trade reversions.
Pullbacks in a Trend: During a clear trend, look for the oscillator to reset back to the Center Line (0) or the ±1 Sigma lines. These often represent optimal, low-risk entry points (buy the dip/sell the rally) before the trend resumes.
Momentum Breakouts: A sudden, aggressive spike that blasts through the ±2 Sigma line can indicate a genuine structural breakout with heavy momentum, rather than a mere overextension.
▶️Settings & Customization
If you select "Custom" in the Operating Mode, you can fine-tune:
Left/Right Bars: Adjusts the sensitivity of the pivot detection. Lower numbers catch micro-swings, while higher numbers catch major structural points.
StdDev Length: The lookback period for calculating the variance of the errors.
Past Pivots Count (N): Determines how many historical pivots are used to calculate the "Expected Value" baseline.
Disclaimer: This script is for educational and analytical purposes only. Always combine oscillator readings with broader price action analysis and proper risk management.
Информация о релизе
The recording methodology for pivot highs and lows has been revised from an individual to a collective format. Furthermore, the most recent pivot is now excluded from average calculations to ensure a more robust estimation.Информация о релизе
changed pivot calculations to close-base.Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.