OPEN-SOURCE SCRIPT
Trend Lines (HTF)

Trend Lines (HTF)
Auto-detected trend lines drawn between recent confirmed pivots across up to three higher timeframes. Resistance lines connect swing highs; support lines connect swing lows. Each line extends to the chart's right edge, and lines that price has closed through are dimmed and dashed — visible for context without dominating the chart.
The point is to put higher-timeframe trend structure on a single chart, without manually redrawing every time a new swing prints.
How it works
For each of the three configured timeframes, the script runs a pivot detector inside request.security, with bar timestamps stored alongside each pivot so lines stay anchored to absolute chart time and don't drift on zoom or scroll. The most recent swing highs and swing lows are kept per timeframe.
Trend lines are drawn between adjacent pivots — pivot N−1 to pivot N for the most recent line, pivot N−2 to pivot N−1 for the previous one, and so on, up to the configured number per side. Newer lines render at full opacity; older ones progressively fade.
A line is marked broken the moment current close has crossed past its projected price — above for resistance, below for support. Broken lines switch to grey and dashed.
All lines and labels rebuild on every tick of the last bar so the right-edge price label always reflects the line's current projected level.
How to read it
Each timeframe has its own color (defaults: teal for TF1, amber for TF2, purple for TF3) and its own line width. The most recent line per direction gets a price label at the right edge showing where that line currently projects.
Older lines fade with age. A solid, full-opacity line is the freshest trend; faded ones are historical structure that may still be relevant. Broken lines flip to grey-dashed — useful for spotting role reversal, where a broken resistance becomes new support or vice versa.
The lines connect adjacent pivots — they're not best-fit lines through many touches. This is deliberate: it shows you the slope of the most recent swing, not a line of best fit that may not match what price is actually doing right now.
Inputs
Built-in alerts
Six alerts, one per timeframe and direction:
Breaks fire on the bar they occur, based on the line's current projected price.
Notes
The lines connect adjacent pivots only. Some auto-trendline indicators try to fit lines through several swings at once; this one doesn't. The design assumption is that the slope between the two most recent swings is what's currently relevant, and older swings shouldn't be forced onto the same line just because they're nearby. If you want longer trend channels, increase pivot lookback so individual swings represent larger structural moves.
Each timeframe has its own pivot lookback by design. A daily chart and a 3-month chart usually need different sensitivities, and forcing them to share one setting tends to make at least one of them wrong.
Higher-timeframe pivots don't confirm until pivot lookback bars after the actual high or low. On a 3-month timeframe with lookback 3, that's nine months of delay — which is why TF3 is off by default and only worth turning on if you're trading multi-year structure.
When a line breaks, it stays dimmed permanently. There's no un-breaking. If price reclaims the level, that's role reversal: the broken resistance is now informing as historical structure while the most recent unbroken support takes over the active role.
This is a structural tool, not a signal generator. It marks where the recent swing slopes sit and which of those slopes price has already broken.
Five years of work on a trading system left me with dozens of indicators that ultimately didn't earn a place in the final build. They're not failures — they're tools that solved problems I no longer needed solved. So instead of shelving them, I'm publishing the majority of them open-source.
If you're a discretionary trader, take what's useful. If you're a systems builder, the source is yours to dissect, modify, and improve. The best return on five years of work is for it to keep working — for someone.
If you use this script — or part of it — in your own work, please credit the original with a link back to my profile.
Note: these indicators have been updated to Pine Script v6 — some manually, some with AI assistance.
Auto-detected trend lines drawn between recent confirmed pivots across up to three higher timeframes. Resistance lines connect swing highs; support lines connect swing lows. Each line extends to the chart's right edge, and lines that price has closed through are dimmed and dashed — visible for context without dominating the chart.
The point is to put higher-timeframe trend structure on a single chart, without manually redrawing every time a new swing prints.
How it works
For each of the three configured timeframes, the script runs a pivot detector inside request.security, with bar timestamps stored alongside each pivot so lines stay anchored to absolute chart time and don't drift on zoom or scroll. The most recent swing highs and swing lows are kept per timeframe.
Trend lines are drawn between adjacent pivots — pivot N−1 to pivot N for the most recent line, pivot N−2 to pivot N−1 for the previous one, and so on, up to the configured number per side. Newer lines render at full opacity; older ones progressively fade.
A line is marked broken the moment current close has crossed past its projected price — above for resistance, below for support. Broken lines switch to grey and dashed.
All lines and labels rebuild on every tick of the last bar so the right-edge price label always reflects the line's current projected level.
How to read it
Each timeframe has its own color (defaults: teal for TF1, amber for TF2, purple for TF3) and its own line width. The most recent line per direction gets a price label at the right edge showing where that line currently projects.
Older lines fade with age. A solid, full-opacity line is the freshest trend; faded ones are historical structure that may still be relevant. Broken lines flip to grey-dashed — useful for spotting role reversal, where a broken resistance becomes new support or vice versa.
The lines connect adjacent pivots — they're not best-fit lines through many touches. This is deliberate: it shows you the slope of the most recent swing, not a line of best fit that may not match what price is actually doing right now.
Inputs
- Timeframes 1/2/3 — defaults: Daily, Weekly, 3-Month. Choose timeframes higher than your chart timeframe.
- Per-TF Pivot Lookback — bars required on each side to confirm a swing, set independently per timeframe. Default 3 each. Higher values capture only major swings.
- Resistance / Support lines per TF — how many trend lines to draw per timeframe per direction. Defaults 2 each. Increase to see more historical structure.
- Display toggles — per-TF, resistance/support, broken lines, pivot anchor markers, right-edge price labels, and timeframe tag in the label. TF3 is off by default because 3-Month pivots confirm very slowly.
- Colors — one per timeframe, plus a separate broken-lines color.
- Line widths — independent per timeframe.
- Extension — Right (default), Both, or None. Controls whether each line extends past its second pivot.
- Line Style — Solid, Dashed, or Dotted (applies to unbroken lines).
Built-in alerts
Six alerts, one per timeframe and direction:
- TF1 / TF2 / TF3 Resistance Break ↑ — close crosses above the most recent unbroken resistance line on that timeframe
- TF1 / TF2 / TF3 Support Break ↓ — close crosses below the most recent unbroken support line on that timeframe
Breaks fire on the bar they occur, based on the line's current projected price.
Notes
The lines connect adjacent pivots only. Some auto-trendline indicators try to fit lines through several swings at once; this one doesn't. The design assumption is that the slope between the two most recent swings is what's currently relevant, and older swings shouldn't be forced onto the same line just because they're nearby. If you want longer trend channels, increase pivot lookback so individual swings represent larger structural moves.
Each timeframe has its own pivot lookback by design. A daily chart and a 3-month chart usually need different sensitivities, and forcing them to share one setting tends to make at least one of them wrong.
Higher-timeframe pivots don't confirm until pivot lookback bars after the actual high or low. On a 3-month timeframe with lookback 3, that's nine months of delay — which is why TF3 is off by default and only worth turning on if you're trading multi-year structure.
When a line breaks, it stays dimmed permanently. There's no un-breaking. If price reclaims the level, that's role reversal: the broken resistance is now informing as historical structure while the most recent unbroken support takes over the active role.
This is a structural tool, not a signal generator. It marks where the recent swing slopes sit and which of those slopes price has already broken.
Five years of work on a trading system left me with dozens of indicators that ultimately didn't earn a place in the final build. They're not failures — they're tools that solved problems I no longer needed solved. So instead of shelving them, I'm publishing the majority of them open-source.
If you're a discretionary trader, take what's useful. If you're a systems builder, the source is yours to dissect, modify, and improve. The best return on five years of work is for it to keep working — for someone.
If you use this script — or part of it — in your own work, please credit the original with a link back to my profile.
Note: these indicators have been updated to Pine Script v6 — some manually, some with AI assistance.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.