OPEN-SOURCE SCRIPT
Structured Head and Shoulder Pattern (MastersinMarkets)

[]Overview
This proprietary indicator automates the detection of classic Head and Shoulders (H&S) and Inverse Head and Shoulders patterns using a rigorous structural approach. Designed for traders who prioritize geometric symmetry and statistical quality, it filters out "noisy" or low-probability formations that often lead to false breakouts.
[]Core Logic
The script utilizes a multi-stage validation engine to confirm pattern integrity:
*Pivot Analysis: Identifies high-fidelity swing points using a configurable "Swing Strength" to ensure only significant market turns are considered.
*Symmetry Scoring: A proprietary algorithm evaluates patterns based on price symmetry (Shoulder height similarity), time symmetry (duration between peaks), and neckline slope.
*ATR Volatility Scaling: The "Min Pattern Size" filter ensures the pattern is large enough relative to current market volatility to be considered structurally significant.
[]Key Features
*Dynamic Quality Score: Every detected pattern is assigned a score (0–100). Only those meeting your "Min Quality Threshold" are displayed, helping you focus on high-probability setups.
*Flexible Necklines: Allows for both horizontal and sloping necklines with a "Max Slope" constraint to maintain structural validity.
*Visual Structure Mapping: Automatically plots the connecting lines of the pattern and extends the neckline for clear breakout monitoring.
*Real-time Alerts: Integrated alerts trigger the moment a validated pattern completes its Right Shoulder.
[]How It Works
*Detection: The script looks for a sequence of five swing points (High-Low-High-Low-High for bearish setups).
*Validation: It checks if the "Head" is higher than both "Shoulders" and if the distance between swings meets the minimum bar count.
*Scoring: It calculates the $Price\_Symmetry$,
TIME\_Ratio$, and $Slope\_Score$.
*Execution: If the cumulative score exceeds the user-defined threshold (e.g., 60), the pattern is drawn on the chart.
[]Disclaimer
Trading involves significant risk. This indicator is a tool for technical analysis and does not constitute financial advice. Past performance, including high-quality symmetry scores, does not guarantee future results. Always use proper risk management and consider market context before executing trades.
This proprietary indicator automates the detection of classic Head and Shoulders (H&S) and Inverse Head and Shoulders patterns using a rigorous structural approach. Designed for traders who prioritize geometric symmetry and statistical quality, it filters out "noisy" or low-probability formations that often lead to false breakouts.
[]Core Logic
The script utilizes a multi-stage validation engine to confirm pattern integrity:
*Pivot Analysis: Identifies high-fidelity swing points using a configurable "Swing Strength" to ensure only significant market turns are considered.
*Symmetry Scoring: A proprietary algorithm evaluates patterns based on price symmetry (Shoulder height similarity), time symmetry (duration between peaks), and neckline slope.
*ATR Volatility Scaling: The "Min Pattern Size" filter ensures the pattern is large enough relative to current market volatility to be considered structurally significant.
[]Key Features
*Dynamic Quality Score: Every detected pattern is assigned a score (0–100). Only those meeting your "Min Quality Threshold" are displayed, helping you focus on high-probability setups.
*Flexible Necklines: Allows for both horizontal and sloping necklines with a "Max Slope" constraint to maintain structural validity.
*Visual Structure Mapping: Automatically plots the connecting lines of the pattern and extends the neckline for clear breakout monitoring.
*Real-time Alerts: Integrated alerts trigger the moment a validated pattern completes its Right Shoulder.
[]How It Works
*Detection: The script looks for a sequence of five swing points (High-Low-High-Low-High for bearish setups).
*Validation: It checks if the "Head" is higher than both "Shoulders" and if the distance between swings meets the minimum bar count.
*Scoring: It calculates the $Price\_Symmetry$,
*Execution: If the cumulative score exceeds the user-defined threshold (e.g., 60), the pattern is drawn on the chart.
[]Disclaimer
Trading involves significant risk. This indicator is a tool for technical analysis and does not constitute financial advice. Past performance, including high-quality symmetry scores, does not guarantee future results. Always use proper risk management and consider market context before executing trades.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.