OPEN-SOURCE SCRIPT

Structural Flow Decoder [JOAT]

7 220
Structural Flow Decoder [JOAT]

Introduction

The Structural Flow Decoder is an advanced open-source market structure analysis indicator that combines Break of Structure (BOS) detection, Change of Character (CHoCH) identification, nested pattern recognition, and multi-timeframe confluence into a unified structural analysis system. This indicator helps traders identify trend direction, structural shifts, and momentum changes by analyzing how price breaks through swing highs and lows across multiple timeframes.

Unlike basic trend indicators that use moving averages, this system analyzes actual market structure - the sequence of higher highs, higher lows, lower highs, and lower lows that define trends. Break of Structure signals trend continuation, Change of Character signals potential reversals, nested patterns reveal internal structure, and multi-timeframe alignment confirms institutional conviction. The indicator is designed for traders who understand that market structure precedes price and that structural breaks reveal directional intent.

Why This Indicator Exists

This indicator addresses a critical need in technical analysis: the ability to identify trend changes before they're obvious. Market structure analysis reveals when institutions are shifting positioning. By combining multiple structural methodologies, this indicator reveals:

  • Break of Structure (BOS): Price breaks swing high/low in trend direction - confirms continuation and momentum
  • Change of Character (CHoCH): Price breaks swing high/low against trend - signals potential reversal or consolidation
  • Nested Structure: Internal patterns within larger structure - reveals micro-trends and entry timing
  • Multi-Timeframe Confluence: Higher timeframe structure alignment - confirms institutional participation
  • Momentum Shifts: RSI and MACD crossovers at structure breaks - adds confirmation layer
  • Trend Strength Analysis: Quantifies structural conviction - distinguishes strong from weak trends


Each component provides a different lens on market structure. BOS shows continuation, CHoCH shows reversals, nested structure shows timing, MTF alignment shows conviction, and momentum shows acceleration. Together, they create a comprehensive view of structural flow.

syot kilat

Core Components Explained

1. Break of Structure (BOS) Detection

Break of Structure occurs when price breaks a swing high in an uptrend or swing low in a downtrend. It confirms trend continuation:

Pine Script®


The indicator identifies BOS using swing detection:
  • Detects swing highs and lows using pivot lookback (default 5 periods)
  • Compares current swing to previous swing in same direction
  • Draws solid lines connecting swings when BOS occurs
  • Labels breaks with "BOS ↑" or "BOS ↓" for clarity


BOS signals that the trend is intact and institutions are pushing price in the established direction. Multiple consecutive BOS indicate strong trending conditions.

2. Change of Character (CHoCH) Detection

Change of Character occurs when price breaks a swing high in a downtrend or swing low in an uptrend. It signals potential trend reversal:

Pine Script®


CHoCH is more significant than BOS because it represents structural shift:
  • Breaks counter-trend swing points
  • Signals potential trend reversal or major consolidation
  • Drawn with dashed lines to distinguish from BOS
  • Flips internal trend state when detected


CHoCH doesn't guarantee reversal, but it warns that the previous trend is weakening. Confirmation from other factors (volume, momentum, higher timeframe) increases reliability.

3. Nested Structure Analysis

Nested structure reveals internal patterns within the larger trend. It uses shorter lookback periods to detect micro-structure:

The indicator tracks internal swings using a separate period (default 3 bars vs 5 for main structure). This reveals:
  • Internal BOS within larger trends - shows momentum acceleration
  • Internal CHoCH before main CHoCH - early warning of reversals
  • Pullback structure in trends - identifies entry opportunities
  • Consolidation patterns - shows when to wait


Nested structure is drawn with thinner dashed lines to distinguish from main structure. It provides entry timing within the larger trend context.

4. Multi-Timeframe Confluence

The indicator requests structure data from a higher timeframe (default 60-minute) and compares it to current timeframe:

Pine Script®


Multi-timeframe analysis reveals:
  • Whether current timeframe structure aligns with higher timeframe
  • Institutional conviction (HTF structure = larger positions)
  • Confluence zones where both timeframes show same direction
  • Divergence warnings when timeframes conflict


The dashboard displays HTF alignment status (Bullish/Bearish) and confluence state (Synced/Divergent). Trading in direction of HTF structure with current timeframe confirmation produces highest win rates.

5. Momentum Shift Detection

The indicator integrates RSI and MACD to detect momentum shifts at structural breaks:

Pine Script®


Momentum shifts are marked with "M+" (bullish) or "M-" (bearish) labels. When momentum shifts align with structural breaks, it confirms the move. Momentum divergence from structure warns of potential failures.

6. Trend Strength Classification

The indicator quantifies trend strength based on consecutive structural breaks:

  • Explosive: 3+ consecutive BOS in same direction
  • Active: 1-2 consecutive BOS
  • Weak: No recent BOS or mixed signals


Strength classification appears in the dashboard and influences background gradient intensity. Strong trends show vibrant colors, weak trends show muted colors.

syot kilat

Visual Elements

  • BOS Lines: Solid thick lines (cyan for bullish, magenta for bearish)
  • CHoCH Lines: Dashed thick lines (cyan for bullish, magenta for bearish)
  • Internal Structure: Thin dashed lines showing nested patterns
  • Swing Point Labels: "H" and "L" markers at pivot highs/lows
  • Momentum Labels: "M+" and "M-" at momentum shifts
  • Gradient Background: Color intensity based on trend strength
  • Gradient Candles: Strong moves in bright colors, weak moves in muted colors
  • Dashboard: Real-time structure state and confluence metrics


