OPEN-SOURCE SCRIPT
Structural Pivot Mapper [JOAT]

Structural Pivot Mapper [JOAT]
Introduction
The Structural Pivot Mapper (SPM) is an advanced open-source structural analysis indicator that combines W/M pattern detection, dynamic support/resistance level mapping, pivot point analysis, volume profile integration, and break-retest detection to identify institutional structural pivots and key price levels. This indicator reveals market structure through systematic detection of swing highs/lows, classical chart patterns, and volume-based price levels, providing traders with a comprehensive structural framework for identifying high-probability entry and exit zones.
Unlike basic pivot indicators that simply mark swing points, SPM employs sophisticated pattern recognition algorithms to detect W patterns (bullish reversal), M patterns (bearish reversal), Head & Shoulders formations, and tracks level strength through touch counting and volume analysis. The indicator automatically manages support/resistance levels, removes outdated levels, and highlights Point of Control (POC) from volume profile analysis to show where institutional activity is concentrated.

Why This Indicator Exists
This indicator addresses the challenge of identifying key structural levels where institutional players are likely to defend positions or initiate new trades. Market structure provides the framework for understanding price behavior, and SPM systematically reveals:
Each component provides unique intelligence. W/M patterns show reversal zones, pivots show swing structure, touch counting shows level strength, volume profile shows institutional interest, break-retest confirms level validity, and H&S patterns show major reversals.
Core Components Explained
1. W Pattern Detection (Bullish Reversal)
SPM detects W patterns through systematic analysis of 5 pivot points (A-B-C-D-E):
Pine Script®
W patterns indicate bullish reversal when:
- Price forms double bottom (D and B)
- Middle high (C) is lower than current price (E)
- Second low (B) is higher than or equal to first low (D) in strict mode
- Pattern completes with breakout above middle high (C)
Entry level is at middle high (C), stop loss at second low (B).
2. M Pattern Detection (Bearish Reversal)
M patterns are detected through inverted W logic:
Pine Script®
M patterns indicate bearish reversal when:
- Price forms double top (D and B)
- Middle low (C) is higher than current price (E)
- Second high (B) is lower than or equal to first high (D) in strict mode
- Pattern completes with breakdown below middle low (C)
Entry level is at middle low (C), stop loss at second high (B).
3. Dynamic Support/Resistance Level Management
SPM tracks pivot-based support and resistance levels with automatic management:
Pine Script®
Level strength is calculated through touch counting:
Levels are automatically removed when max_levels is reached and auto_cleanup is enabled.

4. Level Touch Counting & Strength Scoring
SPM tracks how many times price interacts with each level:
Pine Script®
Strength score (0-100) is calculated based on:
Only levels with 2+ touches and strength >60 are displayed to reduce clutter.
5. Volume Profile & Point of Control (POC)
SPM calculates volume profile to identify price levels with maximum trading activity:
Pine Script®
POC represents the price level where most volume traded - typically where institutions have significant positions. Value Area High (VAH) and Value Area Low (VAL) define the range containing 70% of volume.
6. Break & Retest Detection
SPM monitors when price breaks through resistance levels and subsequently retests:
Pine Script®
Successful retests confirm level validity and often provide high-probability entry opportunities.
7. Head & Shoulders Pattern Detection
SPM detects both regular and inverse Head & Shoulders formations:
Pine Script®
H&S patterns are major reversal formations indicating trend exhaustion and potential reversal.
Visual Elements
Input Parameters
Pattern Detection:
Pivot Settings:
Level Management:
Visualization:

