HMA Z-Score Probability Indicator by Erika Barker

Key Features:
Z-Score Calculation: Measures how many standard deviations the current price is from its HMA.
Hull Moving Average (HMA): This moving average provides a more responsive baseline for Z-Score calculations.
Flexible Display: Offers both area and candlestick visualization options for the Z-Score.
Probability Zones: Color-coded areas showing the statistical likelihood of prices based on their Z-Score.
Dynamic Price Level Labels: Displays actual price levels corresponding to Z-Score values.
Z-Table: An optional table showing the probability of occurrence for different Z-Score ranges.
Standard Deviation Lines: Horizontal lines at each standard deviation level for easy reference.
How It Works:
The indicator calculates the Z-Score by comparing the current price to its HMA and dividing by the standard deviation. This Z-Score is then plotted on a separate pane below the main chart.
Green areas/candles: Indicate prices above the HMA (positive Z-Score)
Red areas/candles: Indicate prices below the HMA (negative Z-Score)
Color-coded zones:
Green: Within 1 standard deviation (high probability)
Yellow: Between 1 and 2 standard deviations (medium probability)
Red: Beyond 2 standard deviations (low probability)
The HMA line (white) shows the trend of the Z-Score itself, offering insight into whether the asset is becoming more or less volatile over time.
Customization Options:
Adjust lookback periods for Z-Score and HMA calculations
Toggle between area and candlestick display
Show/hide probability fills, Z-Table, HMA line, and standard deviation bands
Customize text color and decimal rounding for price levels
Interpretation:
This indicator helps traders identify potential overbought or oversold conditions based on statistical probabilities. Extreme Z-Score values (beyond ±2 or ±3) often suggest a higher likelihood of mean reversion, while consistent Z-Scores in one direction may indicate a strong trend.
By combining the Z-Score with the HMA and probability zones, traders can gain a nuanced understanding of price movements relative to recent trends and their statistical significance.
This is Version 2 of the Z-Score Probability Indicator (HMA) by Erika Barker.
Version 1 of this indicator was a heavy modification of SteverSteves' Z-score probability indicator, but I've significantly enhanced version 2 of this Z-score indicator with several professional trading features and UX improvements, while maintaining the core concept of measuring price deviations from a Hull Moving Average in terms of standard deviations.
Technical Enhancements
Adaptive Lookback Periods
- Dynamically adjusts the lookback length based on market volatility
- Uses longer periods in high volatility (for stability) and shorter in low volatility (for responsiveness)
- Configurable minimum and maximum boundaries to prevent extreme values
- Visual indicator shows the current adaptive period length
Divergence Detection System
- Identifies when price makes a new high/low but the Z-Score fails to confirm
- Uses a sophisticated pivot detection algorithm to reduce false signals
- Configurable sensitivity threshold
- Visual markers for both bullish and bearish divergences
Improved Error Handling
- Protected against division by zero in standard deviation calculations
- Added checks for NaN values and the first few bars where data is insufficient
- More robust pivot detection to reduce false signals
Performance Optimization
- Conditional calculations that only run when features are enabled
- Better variable management to reduce unnecessary recalculations
- More efficient code structure
User Interface Improvements
Organized Settings Menu
- Settings grouped into logical categories for easier navigation
- Added tooltips for better explanation of each option
- Improved defaults for better out-of-the-box experience
Modernized Visual Design
- Professional color scheme with Material Design-inspired colors
- Customizable color settings for all visual elements
- Improved contrast and readability
- Enhanced probability zone visualization
Interactive Information Display
- Improved Z-Score probability table with current value indicator
- Clear mode indicator (Adaptive vs Fixed)
- Better positioning of price level labels
Custom Alerts
- Added alerts for bullish and bearish divergences
- Added alerts for crossing extreme Z-Score thresholds
- Custom alert messages with relevant trading information
Code Structure Improvements
Updated to Pine Script v6
Leverages the latest Pine Script features and optimizations
Better Variable Organization
- Clearer variable naming conventions
- More logical grouping of related calculations
- Improved comments for better code maintainability
Fixed Syntax Issues
- Corrected issues with multi-line function calls
- Fixed variable scope problems
- Added proper conditional processing
Usage Recommendations
This enhanced Z-Score indicator is particularly effective for:
- Mean-reversion trading strategies
- Identifying potential reversal points
- Statistical analysis of price movements
- Volatility-aware market analysis
For best results, combine with volume analysis and trend identification tools. The divergence detection is especially useful for finding high-probability reversal points in ranging markets.
Version 1 of this indicator was a heavy modification of SteverSteves' Z-score probability indicator, but I've significantly enhanced version 2 of this Z-score indicator with several professional trading features and UX improvements, while maintaining the core concept of measuring price deviations from a Hull Moving Average in terms of standard deviations.
Technical Enhancements
Adaptive Lookback Periods
- Dynamically adjusts the lookback length based on market volatility
- Uses longer periods in high volatility (for stability) and shorter in low volatility (for responsiveness)
- Configurable minimum and maximum boundaries to prevent extreme values
- Visual indicator shows the current adaptive period length
Divergence Detection System
- Identifies when price makes a new high/low but the Z-Score fails to confirm
- Uses a sophisticated pivot detection algorithm to reduce false signals
- Configurable sensitivity threshold
- Visual markers for both bullish and bearish divergences
Improved Error Handling
- Protected against division by zero in standard deviation calculations
- Added checks for NaN values and the first few bars where data is insufficient
- More robust pivot detection to reduce false signals
Performance Optimization
- Conditional calculations that only run when features are enabled
- Better variable management to reduce unnecessary recalculations
- More efficient code structure
User Interface Improvements
Organized Settings Menu
- Settings grouped into logical categories for easier navigation
- Added tooltips for better explanation of each option
- Improved defaults for better out-of-the-box experience
Modernized Visual Design
- Professional color scheme with Material Design-inspired colors
- Customizable color settings for all visual elements
- Improved contrast and readability
- Enhanced probability zone visualization
Interactive Information Display
- Improved Z-Score probability table with current value indicator
- Clear mode indicator (Adaptive vs Fixed)
- Better positioning of price level labels
Custom Alerts
- Added alerts for bullish and bearish divergences
- Added alerts for crossing extreme Z-Score thresholds
- Custom alert messages with relevant trading information
Code Structure Improvements
Updated to Pine Script v6
Leverages the latest Pine Script features and optimizations
Better Variable Organization
- Clearer variable naming conventions
- More logical grouping of related calculations
- Improved comments for better code maintainability
Fixed Syntax Issues
- Corrected issues with multi-line function calls
- Fixed variable scope problems
- Added proper conditional processing
Usage Recommendations
This enhanced Z-Score indicator is particularly effective for:
- Mean-reversion trading strategies
- Identifying potential reversal points
- Statistical analysis of price movements
- Volatility-aware market analysis
For best results, combine with volume analysis and trend identification tools. The divergence detection is especially useful for finding high-probability reversal points in ranging markets.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông báo miễn trừ trách nhiệm
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.