The dashboard displays 8 key metrics:
1. Structure Flow (Bullish/Bearish)
2. Flow Strength (Explosive/Active/Weak)
3. HTF Alignment (Bullish/Bearish/Off)
4. Confluence (Synced/Divergent)
5. Momentum (Strong/Neutral/Weak)
6. MACD Signal (Bullish/Bearish)
7. Last Pivot price level

Input Parameters

Structure Analysis:
  • Detection Period: Swing lookback for main structure (default: 5)
  • Break of Structure: Enable/disable BOS detection
  • Change of Character: Enable/disable CHoCH detection
  • Nested Patterns: Enable/disable internal structure
  • Nested Period: Swing lookback for internal structure (default: 3)
  • Momentum Shifts: Enable/disable RSI/MACD labels


Higher Timeframe:
  • Multi-Timeframe Sync: Enable/disable HTF analysis
  • HTF Period: Higher timeframe to analyze (default: 60 minutes)
  • Confluence Filter: Require HTF alignment for signals


Visualization:
  • Directional Zones: Show gradient backgrounds
  • Pivot Markers: Show H/L labels at swings
  • Strength Histogram: Show trend strength bars


How to Use This Indicator

Step 1: Identify Current Structure
Check the dashboard for Structure Flow. Bullish structure = look for longs, Bearish structure = look for shorts. This is your directional bias.

Step 2: Wait for Structural Confirmation
In bullish structure, wait for BOS (break above swing high) to confirm continuation. In bearish structure, wait for BOS (break below swing low). Don't trade against structure.

Step 3: Watch for Change of Character
CHoCH signals potential reversal. When CHoCH occurs, structure flips. Wait for confirmation BOS in new direction before entering. Don't trade immediately on CHoCH.

Step 4: Use Nested Structure for Timing
Internal structure shows pullback completion. Enter when internal BOS occurs in direction of main structure. This provides precise entry timing.

Step 5: Confirm with Higher Timeframe
Check HTF Alignment in dashboard. "Synced" = both timeframes agree (best setups). "Divergent" = conflict (avoid or reduce size).

Step 6: Add Momentum Confirmation
Look for M+ labels in bullish structure or M- labels in bearish structure. Momentum + Structure = highest probability setups.

Best Practices

  • Trade in direction of structure - don't fight it
  • BOS confirms trend, CHoCH warns of change - respect both
  • Multiple BOS in same direction = strong trend, ride it
  • CHoCH requires confirmation - don't reverse immediately
  • Nested structure provides entries within larger trend
  • HTF alignment is critical - always check confluence
  • Momentum divergence from structure = warning sign
  • Explosive strength = trending conditions, use breakout strategies
  • Weak strength = ranging conditions, use mean reversion
  • Structure works on all timeframes - scale appropriately


Indicator Limitations

  • Structure analysis works best on trending markets with clear swings
  • Choppy, sideways markets produce frequent false CHoCH signals
  • Swing detection requires sufficient volatility - low volatility reduces reliability
  • CHoCH doesn't guarantee reversal - it signals potential change
  • Multiple CHoCH in short period indicates consolidation, not trend
  • HTF data may repaint on lower timeframes - use confirmed bars
  • Nested structure can be noisy in ranging markets
  • The indicator shows structure state, not future direction
  • Momentum shifts can occur without structural confirmation


Technical Implementation

Built with Pine Script v6 using:
  • Pivot-based swing detection with configurable lookback
  • State machine tracking for bullish/bearish structure
  • Nested structure analysis with separate period
  • Multi-timeframe security requests with proper gap handling
  • RSI and MACD momentum calculations
  • Trend strength quantification system
  • Dynamic gradient backgrounds based on strength
  • Real-time dashboard with 8 structural metrics


The code is fully open-source and can be modified to suit individual trading styles and preferences.

Originality Statement

This indicator is original in its comprehensive structural integration approach. While individual components (BOS, CHoCH, swing detection) are established concepts, this indicator is justified because:

  • It synthesizes BOS and CHoCH detection with nested pattern analysis in a unified system
  • The multi-timeframe confluence detection provides institutional conviction measurement
  • Momentum shift integration (RSI + MACD) adds confirmation layer to structural breaks
  • Trend strength quantification distinguishes explosive from weak structural flows
  • Nested structure analysis reveals micro-patterns within macro-trends for entry timing
  • The gradient visualization system shows structural conviction through color intensity
  • Real-time dashboard presents 8 metrics simultaneously for holistic structural analysis


Each component contributes unique information: BOS shows continuation, CHoCH shows reversals, nested structure shows timing, HTF shows conviction, momentum shows acceleration, and strength shows quality. The indicator's value lies in presenting these complementary perspectives simultaneously with unified classification and visual hierarchy.

Disclaimer

This indicator is provided for educational and informational purposes only. It is not financial advice or a recommendation to buy or sell any financial instrument. Trading involves substantial risk of loss and is not suitable for all investors.

Market structure analysis is a tool for understanding price behavior, not a crystal ball for predicting future movement. BOS does not guarantee continuation. CHoCH does not guarantee reversal. Past structural patterns do not guarantee future structural patterns. Market conditions change, and strategies that worked historically may not work in the future.

The structural states displayed are analytical constructs based on current market data, not predictions of future price movement. Structure alignment does not guarantee profitable trades. Users must conduct their own analysis and risk assessment before making trading decisions.

Always use proper risk management, including stop losses and position sizing appropriate for your account size and risk tolerance. Never risk more than you can afford to lose. Consider consulting with a qualified financial advisor before making investment decisions.

The author is not responsible for any losses incurred from using this indicator. Users assume full responsibility for all trading decisions made using this tool.

-Made with passion by officialjackofalltrades

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.