How to Use This Indicator
Step 1: Identify Key Structural Levels
Look for blue (support) and pink (resistance) lines. Thicker lines with higher touch counts [3x+] are strongest.
Step 2: Monitor Pattern Formations
Watch dashboard for "W Pattern" (bullish) or "M Pattern" (bearish) status. These indicate potential reversal zones.
Step 3: Check POC Proximity
Yellow POC line shows where maximum volume traded. Price often gravitates toward POC or bounces from it.
Step 4: Wait for Break & Retest
When price breaks resistance and retests (RT label), it confirms level as new support. High-probability long entry.
Step 5: Use Level Strength for Confidence
Levels with 3+ touches are most reliable. Dashboard shows total support/resistance count.
Step 6: Combine with Higher Timeframe Structure
Use SPM on multiple timeframes. Daily/weekly levels are stronger than intraday levels.
Best Practices
Indicator Limitations
Technical Implementation
Built with Pine Script v6 using:
The code is fully open-source and can be modified to suit individual trading styles.
Originality Statement
This indicator is original in its comprehensive structural analysis approach. While pivot detection and pattern recognition are established concepts, this indicator is justified because:
Each component contributes unique information: W/M patterns show reversals, pivots show structure, touch counting shows strength, volume profile shows institutional interest, break-retest confirms validity, H&S shows major reversals, and strength scoring quantifies importance. The indicator's value lies in presenting these complementary perspectives simultaneously with intelligent level management.
Disclaimer
This indicator is provided for educational and informational purposes only. It is not financial advice. Structural levels and patterns do not guarantee price behavior. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always use proper risk management and never risk more than you can afford to lose.
-Made with passion by officialjackofalltrades
Introduction
The Structural Pivot Mapper (SPM) is an advanced open-source structural analysis indicator that combines W/M pattern detection, dynamic support/resistance level mapping, pivot point analysis, volume profile integration, and break-retest detection to identify institutional structural pivots and key price levels. This indicator reveals market structure through systematic detection of swing highs/lows, classical chart patterns, and volume-based price levels, providing traders with a comprehensive structural framework for identifying high-probability entry and exit zones.
Unlike basic pivot indicators that simply mark swing points, SPM employs sophisticated pattern recognition algorithms to detect W patterns (bullish reversal), M patterns (bearish reversal), Head & Shoulders formations, and tracks level strength through touch counting and volume analysis. The indicator automatically manages support/resistance levels, removes outdated levels, and highlights Point of Control (POC) from volume profile analysis to show where institutional activity is concentrated.
Why This Indicator Exists
This indicator addresses the challenge of identifying key structural levels where institutional players are likely to defend positions or initiate new trades. Market structure provides the framework for understanding price behavior, and SPM systematically reveals:
- W/M Pattern Detection: Identifies classical reversal patterns with strict validation rules
- Dynamic Support/Resistance: Tracks pivot-based levels with automatic strength scoring
- Level Touch Counting: Quantifies level importance through historical price interaction
- Volume Profile Integration: Identifies Point of Control (POC) where maximum volume traded
- Break & Retest Detection: Monitors level breaks and subsequent retests for confirmation
- Head & Shoulders Patterns: Detects both regular and inverse H&S formations
- Smart Level Management: Automatically removes weak levels and maintains only strongest
Each component provides unique intelligence. W/M patterns show reversal zones, pivots show swing structure, touch counting shows level strength, volume profile shows institutional interest, break-retest confirms level validity, and H&S patterns show major reversals.
Core Components Explained
1. W Pattern Detection (Bullish Reversal)
SPM detects W patterns through systematic analysis of 5 pivot points (A-B-C-D-E):
f_detect_w_pattern(float src, int lookback, int offset, bool strict) =>
// Find 5 pivot points forming W shape
// E = current, D = first low, C = middle high, B = second low, A = left high
// Validation: E > C, D < E, D < C, B <= D (strict), B < A
found := a > 0 and a != b and c != 0 and d != 0 and
src[e] > src[c] and src[d] < src[e] and src[d] < src[c] and
(src <= src[d] or not strict) and src < src[a]
[found, valueC, valueB, c, b]
W patterns indicate bullish reversal when:
- Price forms double bottom (D and B)
- Middle high (C) is lower than current price (E)
- Second low (B) is higher than or equal to first low (D) in strict mode
- Pattern completes with breakout above middle high (C)
Entry level is at middle high (C), stop loss at second low (B).
2. M Pattern Detection (Bearish Reversal)
M patterns are detected through inverted W logic:
f_detect_m_pattern(float src, int lookback, int offset, bool strict) =>
// Find 5 pivot points forming M shape
// E = current, D = first high, C = middle low, B = second high, A = left low
// Validation: E < C, D > E, D > C, B >= D (strict), B > A
found := a > 0 and a != b and c != 0 and d != 0 and
src[e] < src[c] and src[d] > src[e] and src[d] > src[c] and
(src >= src[d] or not strict) and src > src[a]
[found, valueC, valueB, c, b]
M patterns indicate bearish reversal when:
- Price forms double top (D and B)
- Middle low (C) is higher than current price (E)
- Second high (B) is lower than or equal to first high (D) in strict mode
- Pattern completes with breakdown below middle low (C)
Entry level is at middle low (C), stop loss at second high (B).
3. Dynamic Support/Resistance Level Management
SPM tracks pivot-based support and resistance levels with automatic management:
float pivot_high = ta.pivothigh(high, pivot_left, pivot_right)
float pivot_low = ta.pivotlow(low, pivot_left, pivot_right)
// Store levels in arrays
if not na(pivot_high) and barstate.isconfirmed
if array.size(resistance_levels) < max_levels
array.push(resistance_levels, pivot_high)
array.push(resistance_touches, 1)
else if auto_cleanup
array.shift(resistance_levels) // Remove oldest
array.push(resistance_levels, pivot_high)
Level strength is calculated through touch counting:
- 1 touch: New level (weak)
- 2 touches: Confirmed level (moderate)
- 3+ touches: Strong level (high importance)
Levels are automatically removed when max_levels is reached and auto_cleanup is enabled.
4. Level Touch Counting & Strength Scoring
SPM tracks how many times price interacts with each level:
float zone_size = atr_value * zone_width
if high >= level - zone_size and high <= level + zone_size
array.set(resistance_touches, i, array.get(resistance_touches, i) + 1)
Strength score (0-100) is calculated based on:
- Touch Count (0-40 points): More touches = stronger level (8 points per touch, max 40)
- Age Factor (0-30 points): Older levels = more established (based on level_strength_period)
- Volume Factor (0-30 points): Higher volume at level = more institutional interest
Only levels with 2+ touches and strength >60 are displayed to reduce clutter.
5. Volume Profile & Point of Control (POC)
SPM calculates volume profile to identify price levels with maximum trading activity:
f_volume_profile(int bins, int lookback) =>
float price_range = price_high - price_low
float bin_size = price_range / bins
// Accumulate volume in 20 price bins
for i = 0 to lookback - 1
float bar_price = hlc3
int bin = math.floor((bar_price - price_low) / bin_size)
array.set(vp_volumes, bin, current_vol + bar_vol)
// Find POC (highest volume bin)
float poc_price = array.get(vp_prices, poc_bin)
[poc_price, vah, val, vp_prices, vp_volumes]
POC represents the price level where most volume traded - typically where institutions have significant positions. Value Area High (VAH) and Value Area Low (VAL) define the range containing 70% of volume.
6. Break & Retest Detection
SPM monitors when price breaks through resistance levels and subsequently retests:
// Detect break (close above resistance)
if not was_broken and close > level and close[1] <= level
array.set(level_broken, i, true)
array.set(break_bar_index, i, bar_index)
// Detect retest (price returns to broken level within 3-20 bars)
if was_broken
int break_bar = array.get(break_bar_index, i)
bool is_retest = bar_index - break_bar >= 3 and bar_index - break_bar <= 20
bool touching_level = math.abs(close - level) < atr_value * 0.5
if is_retest and touching_level
label.new(bar_index, level, "RT", color=c_support_strong)
Successful retests confirm level validity and often provide high-probability entry opportunities.
7. Head & Shoulders Pattern Detection
SPM detects both regular and inverse Head & Shoulders formations:
f_detect_head_shoulders(float src, int lookback) =>
// Find 3 pivot highs: left shoulder, head, right shoulder
float ph1 = ta.pivothigh(src, lookback, lookback)
float ph2 = ta.pivothigh(src, lookback, lookback)[lookback]
float ph3 = ta.pivothigh(src, lookback, lookback)[lookback*2]
// Validate: head higher than shoulders, shoulders roughly equal
if ph2 > ph1 and ph2 > ph3 and math.abs(ph1 - ph3) < (ph2 - ph1) * 0.3
found := true
neckline := math.min(low[lookback], low[lookback*2])
[found, left_shoulder, head, right_shoulder, neckline]
H&S patterns are major reversal formations indicating trend exhaustion and potential reversal.
Visual Elements
- Support Lines: Blue horizontal lines with strength-based width (2-3px)
- Resistance Lines: Pink horizontal lines with strength-based width (2-3px)
- Level Labels: "S: price [Nx]" for support, "R: price [Nx]" for resistance (N = touch count)
- Pivot Markers: Small circles at swing highs (pink) and lows (blue)
- POC Line: Yellow dotted line showing Point of Control from volume profile
- Retest Markers: "RT" labels when price retests broken levels
- Pattern Lines: Optional dashed lines showing W/M pattern structure (disabled by default)
- Dashboard: Real-time metrics showing resistance count, support count, pattern status, POC price
Input Parameters
Pattern Detection:
- Pattern Range: Lookback period for W/M detection (default: 9)
- Pattern Offset: Additional bars to check (default: 0)
- Strict Pattern Validation: Enforce stricter pattern rules (default: false)
Pivot Settings:
- Pivot Left Bars: Bars to left of pivot (default: 6)
- Pivot Right Bars: Bars to right of pivot (default: 1)
- Show Pivot Labels: Toggle pivot markers (default: true)
Level Management:
- Maximum Levels: Max support/resistance levels to track (default: 3)
- Level Strength Period: Lookback for strength calculation (default: 50)
- Auto-Cleanup Old Levels: Remove oldest when max reached (default: true)
Visualization:
- Show Support/Resistance Zones: Toggle level display (default: true)
- Zone Width (ATR %): Width of level zones (default: 0.5)
- Show Pattern Lines: Toggle W/M pattern visualization (default: false)
How to Use This Indicator
Step 1: Identify Key Structural Levels
Look for blue (support) and pink (resistance) lines. Thicker lines with higher touch counts [3x+] are strongest.
Step 2: Monitor Pattern Formations
Watch dashboard for "W Pattern" (bullish) or "M Pattern" (bearish) status. These indicate potential reversal zones.
Step 3: Check POC Proximity
Yellow POC line shows where maximum volume traded. Price often gravitates toward POC or bounces from it.
Step 4: Wait for Break & Retest
When price breaks resistance and retests (RT label), it confirms level as new support. High-probability long entry.
Step 5: Use Level Strength for Confidence
Levels with 3+ touches are most reliable. Dashboard shows total support/resistance count.
Step 6: Combine with Higher Timeframe Structure
Use SPM on multiple timeframes. Daily/weekly levels are stronger than intraday levels.
Best Practices
- Focus on levels with 3+ touches - these have proven institutional interest
- W/M patterns work best at major support/resistance levels
- POC acts as magnet - price often returns to POC after deviating
- Break-retest setups have highest win rate when combined with volume confirmation
- Disable pattern lines to reduce chart clutter - use dashboard for pattern status
- Adjust zone width based on instrument volatility (higher ATR = wider zones)
- Auto-cleanup keeps chart clean but may remove valid older levels
- H&S patterns are most reliable on higher timeframes (4H+)
- Level strength score >70 indicates institutional-grade level
- Smart spacing prevents overlapping levels - only strongest levels shown
Indicator Limitations
- Pattern detection requires sufficient historical data and clear pivot formation
- W/M patterns can produce false signals during strong trends
- Level touch counting is historical - doesn't predict future touches
- Volume profile requires consistent volume data - may not work on illiquid instruments
- Break-retest detection has time window (3-20 bars) - may miss delayed retests
- Maximum level limit means some valid levels may be removed
- Pivot detection lags by pivot_right bars - not real-time
- H&S patterns are rare and require specific market conditions
- Level strength scoring is multi-factor but still subjective
- Smart spacing may hide valid levels that are too close to stronger levels
Technical Implementation
Built with Pine Script v6 using:
- Custom W/M pattern detection with 5-point validation
- Pivot-based support/resistance tracking with arrays
- Touch counting system with ATR-based zone detection
- Multi-factor level strength scoring (touches + age + volume)
- Volume profile calculation with 20-bin price distribution
- POC detection through maximum volume identification
- Break-retest monitoring with time window validation
- Head & Shoulders pattern detection (regular and inverse)
- Smart level spacing to prevent overlapping (1.5 ATR minimum)
- Automatic level cleanup when maximum reached
- Dynamic line and label management to prevent memory issues
- Real-time dashboard with 4 key metrics
The code is fully open-source and can be modified to suit individual trading styles.
Originality Statement
This indicator is original in its comprehensive structural analysis approach. While pivot detection and pattern recognition are established concepts, this indicator is justified because:
- It combines W/M pattern detection with dynamic support/resistance management in a unified system
- The multi-factor level strength scoring (touches + age + volume) provides quantitative level assessment
- Volume profile integration with POC detection adds institutional perspective to structural analysis
- Break-retest detection with time window validation automates a manual trading technique
- Smart level spacing prevents chart clutter while maintaining strongest levels
- Head & Shoulders detection (both regular and inverse) adds major reversal pattern recognition
- Automatic level cleanup maintains chart readability without manual intervention
- Integration of classical patterns (W/M, H&S) with modern volume analysis creates layered confirmation
Each component contributes unique information: W/M patterns show reversals, pivots show structure, touch counting shows strength, volume profile shows institutional interest, break-retest confirms validity, H&S shows major reversals, and strength scoring quantifies importance. The indicator's value lies in presenting these complementary perspectives simultaneously with intelligent level management.
Disclaimer
This indicator is provided for educational and informational purposes only. It is not financial advice. Structural levels and patterns do not guarantee price behavior. Trading involves substantial risk of loss. Past performance does not guarantee future results. Always use proper risk management and never risk more than you can afford to lose.
-Made with passion by officialjackofalltrades
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
The AI Trading Ecosystem, Built to win trades 📈
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
The AI Trading Ecosystem, Built to win trades 📈
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.