OPEN-SOURCE SCRIPT
Updated HH/LL Trendlines [twr]

Automatically detects swing structure (HH/HL/LH/LL) using pivot highs/lows, labels each swing point, and — the key feature — draws trendlines connecting same-type consecutive pivots: LH→LH on the high side, HL→HL on the low side. This visualizes the two "structure lines" traders watch for trend continuation and potential breaks.
How it works

Trendline logic
Live projection
Inputs summary
How it works
- Pivot detection & classification
- Uses ta.pivothigh()/ta.pivotlow() with a user-defined Swing Length (fractal-style, symmetric lookback/lookforward)
- Each new swing high is compared to the prior swing high: higher → labeled HH (bullish, green), lower → labeled LH (bearish, red)
- Each new swing low is compared to the prior swing low: lower → labeled LL (bearish, red), higher → labeled HL (bullish, green)
- First pivot on each side gets a neutral "x" label since there's nothing to compare against yet
Trendline logic
- Only connects pivots of the same classification — so a LH connects to the previous LH (skipping over any HH in between), and a HL connects to the previous HL. This produces clean descending-resistance / ascending-support structure lines rather than zigzagging between every pivot.
- Lines are capped per side (Max Trend Lines Shown) using an array-based pool with oldest-first trimming, so the chart doesn't get cluttered over time
Live projection
- If Project Lines Forward is enabled, each line's slope is recalculated every bar and extended to the current bar (getProjectedY()), so the structure line behaves like a live trend channel boundary rather than a static segment frozen at the two pivot points
- Optional Remove Line Once Price Crosses It will auto-delete a line when price closes (or wicks, depending on Cross Source) through the projected level — useful for treating the line as an invalidated trendline break
Inputs summary
- Structure: swing length, label toggle
- Trend Lines: enable high/low connections independently, line width/style, max lines per side
- Projection: forward extension toggle, cross-removal toggle, cross source (Close vs High/Low)
- Colors: bullish/bearish color customization
Release Notes
Added ZigZag with live lineOpen-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.