HorizonAI
IndicatorPro

Head & Shoulders Pattern

Classic pattern recognition automated. Detects both head & shoulders tops and inverse H&S bottoms with neckline projection. Includes measured move targets and pattern validation scoring.

Full Source Code
Alert Templates
Build on with HorizonAI

What's Included

Auto H&S detection
Inverse H&S detection
Neckline projection
Measured move targets
Pattern strength scoring
Alert on pattern completion

How Head & Shoulders Pattern works

The head and shoulders is one of the oldest and most widely recognised reversal patterns in technical analysis. It forms as three peaks: a first peak (the left shoulder), a higher peak (the head), and a third, lower peak roughly level with the first (the right shoulder). A line connecting the two intervening troughs is the neckline, and a break of that neckline signals the potential reversal from up to down. The inverse pattern mirrors this at market bottoms with three troughs.

The logic is a loss of momentum. Each successive push fails to sustain new highs after the head, and the lower right shoulder shows buyers are no longer able to press price higher. Volume traditionally tapers through the formation and expands on the neckline break, adding conviction. The measured-move target is estimated by taking the vertical distance from the head to the neckline and projecting it from the break point in the direction of the breakout.

In practice, traders wait for a decisive neckline break rather than anticipating one, and many look for a retest of the broken neckline as former support turned resistance before committing. The measured move is a guideline for a target, not a promise, and the pattern can fail if price reclaims the neckline.

When to use it

  • Spotting potential trend reversals after an extended move up (head and shoulders) or down (inverse).
  • Setting a measured-move target using the head-to-neckline distance projected from the break.
  • Timing entries on a confirmed neckline break, or on a retest of the broken neckline.
  • Placing logical invalidation above the right shoulder (or below it for the inverse pattern).

When it's not the right tool

  • Choppy or range-bound markets that throw up messy, unreliable shapes resembling the pattern.
  • Acting before the neckline breaks; an unconfirmed pattern often fails to complete.
  • Treating the measured move as a certainty rather than a rough, frequently-missed target.

Source Code Preview

Get the full PineScript v6 source code—use it as a foundation and build on top of it with HorizonAI.

head-and-shoulders.pine
1//@version=6
2indicator("Head & Shoulders Pattern", overlay=true)
3// ─────────────────────────────────────
4// Head & Shoulders Pattern - Full Source Code
5// ─────────────────────────────────────
6
7// Input Settings
8pivotLen = input.int(5, "Pivot Length")
9showLabels = input.bool(true, "Show Labels")
10
11// Core Logic
12pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
13pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
14
15// Structure Detection
16var float lastHigh = na
17var float lastLow = na
18
19if not na(pivotHigh)
20 lastHigh := pivotHigh
21 // ... more logic
22
23// Break of Structure
24bosUp = close > lastHigh

200+ lines of source code

Unlock premium to access the full source code

Unlock Source Code

Frequently asked questions

How do I calculate the price target?

Measure the vertical distance from the top of the head to the neckline, then project that same distance from the point where price breaks the neckline, in the direction of the break. It gives a reasonable objective, but price can fall short of or exceed it, so treat it as a guide rather than a fixed destination.

Should I enter as soon as I spot the pattern?

Generally no. The pattern is only confirmed when price closes decisively through the neckline. Many traders wait for that break, and some for a subsequent retest of the neckline as new resistance or support, to reduce the chance of trading a formation that never completes.

What is an inverse head and shoulders?

It is the same structure flipped for market bottoms: three troughs with a lower middle trough (the head) and a neckline above. A break above the neckline signals a potential reversal from down to up. The measured-move logic and the risk of false breaks apply equally, so confirmation still matters.

Get access to all 23+ scripts

Full source code, alert templates, and the perfect base to build on with HorizonAI. Join 10,000+ traders.