OPEN-SOURCE SCRIPT

Market Structure MTF [HH/HL/LH/LL + CHoCH + BOS]

2 280
Automatic market structure detection with pivot classification (HH/HL/LH/LL), Change of Character (CHoCH) and Break of Structure (BOS) signals. Multi-timeframe support allows overlaying higher timeframe structure on any chart.

█ OVERVIEW

This indicator automatically detects and classifies pivot points to visualize market structure. It identifies trend direction through the sequence of highs and lows, and signals potential reversals through Change of Character (CHoCH) and trend continuation through Break of Structure (BOS).

█ CONCEPTS

Market structure analysis is based on the relationship between consecutive pivot points:

Bullish Structure:
• HH (Higher High): A swing high that exceeds the previous swing high
• HL (Higher Low): A swing low that stays above the previous swing low
• Sequence: HH → HL → HH → HL confirms uptrend

Bearish Structure:
• LH (Lower High): A swing high that fails to exceed the previous swing high
• LL (Lower Low): A swing low that breaks below the previous swing low
• Sequence: LH → LL → LH → LL confirms downtrend

Structure Shifts:
• CHoCH (Change of Character): Signals when the expected sequence breaks, suggesting potential trend reversal
• BOS (Break of Structure): Confirms trend continuation when price breaks a pivot level in trend direction

█ FEATURES

• Automatic pivot detection using configurable lookback period
• Smart classification comparing each pivot to its predecessor
• CHoCH detection when trend sequence is violated
• BOS signals with anti-repetition filter to reduce noise in consolidation zones
• Multi-Timeframe (MTF) support to display higher timeframe structure
• Horizontal dashed lines marking HTF pivot levels
• Clean visual output with color-coded labels

█ SETTINGS

Structure Settings:
• Pivot Length: Number of bars on each side required to confirm a pivot (default: 5)
- Lower values (2-3) = more sensitive, detects minor swings
- Higher values (10-20) = less sensitive, only major structure

Multi-Timeframe:
• Show HTF Structure: Enable/disable higher timeframe overlay
• HTF Timeframe: Select the higher timeframe to display (D, W, M, etc.)

Visualization:
• Show Local Structure: Toggle visibility of current timeframe pivots

Filters:
• BOS Buffer: Minimum bars between BOS signals to avoid repetition

█ HOW TO USE

The indicator offers three visualization modes:

1. LOCAL STRUCTURE ONLY (default)
├─ Show Local Structure: ✓ Enabled
├─ Show HTF Structure: ✗ Disabled
└─ Use case: Analyze structure on the current timeframe only

2. HIGHER TIMEFRAME ONLY (recommended for clarity)
├─ Show Local Structure: ✗ Disabled
├─ Show HTF Structure: ✓ Enabled
├─ HTF Timeframe: Select desired TF (D, W, M)
└─ Use case: View higher TF context on lower TF charts without clutter

3. BOTH TIMEFRAMES (advanced)
├─ Show Local Structure: ✓ Enabled
├─ Show HTF Structure: ✓ Enabled
└─ Use case: See confluence between timeframes
⚠️ WARNING: This mode can make the chart visually crowded.
Recommended only for experienced users who need both layers simultaneously.

█ RECOMMENDED SETTINGS BY TIMEFRAME

| Chart TF | Pivot Length | Suggested HTF |
|----------|--------------|---------------|
| 1H | 10-15 | 4H or D |
| 4H | 5-10 | D or W |
| 1D | 5-7 | W |
| 1W | 3-5 | M |

The goal is to make pivots on lower timeframes represent equivalent time context.

█ VISUAL REFERENCE

Local Structure Labels:
• 🟩 Green (above): HH - Higher High
• 🟥 Red (above): LH - Lower High
• 🟩 Green (below): HL - Higher Low
• 🟥 Red (below): LL - Lower Low
• 🟧 Orange: CHoCH - Change of Character
• 🟦 Blue: BOS - Break of Structure

HTF Structure Labels:
• 🩵 Teal: HH/HL - Bullish HTF structure
• 🟫 Maroon: LH/LL - Bearish HTF structure
• 🟨 Yellow: CHoCH - HTF trend shift
• 🟦 Navy: BOS - HTF structure break
• ┈┈ Dashed lines mark HTF pivot price levels

█ INTERPRETATION GUIDELINES

Reading the sequence:
• Consistent HH + HL = Bullish bias, look for long opportunities
• Consistent LH + LL = Bearish bias, look for short opportunities
• CHoCH after trending sequence = Potential reversal, exercise caution
• BOS in trend direction = Trend continuation confirmed

Combining timeframes:
• HTF structure defines the primary bias
• Local structure provides entry timing
• Confluence (both TFs aligned) = Higher probability setups

█ LIMITATIONS

• Pivots are confirmed with a delay equal to the Pivot Length parameter
• In ranging markets, multiple CHoCH signals may appear (this is correct behavior - the market IS changing direction frequently)
• CHoCH signals potential reversal, not guaranteed reversal
• Works best on liquid markets with clean price action

█ TECHNICAL NOTES

• Uses ta.pivothigh() and ta.pivotlow() for pivot detection
• request.security() fetches higher timeframe data
• Anti-repetition logic prevents BOS signal clustering in consolidation
• All crossover/crossunder calculations are performed at global scope for consistency (Pine Script v6 compliance)

█ CREDITS

Developed for swing traders and position traders who use market structure for trend analysis and trade timing.

Feedback and suggestions are welcome.

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.