indicator · on price · open source

Market Structure (HH/HL/LH/LL)

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

Market Structure classifies every confirmed swing as HH/HL/LH/LL so you can read the trend at a glance.

  • Step plot holds the most recent swing high/low until a new pivot prints.
  • Labels appear above/below each confirmed pivot: HH/LH above, HL/LL below.
  • Use the stair-step line + labels to trade with the dominant sequence.
  • Higher-Low after Lower-Lows is the textbook bullish change of character; Lower-High after Higher-Highs is the bearish mirror.
  • A clean HH/HL sequence (no LH/LL) is the highest-quality trend day you can find.
  • Combine with a higher-timeframe structure overlay to confirm whether internal structure agrees with the dominant trend.
  • Default swing = 5, which works well on 1m–15m charts; raise it to 10+ for swing structure.

Source code

//@version=5
indicator("Market Structure (HH/HL/LH/LL)", overlay=true)
swing = input.int(5, "Swing Length", minval=2, maxval=50)
showLine = input.bool(true, "Show Structure Line")
showLabels = input.bool(true, "Show HH/HL/LH/LL Labels")
hiColor = input.string("color.green", "High Structure Color")
loColor = input.string("color.red", "Low Structure Color")
lineWidth = input.int(2, "Line Width", minval=1, maxval=5)
ph = ta.pivothigh(high, swing, swing)
pl = ta.pivotlow(low, swing, swing)
var float lastPh = na
var float prevPh = na
var float lastPl = na
var float prevPl = na
var string hiLab = ""
var string loLab = ""
if not na(ph)
    prevPh := lastPh
    lastPh := ph
    if not na(prevPh)
        hiLab := ph > prevPh ? 'HH' : 'LH'
if not na(pl)
    prevPl := lastPl
    lastPl := pl
    if not na(prevPl)
        loLab := pl > prevPl ? 'HL' : 'LL'
hiLine = showLine ? ta.valuewhen(not na(ph), ph, 0) : na
loLine = showLine ? ta.valuewhen(not na(pl), pl, 0) : na
p_Structure_High = plot(hiLine, "Structure High", color=hiColor, style=plot.style_stepline, linewidth=2)
p_Structure_Low = plot(loLine, "Structure Low", color=loColor, style=plot.style_stepline, linewidth=2)
plotshape(showLabels and not na(ph) and hiLab != '', "HH/LH", style=shape.labeldown, location=location.abovebar, color=hiColor, text="hiLab")
plotshape(showLabels and not na(pl) and loLab != '', "HL/LL", style=shape.labelup, location=location.belowbar, color=loColor, text="loLab")
alertcondition(not na(ph) and hiLab == 'HH', "HH printed", "Higher High confirmed")
alertcondition(not na(pl) and loLab == 'LL', "LL printed", "Lower Low confirmed")
alertcondition(not na(ph) and hiLab == 'LH', "LH printed", "Lower High confirmed — bearish reversal seed")
alertcondition(not na(pl) and loLab == 'HL', "HL printed", "Higher Low confirmed — bullish reversal seed")

Comments

No comments yet.

Sign in to comment.