OPEN-SOURCE SCRIPT
Atualizado

Head & Shoulders Auto Detector [AGPro Series]

3 378
Head & Shoulders Auto Detector [AGPro Series]

🎯 **Overview**

Head & Shoulders Auto Detector is a precision pattern recognition tool that automatically identifies classic Head & Shoulders (bearish) and Inverse Head & Shoulders (bullish) reversal formations across any market and timeframe. Built from the ground up for traders who want the full lifecycle of a pattern tracked on-chart — not just a label and a line, but forming → confirmation → target/stop outcome — with a transparent, quality-scored framework that filters low-probability setups before they clutter the chart.

Every pattern carries a composite quality score, a symmetry percentage, an ATR-adaptive neckline, two projection targets, and a live status label that evolves through the pattern's lifespan.

🔹 **Unique Edge**

Most H&S indicators stop at detection. This one goes further:

• **Full lifecycle state machine** — every pattern moves through four explicit states (Forming → Confirmed → Target Hit / Stopped / Invalidated / Expired), and the visuals update in real time at each transition.

• **Dead pattern hygiene** — once a pattern fails or hits target, orphan TP and stop lines are removed, the neckline freezes at the decision bar, and the status label grays out. The chart never accumulates stale clutter.

• **Quality-driven visual hierarchy** — high-quality patterns (Q≥75) are rendered with a star marker and full saturation, mid-tier patterns get standard treatment, and low-tier patterns (Q<60) fade into the background so the trader's eye is guided to what matters.

• **Dual-target projection with R:R** — every confirmation displays both a classic measured-move TP1 and an extended 1.618× TP2, each labeled with the exact reward-to-risk ratio calculated at entry.

• **ATR-adaptive everything** — shoulder tolerance, neckline flatness, head prominence, stop buffer, and label offsets all scale with volatility, so the same settings work across BTC 4H, gold daily, or small-cap stocks.

🔹 **Methodology**

Patterns are detected from confirmed pivot highs and lows using a configurable pivot length. For a valid Head & Shoulders, three same-side pivots (Left Shoulder → Head → Right Shoulder) must satisfy:

• Head extends beyond both shoulders by at least the configured ATR multiple (prominence test).
• Shoulder heights differ by less than the shoulder tolerance in ATR units (symmetry test).
• Two opposite-side pivots between LS-Head and Head-RS define the neckline; their vertical distance must be within the neckline tolerance.
• Composite symmetry score (50% time symmetry, 50% price symmetry) must exceed the minimum threshold.

Quality score combines four weighted components:
• Symmetry (45%) — time + price balance between shoulders
• Neckline flatness (25%) — how horizontal the neckline is
• Volume profile (15%) — head-bar volume relative to shoulder average
• Head prominence (15%) — how clearly the head dominates

Confirmation triggers when price closes beyond the neckline level (interpolated for sloped necklines). Stop is placed at the head level plus an ATR buffer to avoid wick stop-outs. TP1 uses the standard head-to-neckline measured move; TP2 extends to 1.618× that projection.

🔹 **Signals & Alerts**

Four alert events available:

• **Pattern Forming** — a valid H&S or Inverse H&S structure has been detected but not yet confirmed.
• **Pattern Confirmed** — close has broken the neckline; entry is live with TP/Stop drawn.
• **Target Hit** — TP1 has been reached on a confirmed pattern.
• **Neckline Retest** — after confirmation, price has returned to touch the neckline (common high-probability re-entry zone).

🔹 **Key Inputs**

• **Pivot Length** — controls swing-point sensitivity
• **Min Symmetry Score** — minimum shoulder symmetry percentage to accept a pattern (default 60, balanced)
• **Neckline Tolerance (ATR)** — how sloped a neckline is allowed to be
• **Shoulder Height Tolerance (ATR)** — how different the two shoulders can be
• **Head Prominence (ATR)** — minimum head extension beyond shoulders
• **Volume Soft Confirmation** — toggle volume influence on quality score
• **TP1 Method** — Classic (horizontal neckline reference) or Measured Move (slope-aware)
• **Stop Buffer (ATR)** — extra room beyond the head level (default 0.35)
• **Max Pattern Lifetime** — bars after which an unconfirmed pattern expires
• Full visual controls: font size, panel position, theme, zone display, label offset, color palette

🔹 **How to Use**

1. Apply the indicator to any liquid market and timeframe. 4H and higher tend to produce the most reliable formations; intraday works but expects more noise.
2. Watch for patterns labeled with a ⭐ and bright color (Q≥75) — these are the highest-confidence setups.
3. Wait for the ✓ Confirmed status to appear before entering; the ⚡ breakout marker pinpoints the exact confirmation bar.
4. Use the TP1 / TP2 R:R labels to size the trade. Stop is pre-calculated at head level + ATR buffer.
5. Monitor the panel stats over time to understand the indicator's behavior on your specific market — Win Rate, Avg Quality, and Last Signal all update live.
6. Consider combining with trend context (a bearish H&S is far more powerful at resistance in a downtrend than in the middle of a strong uptrend).

🔹 **Limitations & Transparency**

• Pattern detection uses confirmed pivots, so signals appear with a natural delay equal to the Pivot Length setting. This is intrinsic to pivot-based logic, not a flaw.
• Quality score and historical win rate are chart-native calculations based on the loaded history; they are descriptive, not predictive.
• The script does not include multi-timeframe confluence or trend filters — these are deliberate design choices to keep the tool focused and composable with other indicators.
• Volume confirmation is a soft scoring input, not a hard filter, since many crypto pairs and indices have volume data of variable reliability.
• Pattern state transitions use close-based confirmation; intrabar wicks do not trigger state changes except for stop/target hits, which are high/low based as expected.

