OPEN-SOURCE SCRIPT
Automated Z-scoring - [JTCAPITAL]

Automated Z-Scoring - [JTCAPITAL] is a modified way to use statistical normalization through Z-Scores for analyzing price deviations, volatility extremes, and mean reversion opportunities in financial markets.
The indicator works by calculating in the following steps:
Buy and Sell Conditions:
While the indicator itself is designed as a statistical framework rather than a direct buy/sell signal generator, traders can derive actionable strategies from its behavior:
Trend Following: When the Z-Score crosses above zero after a prolonged negative period, it suggests a return to or above the mean — a possible bullish reversal or trend continuation signal.
Mean Reversion: When the Z-score is below for example -1.5 it indicates a good time for a DCA buying opportunity.
Trend Following: When the Z-Score crosses below zero after being positive, it may indicate a momentum slowdown or bearish shift.
Mean Reversion: When the Z-score is above for example 1.5 it indicates a good time for a DCA sell opportunity
Features and Parameters:
Length – Defines the period for both SMA and Standard Deviation. A longer length smooths the Z-Score and captures broader market context, while a shorter length increases responsiveness.
Source – Allows the user to choose which price data is analyzed (Close, Open, High, Low, etc.).
Fill Visualization – Highlights the magnitude of deviation between the Z-Score and the zero baseline, enhancing readability of volatility extremes.
Specifications:
Mean (Simple Moving Average)
The SMA calculates the average of the selected source over the defined length. It provides a central value to which the price tends to revert. In this indicator, the mean acts as the equilibrium point — the “zero” reference for all deviations.
Standard Deviation
Standard Deviation measures the dispersion of data points from their mean. In trading, it quantifies volatility. A high standard deviation indicates that prices are spread out (volatile), while a low value means they are clustered near the average (stable). The indicator uses this to scale deviations consistently across different market conditions.
Z-Score
The Z-Score converts raw price data into a standardized value measured in units of standard deviation.
A Z-Score of 0 = Price equals its mean.
A Z-Score of +1 = Price is one standard deviation above the mean.
A Z-Score of −1 = Price is one standard deviation below the mean.
This allows comparison of deviation magnitudes across instruments or timeframes, independent of price level.
Length Parameter
A long lookback period (e.g., 3000 bars) smooths temporary volatility and reveals long-term mean deviations — ideal for macro trend identification. Shorter lengths (e.g., 100–500) capture quicker oscillations and are useful for short-term mean reversion trades.
Statistical Interpretation
From a probabilistic perspective, if the distribution of prices is roughly normal:
About 68% of price observations lie within ±1 standard deviation (Z between −1 and +1).
About 95% lie within ±2 standard deviations.
Therefore, when the Z-Score moves beyond ±2, it statistically represents a rare event — often corresponding to price extremes or potential reversal zones.
Practical Benefit of Z-Scoring in Trading
Z-Scoring transforms raw price into a normalized volatility-adjusted metric. This allows traders to:
Compare instruments on a common statistical scale.
Identify mean-reversion setups more objectively.
Spot volatility expansions or contractions early.
Detect when price action significantly diverges from long-term equilibrium.
By automating this process, Automated Z-Scoring - [JTCAPITAL] provides traders with a powerful analytical lens to measure how “stretched” the market truly is — turning abstract statistics into a visually intuitive and actionable form.
Enjoy!
The indicator works by calculating in the following steps:
- Source Selection
 The indicator begins by selecting a user-defined price source (default is the Close price). Traders can modify this to use any indicator that is deployed on the chart, for accurate and fast Z-scoring.
- Mean Calculation
 A Simple Moving Average (SMA) is calculated over the selected length period (default 3000). This represents the long-term equilibrium price level or the “statistical mean” of the dataset. It provides the baseline around which all price deviations are measured.
- Standard Deviation Measurement
 The script computes the Standard Deviation of the price series over the same period. This value quantifies how far current prices tend to stray from the mean — effectively measuring market volatility. The larger the standard deviation, the more volatile the market environment.
- Z-Score Normalization
 The Z-Score is calculated as:
 (Current Price − Mean) ÷ Standard Deviation.
 This normalization expresses how many standard deviations the current price is away from its long-term average. A Z-Score above 0 means the price is above average, while a negative score indicates it is below average.
- Visual Representation
 The Z-Score is plotted dynamically, with color-coding for clarity:
 Bullish readings (Z > 0) are showing positive deviation from the mean.
 Bearish readings (Z < 0) are showing negative deviation from the mean.
 Make sure to select the correct source for what you exactly want to Z-score.
Buy and Sell Conditions:
While the indicator itself is designed as a statistical framework rather than a direct buy/sell signal generator, traders can derive actionable strategies from its behavior:
Trend Following: When the Z-Score crosses above zero after a prolonged negative period, it suggests a return to or above the mean — a possible bullish reversal or trend continuation signal.
Mean Reversion: When the Z-score is below for example -1.5 it indicates a good time for a DCA buying opportunity.
Trend Following: When the Z-Score crosses below zero after being positive, it may indicate a momentum slowdown or bearish shift.
Mean Reversion: When the Z-score is above for example 1.5 it indicates a good time for a DCA sell opportunity
Features and Parameters:
Length – Defines the period for both SMA and Standard Deviation. A longer length smooths the Z-Score and captures broader market context, while a shorter length increases responsiveness.
Source – Allows the user to choose which price data is analyzed (Close, Open, High, Low, etc.).
Fill Visualization – Highlights the magnitude of deviation between the Z-Score and the zero baseline, enhancing readability of volatility extremes.
Specifications:
Mean (Simple Moving Average)
The SMA calculates the average of the selected source over the defined length. It provides a central value to which the price tends to revert. In this indicator, the mean acts as the equilibrium point — the “zero” reference for all deviations.
Standard Deviation
Standard Deviation measures the dispersion of data points from their mean. In trading, it quantifies volatility. A high standard deviation indicates that prices are spread out (volatile), while a low value means they are clustered near the average (stable). The indicator uses this to scale deviations consistently across different market conditions.
Z-Score
The Z-Score converts raw price data into a standardized value measured in units of standard deviation.
A Z-Score of 0 = Price equals its mean.
A Z-Score of +1 = Price is one standard deviation above the mean.
A Z-Score of −1 = Price is one standard deviation below the mean.
This allows comparison of deviation magnitudes across instruments or timeframes, independent of price level.
Length Parameter
A long lookback period (e.g., 3000 bars) smooths temporary volatility and reveals long-term mean deviations — ideal for macro trend identification. Shorter lengths (e.g., 100–500) capture quicker oscillations and are useful for short-term mean reversion trades.
Statistical Interpretation
From a probabilistic perspective, if the distribution of prices is roughly normal:
About 68% of price observations lie within ±1 standard deviation (Z between −1 and +1).
About 95% lie within ±2 standard deviations.
Therefore, when the Z-Score moves beyond ±2, it statistically represents a rare event — often corresponding to price extremes or potential reversal zones.
Practical Benefit of Z-Scoring in Trading
Z-Scoring transforms raw price into a normalized volatility-adjusted metric. This allows traders to:
Compare instruments on a common statistical scale.
Identify mean-reversion setups more objectively.
Spot volatility expansions or contractions early.
Detect when price action significantly diverges from long-term equilibrium.
By automating this process, Automated Z-Scoring - [JTCAPITAL] provides traders with a powerful analytical lens to measure how “stretched” the market truly is — turning abstract statistics into a visually intuitive and actionable form.
Enjoy!
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
