OPEN-SOURCE SCRIPT
Trend Channels Pro [CodedLevels]

Trend Channels Pro [CodedLevels]
A multi-layered trend structure engine that combines regression-based diagonal channels, supply & demand zones, and smart breakout detection into a single unified overlay.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 WHAT IT DOES
This indicator builds a complete structural map of the market by layering three analytical systems:
1 — Trend Channels (Essential + Secondary)
Automatically detects swing pivots and fits linear regression channels across each completed trend leg. Channels are rendered as diagonal lines with shaded fills — visually identical to TradingView's built-in Regression Trend drawing tool, but fully automated. Two independent layers work simultaneously:
• Essential Trend — captures dominant market structure using higher-strength pivots. Channels are colored green (bullish legs) or red (bearish legs) based on structural direction.
• Secondary Trend — captures shorter-term structure within the essential trend. Channels are rendered in grey to visually separate them from the primary structure.
Both layers preserve full historical channels on the chart, giving you a complete visual record of how the trend has evolved over time.
2 — Forming Channel (Live)
A real-time channel drawn from the last confirmed pivot to the current bar. It updates on every new candle, showing you the trend leg that is actively developing — before it becomes a confirmed historical channel. Rendered in a distinct color with dashed lines so you can immediately distinguish it from completed channels.
3 — Supply & Demand Zones
Pivot-based zone detection using candle body mapping. Zones are qualified by departure strength — only pivots with meaningful follow-through moves generate zones. Features include:
• Automatic zone merging when nearby zones overlap
• Freshness tracking: fresh (untested) → retested → weakened → invalidated
• Zones auto-remove when price breaks through with conviction
• Centered labels: SUPPLY / DEMAND with freshness indicators
4 — Smart Breakout Signals
Detects when price closes beyond the latest secondary channel boundary. Includes:
• Minimum penetration filter (in ATR multiples) to eliminate marginal breakouts
• Optional volume confirmation
• Trend alignment filter — only signals that agree with the essential trend direction
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW TREND DIRECTION WORKS
Unlike indicators that determine trend from a moving average or the last candle's slope, this indicator uses structural market analysis:
• Tracks successive pivot highs and pivot lows
• Higher High + Higher Low = Bullish structure
• Lower High + Lower Low = Bearish structure
This means the dashboard won't flip bearish just because price made a normal pullback within an uptrend. It reflects the actual market structure.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW TO USE IT
Essential + Secondary channels give you the structural framework — trade in the direction of the essential trend, use secondary channels for timing.
Supply & Demand zones provide confluence — a breakout signal firing near a fresh demand zone in a bullish essential trend is a high-probability setup.
The info table (top-right) shows: essential and secondary trend direction, alignment status (ALIGNED / DIVERGENT), R² values for channel quality, and zone counts.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERTS
• Bullish / Bearish breakout (with-trend filtered)
• Any secondary channel break (unfiltered)
• Price entering supply or demand zones
• Confluence alerts: breakout + zone overlap
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
All layers can be independently enabled/disabled. Key parameters include swing lookback strength, channel width (standard deviation multiplier), max historical channels, zone merge distance, breakout penetration threshold, and full color customization.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Built for traders who think in terms of market structure, not just indicators.
A multi-layered trend structure engine that combines regression-based diagonal channels, supply & demand zones, and smart breakout detection into a single unified overlay.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 WHAT IT DOES
This indicator builds a complete structural map of the market by layering three analytical systems:
1 — Trend Channels (Essential + Secondary)
Automatically detects swing pivots and fits linear regression channels across each completed trend leg. Channels are rendered as diagonal lines with shaded fills — visually identical to TradingView's built-in Regression Trend drawing tool, but fully automated. Two independent layers work simultaneously:
• Essential Trend — captures dominant market structure using higher-strength pivots. Channels are colored green (bullish legs) or red (bearish legs) based on structural direction.
• Secondary Trend — captures shorter-term structure within the essential trend. Channels are rendered in grey to visually separate them from the primary structure.
Both layers preserve full historical channels on the chart, giving you a complete visual record of how the trend has evolved over time.
2 — Forming Channel (Live)
A real-time channel drawn from the last confirmed pivot to the current bar. It updates on every new candle, showing you the trend leg that is actively developing — before it becomes a confirmed historical channel. Rendered in a distinct color with dashed lines so you can immediately distinguish it from completed channels.
3 — Supply & Demand Zones
Pivot-based zone detection using candle body mapping. Zones are qualified by departure strength — only pivots with meaningful follow-through moves generate zones. Features include:
• Automatic zone merging when nearby zones overlap
• Freshness tracking: fresh (untested) → retested → weakened → invalidated
• Zones auto-remove when price breaks through with conviction
• Centered labels: SUPPLY / DEMAND with freshness indicators
4 — Smart Breakout Signals
Detects when price closes beyond the latest secondary channel boundary. Includes:
• Minimum penetration filter (in ATR multiples) to eliminate marginal breakouts
• Optional volume confirmation
• Trend alignment filter — only signals that agree with the essential trend direction
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW TREND DIRECTION WORKS
Unlike indicators that determine trend from a moving average or the last candle's slope, this indicator uses structural market analysis:
• Tracks successive pivot highs and pivot lows
• Higher High + Higher Low = Bullish structure
• Lower High + Lower Low = Bearish structure
This means the dashboard won't flip bearish just because price made a normal pullback within an uptrend. It reflects the actual market structure.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 HOW TO USE IT
Essential + Secondary channels give you the structural framework — trade in the direction of the essential trend, use secondary channels for timing.
Supply & Demand zones provide confluence — a breakout signal firing near a fresh demand zone in a bullish essential trend is a high-probability setup.
The info table (top-right) shows: essential and secondary trend direction, alignment status (ALIGNED / DIVERGENT), R² values for channel quality, and zone counts.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 ALERTS
• Bullish / Bearish breakout (with-trend filtered)
• Any secondary channel break (unfiltered)
• Price entering supply or demand zones
• Confluence alerts: breakout + zone overlap
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔹 SETTINGS
All layers can be independently enabled/disabled. Key parameters include swing lookback strength, channel width (standard deviation multiplier), max historical channels, zone merge distance, breakout penetration threshold, and full color customization.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Built for traders who think in terms of market structure, not just indicators.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.