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!
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menjadikannya sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Hormat untuk penulisnya! Meskipun anda dapat menggunakannya secara gratis, ingatlah bahwa penerbitan ulang kode tersebut tunduk pada Tata Tertib kami.
Pernyataan Penyangkalan
Informasi dan publikasi tidak dimaksudkan untuk menjadi, dan bukan merupakan saran keuangan, investasi, perdagangan, atau rekomendasi lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Persyaratan Penggunaan.
