OPEN-SOURCE SCRIPT
Auto Trendlines & Market Structure - MTF

Auto Trendlines & Market Structure - MTF
Auto Trendlines & Market Structure - MTF is a visual analytical indicator that automatically draws support and resistance trendlines through swing pivots and classifies the resulting structure into one of seven states: Uptrend, Downtrend, Expanding, Contracting, Range, HH Trending, or LL Trending. A compact panel in the top-right shows how that classification compares across the current chart timeframe and three higher timeframes.
The goal is to remove the subjectivity of manual trendline drawing while keeping the chart readable: only the two currently relevant lines (one from recent pivot highs, one from recent pivot lows) are drawn as active, while older invalidated lines fade into a dashed historical layer for context.
This is a visual analytical tool intended for chart reading and structure mapping. It does not execute trades and does not provide financial advice.
Key Features
Core Concept
Most automatic trendline scripts simply connect the two most recent pivots and call it a trendline. This produces noisy output in choppy markets and resists no contradiction from older swings. This indicator adds three layers on top of that base.
1. Pivot Validation. Before a candidate trendline becomes active, it is checked against up to four older pivots in the same direction. If any of them sits more than 0.3 ATR above a resistance line (or below a support line), the candidate is rejected. This filters out lines that look correct on the latest two pivots but conflict with established structure.
2. ATR-Normalized Slope. Slope is stored not in raw price-per-bar units but in ATR-per-bar units. This makes slope comparable across instruments and timeframes: a normalized slope of 0.1 means roughly one-tenth of an ATR per bar regardless of whether the chart is EURUSD on 15m or BTCUSD on 4H. Strength buckets (Weak / Moderate / Strong / Very Strong) are then defined on this normalized scale.
3. Seven-Class Structure Classification. Instead of collapsing everything into "up or down", the indicator combines the slope sign of both lines:
This classification surfaces structural states that a single trend label cannot describe — particularly Expanding and Contracting, which often precede volatility expansions or breakouts.
Trendline Lifecycle
Each line goes through a defined lifecycle:
The historical trail is capped at 80 frozen lines (FIFO) so the chart does not accumulate clutter on long histories.
Multi-Timeframe Panel
A compact panel in the top-right corner displays the current trend classification across the current timeframe and three higher timeframes. The three HTFs are selected automatically from the standard ladder (1m, 5m, 15m, 1H, 4H, 1D, 1W, 1M, 3M, 12M) based on the active chart timeframe — for example, on a 1H chart the panel shows 4H, 1D, 1W.
Each row shows:
The panel also shows the current chart's HH and LL line levels and the absolute and percentage channel width when both lines are active. HTF data is pulled with non-repainting parameters so the panel stays consistent on confirmed bars.
Typical Analysis Workflow
A common analytical workflow may include:
Configuration
Pivot Lookback Mode — Adaptive (default) scales the pivot length with ATR-relative volatility (between 5 and 10 bars on each side). Fixed lets you set a single lookback between 3 and 15 bars.
Show Trend Lines — Toggles the active two-layer neon trendlines.
Show Channel Fill — Fills the area between active lines with a gradient. Only rendered when both lines are active and the structure is Uptrend, Downtrend, or Range (skipped during Expanding and Contracting to avoid visual confusion).
Show MTF Panel — Toggles the multi-timeframe panel.
Show Pivot Markers — Triangle markers at the most recent pivots, capped at 6 to avoid clutter.
Show Trend Status — Large class badge above price.
Show Line Labels — "HH" and "LL" anchor markers at the right end of each active line.
Line Width (Core) — Width of the inner core line. The outer glow is always rendered at core + 7.
Markets and Timeframes
The indicator can be applied across multiple markets and timeframes:
Because slope is ATR-normalized and pivot lookback is volatility-adaptive, the visual behavior remains consistent across instruments and timeframes without manual re-tuning.
Alerts
Three alert conditions are available:
All alerts evaluate on confirmed bars to avoid intra-bar oscillation.
Notes on Repainting
Active trendlines are anchored to confirmed pivot highs and pivot lows, which are themselves only validated after a pivot lookback window has fully passed. Once an active line is drawn its anchor points do not move. The MTF panel uses confirmed higher-timeframe values with a one-bar offset, so its readings stay consistent across historical and realtime bars. Alerts trigger only on confirmed bars.
Important Notes
This indicator is an analytical visualization tool. It does not execute trades and does not provide financial advice. All outputs are informational and should be interpreted within the context of independent market analysis and proper risk management.
Past behavior of any technical indicator does not guarantee future results.
If you find this indicator useful, feel free to add it to your favorites and share your feedback in the comments. Community feedback helps improve future updates.
Auto Trendlines & Market Structure - MTF is a visual analytical indicator that automatically draws support and resistance trendlines through swing pivots and classifies the resulting structure into one of seven states: Uptrend, Downtrend, Expanding, Contracting, Range, HH Trending, or LL Trending. A compact panel in the top-right shows how that classification compares across the current chart timeframe and three higher timeframes.
The goal is to remove the subjectivity of manual trendline drawing while keeping the chart readable: only the two currently relevant lines (one from recent pivot highs, one from recent pivot lows) are drawn as active, while older invalidated lines fade into a dashed historical layer for context.
This is a visual analytical tool intended for chart reading and structure mapping. It does not execute trades and does not provide financial advice.
Key Features
- Auto-detected trendlines through the two most recent valid pivot highs (resistance) and pivot lows (support)
- Adaptive pivot lookback that scales with ATR-relative volatility, with optional fixed-length mode
- Seven-class structure classification rather than a binary up/down trend
- Multi-timeframe panel scanning the current TF plus three higher TFs
- Validation logic that rejects lines penetrated by older pivots beyond an ATR-based tolerance
- Historical line trail (dashed) preserved when an active trendline gets broken or replaced
- Two-layer neon line rendering and gradient channel fill scaled by ATR
Core Concept
Most automatic trendline scripts simply connect the two most recent pivots and call it a trendline. This produces noisy output in choppy markets and resists no contradiction from older swings. This indicator adds three layers on top of that base.
1. Pivot Validation. Before a candidate trendline becomes active, it is checked against up to four older pivots in the same direction. If any of them sits more than 0.3 ATR above a resistance line (or below a support line), the candidate is rejected. This filters out lines that look correct on the latest two pivots but conflict with established structure.
2. ATR-Normalized Slope. Slope is stored not in raw price-per-bar units but in ATR-per-bar units. This makes slope comparable across instruments and timeframes: a normalized slope of 0.1 means roughly one-tenth of an ATR per bar regardless of whether the chart is EURUSD on 15m or BTCUSD on 4H. Strength buckets (Weak / Moderate / Strong / Very Strong) are then defined on this normalized scale.
3. Seven-Class Structure Classification. Instead of collapsing everything into "up or down", the indicator combines the slope sign of both lines:
- Both up — Uptrend
- Both down — Downtrend
- Resistance up, support down — Expanding (broadening)
- Resistance down, support up — Contracting (converging)
- Both flat within threshold — Range
- Only support active — LL Trending (one-sided structure)
- Only resistance active — HH Trending (one-sided structure)
This classification surfaces structural states that a single trend label cannot describe — particularly Expanding and Contracting, which often precede volatility expansions or breakouts.
Trendline Lifecycle
Each line goes through a defined lifecycle:
- Built from the two newest valid pivots in its direction
- Projected to the right and rendered with a colored core plus a wider transparent glow
- Replaced when a newer pivot pair forms a more recent line — the previous line is then frozen as a dashed historical reference
- Invalidated when price closes more than 0.5 ATR beyond the line — at that moment the line stops projecting, freezes at the breakpoint, and a break alert can fire
The historical trail is capped at 80 frozen lines (FIFO) so the chart does not accumulate clutter on long histories.
Multi-Timeframe Panel
A compact panel in the top-right corner displays the current trend classification across the current timeframe and three higher timeframes. The three HTFs are selected automatically from the standard ladder (1m, 5m, 15m, 1H, 4H, 1D, 1W, 1M, 3M, 12M) based on the active chart timeframe — for example, on a 1H chart the panel shows 4H, 1D, 1W.
Each row shows:
- Timeframe label
- Block-bar strength gauge
- Class name (Uptrend / Downtrend / Expanding / Contracting / Range / HH Trending / LL Trending / Building)
- Strength tier (Weak / Moderate / Strong / Very Strong)
The panel also shows the current chart's HH and LL line levels and the absolute and percentage channel width when both lines are active. HTF data is pulled with non-repainting parameters so the panel stays consistent on confirmed bars.
Typical Analysis Workflow
A common analytical workflow may include:
- Reading the structure class on the chart timeframe to understand the immediate state
- Comparing it to the three higher timeframes in the panel to detect alignment or conflict
- Watching the channel width as the structure transitions between Expanding, Contracting, and Range
- Using line breaks and the dashed historical trail to time potential structure shifts
- Combining the structure read with other forms of analysis and risk management
Configuration
Pivot Lookback Mode — Adaptive (default) scales the pivot length with ATR-relative volatility (between 5 and 10 bars on each side). Fixed lets you set a single lookback between 3 and 15 bars.
Show Trend Lines — Toggles the active two-layer neon trendlines.
Show Channel Fill — Fills the area between active lines with a gradient. Only rendered when both lines are active and the structure is Uptrend, Downtrend, or Range (skipped during Expanding and Contracting to avoid visual confusion).
Show MTF Panel — Toggles the multi-timeframe panel.
Show Pivot Markers — Triangle markers at the most recent pivots, capped at 6 to avoid clutter.
Show Trend Status — Large class badge above price.
Show Line Labels — "HH" and "LL" anchor markers at the right end of each active line.
Line Width (Core) — Width of the inner core line. The outer glow is always rendered at core + 7.
Markets and Timeframes
The indicator can be applied across multiple markets and timeframes:
- Forex
- Stocks and Indices
- Commodities
- Cryptocurrencies
Because slope is ATR-normalized and pivot lookback is volatility-adaptive, the visual behavior remains consistent across instruments and timeframes without manual re-tuning.
Alerts
Three alert conditions are available:
- Trend Class Changed — fires when the structure classification transitions between any of the seven states
- Resistance Break — fires when price closes more than 0.5 ATR above the active resistance line
- Support Break — fires when price closes more than 0.5 ATR below the active support line
All alerts evaluate on confirmed bars to avoid intra-bar oscillation.
Notes on Repainting
Active trendlines are anchored to confirmed pivot highs and pivot lows, which are themselves only validated after a pivot lookback window has fully passed. Once an active line is drawn its anchor points do not move. The MTF panel uses confirmed higher-timeframe values with a one-bar offset, so its readings stay consistent across historical and realtime bars. Alerts trigger only on confirmed bars.
Important Notes
This indicator is an analytical visualization tool. It does not execute trades and does not provide financial advice. All outputs are informational and should be interpreted within the context of independent market analysis and proper risk management.
Past behavior of any technical indicator does not guarantee future results.
If you find this indicator useful, feel free to add it to your favorites and share your feedback in the comments. Community feedback helps improve future updates.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
📊 MQLSoftware — Premium TradingView indicators
🎯 Featured: Pro Swing Trading System | DisruptNEX Edge System
🌐 mqlsoftware.info
For educational purposes only.
🎯 Featured: Pro Swing Trading System | DisruptNEX Edge System
🌐 mqlsoftware.info
For educational purposes only.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Skrip open-source
Dengan semangat TradingView yang sesungguhnya, pembuat skrip ini telah menjadikannya sebagai sumber terbuka, sehingga para trader dapat meninjau dan memverifikasi fungsinya. Salut untuk penulisnya! Meskipun Anda dapat menggunakannya secara gratis, perlu diingat bahwa penerbitan ulang kode ini tunduk pada Tata Tertib kami.
📊 MQLSoftware — Premium TradingView indicators
🎯 Featured: Pro Swing Trading System | DisruptNEX Edge System
🌐 mqlsoftware.info
For educational purposes only.
🎯 Featured: Pro Swing Trading System | DisruptNEX Edge System
🌐 mqlsoftware.info
For educational purposes only.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.