OPEN-SOURCE SCRIPT

Market Structure [Proozac]

685
Market Structure — HH · HL · LH · LL

Labels every significant swing as a Higher High, Higher Low, Lower High, or Lower Low, then draws Break of Structure (BOS) and Change of Character (CHoCH) lines automatically. The result is a clean structural map of the market directly on the price chart, with no manual markup required.

How it works

The indicator uses Pine's built-in pivot detection to find confirmed swing highs and lows. A swing is only confirmed after `Swing Length` bars have closed on each side — meaning labels always appear slightly to the left of the current bar, which is the correct behavior for non-repainting detection.

Pivot High logic:

- If the new swing high is above the previous swing high → labeled **HH** (bullish continuation)
- If the new swing high is below the previous swing high → labeled **LH** (bearish continuation)
- When a HH forms after a bearish trend → a **CHoCH** line is drawn (first sign of structural flip)
- When a HH forms during an already-bullish trend → a **BOS** line is drawn (continuation confirmed)

Pivot Low logic:

- If the new swing low is below the previous swing low → labeled **LL** (bearish continuation)
- If the new swing low is above the previous swing low → labeled **HL** (bullish continuation)
- When a LL forms after a bullish trend → **CHoCH** (structural reversal signal)
- When a LL forms during a bearish trend → **BOS** (continuation confirmed)

The zig-zag line connects consecutive pivot points in chronological order, giving a quick visual read of the overall swing sequence.

Visual output

- 🟢 HH label (above bar) → Higher High — bullish structure
- 🟢 HL label (below bar) → Higher Low — bullish pullback held
- 🔴 LH label (above bar) → Lower High — bearish structure
- 🔴 LL label (below bar) → Lower Low — bearish continuation
- 🔵 Dashed line + BOS +/− label → Break of Structure (trend continuation)
- 🟠 Dashed line + CHoCH +/− label → Change of Character (potential reversal)
- Gray zig-zag line → swing sequence connector
- Subtle background tint → green during bullish bias, red during bearish bias
- Live label on last bar → current structural bias ("Bullish" / "Bearish" / "Undefined")

Configurable parameters

Detection

- Swing Length — number of bars required on each side to confirm a pivot (default 10). Lower values = more sensitive, more noise. Higher values = fewer but more significant pivots
- Show Zig-Zag — toggle the connecting line between swings
- Show BOS / CHoCH — toggle the structural break lines and labels

Labels
- Individual toggles for **HH**, **HL**, **LH**, and **LL** labels

Colors
- Bullish Structure — color used for HH and HL labels (default teal)
- Bearish Structure — color used for LH and LL labels (default red)
- Zig-Zag Line — color of the swing connector
- BOS — color for Break of Structure lines (default blue)
- CHoCH — color for Change of Character lines (default orange)

Recommended use

Start with the default swing length of 10 on your primary timeframe and only adjust if the swing count feels too noisy (lower it) or too sparse (raise it). On 15m and 1H charts, 10 works well for most instruments. On daily charts, consider dropping to 5–7.

CHoCH is the early signal — it's the first opposite-direction structural break after a trend. BOS confirms the new trend is continuing. The highest-probability setups occur when you see a CHoCH, then a pullback that holds as a HL or LH, followed by a BOS in the new direction.

Pair this indicator with the Liquidity Sweep Detector: a sweep of the last HL (in a bullish structure) followed by a BOS to the upside is one of the cleanest confluences available in price action trading.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.