🔹 **Risk Disclosure**

This indicator is an analytical tool, not a trading recommendation or financial advice. Pattern recognition describes what has formed on a chart; it does not predict future price movement with certainty. Always use proper risk management, position sizing, and confirm signals with your own analysis. Past pattern statistics shown on the panel are descriptive of the visible history and do not guarantee future performance. Trading involves substantial risk of loss.
Notas de Lançamento
UPDATE NOTES - V1.7

This update focuses on bold hand-drawn pattern visibility and first-glance recognition.

The core purpose of the script remains unchanged.
This release improves how the Head & Shoulders body is drawn on the chart so the structure reads more like a manual analyst annotation.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

* Preserved the original detection engine.
Pivot detection, symmetry scoring, neckline logic, volume scoring, lifecycle tracking, target logic, stop context, and retest alerts remain unchanged.

* Added Pattern Outline Width.
The hand-drawn outline can now be adjusted from thin to bold. The default is now a bold outline for stronger visual recognition.

* Added Show Pattern Glow.
A translucent backbone is drawn under the main H&S outline so the pattern body stands out on both dark and light charts.

* Strengthened the manual drawing style.
The main LS -> neckline -> HEAD -> neckline -> RS path now uses a thick solid outline by default.

* Improved neckline visibility.
The neckline is slightly stronger while still remaining visually distinct from the H&S body.


------------------------
Visual Improvements
------------------------

* The H&S / inverse H&S body is now easier to identify at first glance.

* The structure reads closer to a manually drawn chart annotation.

* The shoulder guide and head-to-neckline stem remain available as secondary context.

* Anchor labels and zones still help users identify LS, HEAD, RS, and the major pivot areas.


------------------------
Interface & Usability
------------------------

* Added a dedicated outline-width control.

* Added a glow toggle for users who want a softer or cleaner look.

* Kept all previous panel theme, panel location, and font-size controls from V1.6.


------------------------
Behavior Notes
------------------------

This update does not change the core analytical logic of the script.

Pattern detection, scoring, confirmation, targets, stops, and retest alerts should be interpreted the same way as before.

The goal is visual clarity, not new predictive behavior.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool.

Head & Shoulders structures can vary by market, timeframe, pivot sensitivity, volatility, and neckline slope.

Outputs should always be interpreted within broader market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only.

It does not provide financial advice or guaranteed trading outcomes.

Users remain responsible for their own decisions.
Notas de Lançamento
🔧 UPDATE NOTES - v1.8

This update focuses on visual clarity and presentation.

The core purpose of the script remains unchanged.
This release improves how the existing Head & Shoulders logic is presented,
organized, and interpreted on the chart. The hand-drawn pattern outline that
defines this tool — left shoulder to neckline, neckline to head, head to
neckline, neckline to right shoulder — is fully preserved.

This script continues to function as an analytical and visualization tool.
It does not attempt to predict price direction or provide guaranteed outcomes.


------------------------
What Changed
------------------------

• Smooth, hand-drawn curved outline
The Head & Shoulders structure is now drawn as one continuous, corner-less curve
that flows through the left shoulder, neckline, head, neckline, and right
shoulder — replacing the previous straight, angular segments. The curve is tuned
to hug the actual shoulder, head, and neckline pivots so it reads like a clean,
hand-drawn annotation without overshooting the structure. The same anchor points
and detection logic are used; only the way the outline is rendered changed.

• Measured-Move Arrow + TARGET badge
On confirmation, a clean measured-move arrow is drawn from the neckline break
to the projected target, with a centered TARGET badge at the target level. This
makes the head-to-neckline projection readable at a glance, the way a measured
move is drawn by hand. It can be toggled with the new "Show Measured-Move
Arrow" setting.

• High-contrast label ink
All on-chart badges now use a luminance-based ink rule, so text stays sharp and
readable on both bright and dark badge fills across every theme.

• Brand-consistent TARGET PROOF panel section
The panel now carries a dedicated "— TARGET PROOF —" section showing the
Target Hit Rate with its sample size, matching the AGPro proof presentation used
across the series. It shows "Building" until enough confirmed patterns exist.

• Cleaner badge weighting
Pattern, anchor, BREAK, and target badges were re-balanced for a more premium,
less cluttered first-glance read.


------------------------
Visual Improvements
------------------------

• Improved chart readability with a smooth, continuous pattern outline that
reads cleanly at a glance instead of as angular segments.

• Reduced visual clutter to enhance first-glance interpretation.

• Refined visual hierarchy so the neckline, the break, and the projected target
read as one connected story.

• Adjusted label ink and positioning so text stays clearly legible against
candles and badge fills.


------------------------
Interface & Usability
------------------------

• Optimized panel layout for clearer information flow, with the target proof
presented in its own section.

• Improved label readability for better chart interaction.

• Adjusted default visual settings for a more balanced appearance.

• Enhanced overall user experience without changing core logic.


------------------------
Behavior Notes
------------------------

This update does not change the core analytical logic of the script.

The goal is to improve clarity and usability, not to introduce new predictive
behavior. Detection, lifecycle, target math, stop context, and retest tracking
all behave exactly as before.

Users should interpret outputs the same way as before, but with improved visual
structure.


------------------------
Limitations Reminder
------------------------

The script remains a rule-based analytical tool.

Market conditions such as volatility, liquidity, and timeframe differences may
affect how patterns and signals appear.

Outputs should always be interpreted within broader market context.


------------------------
Risk Reminder
------------------------

This script is for educational and analytical purposes only.

It does not provide financial advice or guaranteed trading outcomes.

Users remain responsible for their own decisions.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.