headAndShoulders

The Head and Shoulders pattern is one of the most recognized reversal formations. It uses seven swing points to build three peaks: two shoulders and one head in the middle. Traders use it to spot a possible trend reversal (from bullish to bearish, or the inverted version for bearish to bullish).

Syntax

headAndShoulders(leftBase, leftShoulder, leftNeck, head, rightNeck, rightShoulder, rightBase, styles?)

Parameters

leftBase (PricedData) · The start point at the base before the left shoulder. leftShoulder (PricedData) · Peak of the left shoulder. leftNeck (PricedData) · Valley after the left shoulder. head (PricedData) · Highest (or lowest, in inverse) point of the pattern. rightNeck (PricedData) · Valley after the head. rightShoulder (PricedData) · Peak of the right shoulder. rightBase (PricedData) · End base after the right shoulder. styles (HeadAndShouldersStyleOverrides) · Style and display options:

  • fillBackground (boolean) · Fill the inside of the pattern.

  • transparency (number) · Transparency of the fill (0–100).

  • showLabels (boolean) · Show labels for each point.

  • line (LinesLevels without coeff) · Line style for connectors (linestyle, linewidth, color).

  • background (RGBAColor | BaseColors) · Fill color for the shape.

Return Value

(string) · The drawing ID of the created Head and Shoulders pattern.

Example

Every 120 candles, we draw a Head and Shoulders using seven selected swing points.

//@version=1
init = () => {
  indicator({ onMainPanel: true, format: 'inherit' });
};

onTick = () => {
  if (index % 120 === 0) { // draw every 120 bars
    // 1) Define 7 anchors
    const LBase   = newPoint(time(140), low(140));
    const LShould = newPoint(time(120), high(120));
    const LNeck   = newPoint(time(105), low(105));
    const Head    = newPoint(time(85),  high(85));
    const RNeck   = newPoint(time(65),  low(65));
    const RShould = newPoint(time(45),  high(45));
    const RBase   = newPoint(time(25),  low(25));

    // 2) Style options
    const style = {
      fillBackground: true,
      transparency: 75,
      showLabels: true,
      line: { linestyle: 0, linewidth: 2, color: color.red },
      background: color.rgba(255, 0, 0, 0.15)
    };

    // 3) Draw Head and Shoulders
    headAndShoulders(LBase, LShould, LNeck, Head, RNeck, RShould, RBase, style);
  }
};

Tips

  • The neckline (connecting leftNeck and rightNeck) is the key breakout level. Watch closely if price closes beyond it.

  • Works both as a regular H&S (tops, bearish reversal) and inverse H&S (bottoms, bullish reversal).

  • Works best on higher timeframes for more reliable reversals.

Warning

  • Don’t force the pattern on random points — if the head isn’t clearly higher (or lower in inverse), the structure is invalid.

  • A sloping neckline is fine, but too extreme of an angle weakens the pattern.

Good Practice

  • Always combine the H&S with volume analysis — typically, volume decreases across the pattern and spikes on the neckline breakout.

  • Store your style object in a constant for consistency across backtests and visual clarity.

Last updated