OPEN-SOURCE SCRIPT

Pinnacle Structure Cipher [JOAT]

1 393
Pinnacle Structure Cipher [JOAT]

Introduction

The Pinnacle Structure Cipher is an open-source market structure analysis indicator built in Pine Script v6. It detects and visualizes the core building blocks of institutional price action: swing highs and lows, Break of Structure (BOS), Change of Character (CHoCH), Fair Value Gaps (FVG), Order Blocks (OB), displacement candles, Equal Highs/Lows (EQH/EQL), and Premium/Discount zones. Rather than stacking separate indicators for each concept, this tool unifies them into a single coherent overlay with a shared structure engine, consistent visual language, and a real-time HUD dashboard.

The indicator is designed for traders who study how price builds and breaks structure, where institutional footprints appear in the form of imbalances and reaction zones, and how to identify high-probability areas where price is likely to react. Every signal is gated behind confirmed bar close logic to prevent repainting.

snapshot

Why This Indicator Exists

Most retail traders use separate tools for structure detection, FVG mapping, and order block identification. The problem is that these concepts are deeply interconnected. A Break of Structure only matters in the context of the swing it broke. A Fair Value Gap is most relevant when it forms during a displacement candle that also created an Order Block. Equal Highs become significant when they sit at the boundary of a Premium zone.

This indicator solves that fragmentation by running all concepts through a single structure engine:

  • Swing Tracking: Pivot-based swing high/low detection with configurable lookback, tracking the last two swings on each side for pattern recognition (higher highs, lower lows, etc.)
  • BOS/CHoCH Detection: Structural breaks are classified as continuation (BOS) when price breaks a swing in the current trend direction, or reversal (CHoCH) when price breaks against the trend. This distinction is critical for understanding whether the market is continuing or shifting character.
  • Fair Value Gaps: Three-candle imbalances where a gap exists between candle 1's high and candle 3's low (bullish) or candle 1's low and candle 3's high (bearish). Gaps are filtered by a minimum ATR-based size threshold to eliminate noise. The indicator tracks whether each FVG has been filled by subsequent price action.
  • Order Blocks: The last opposing candle before a strong directional move, confirmed by volume exceeding the 20-bar average. OB zones are drawn as boxes and tracked for mitigation when price returns to the zone.
  • Displacement Candles: Large-body candles (body >= 70% of range, body >= 1.8x the 20-bar average body) that indicate aggressive institutional order flow. These often coincide with the creation of FVGs and OBs.
  • EQH/EQL Detection: When two consecutive swing highs or lows are within an ATR-based tolerance of each other, the indicator identifies them as Equal Highs or Equal Lows — key liquidity targets where stop orders tend to cluster. These are drawn as dashed lines and automatically removed when swept.
  • Premium/Discount Zones: The range between the last swing high and swing low is divided at the equilibrium (50%) level. The upper half is labeled Premium (where sellers have an edge), the lower half is Discount (where buyers have an edge). An equilibrium line marks the midpoint.


How the Structure Engine Works

The core of this indicator is a swing-based structure tracking system. Here is how swing detection feeds into BOS/CHoCH classification:

Pine Script®
// Pivot-based swing detection float swH = ta.pivothigh(high, i_swingLen, i_swingLen) float swL = ta.pivotlow(low, i_swingLen, i_swingLen) // Track last two swings for pattern recognition if not na(swH) prevSH := lastSH lastSH := swH if not na(swL) prevSL := lastSL lastSL := swL


The indicator maintains a structural trend variable. When price closes above the last swing high in a bullish or neutral structure, that is a BOS Long (trend continuation). When price closes below the last swing low while the structure was bullish, that is a CHoCH Short (character change — potential reversal). This classification helps traders distinguish between moves that confirm the existing trend and moves that signal a shift.

Fair Value Gap Mechanics

FVGs represent price inefficiencies — areas where the market moved so aggressively that it left a gap in the price ladder. The indicator detects these using the classic three-candle pattern:

  • Bullish FVG: Current candle's low is above the high of two candles ago, creating a gap. The directional candle in the middle must be bullish.
  • Bearish FVG: Current candle's high is below the low of two candles ago. The middle candle must be bearish.
  • Size Filter: The gap must be at least a configurable multiple of ATR (default 0.3x) to filter out insignificant micro-gaps.
  • Fill Tracking: When price returns to close the gap (low touches the bottom of a bullish FVG, or high touches the top of a bearish FVG), the box is visually faded to indicate mitigation.
  • Cleanup: Oldest FVGs are automatically removed when the maximum count is exceeded, keeping the chart clean.


Order Block Detection

Order Blocks are identified as the last opposing candle before a strong move. The detection logic requires:

  • A bearish candle followed by a bullish candle that closes above the bearish candle's high (bullish OB), or vice versa
  • The engulfing move must be proportional — the bullish candle's body must exceed the bearish candle's body multiplied by a configurable factor
  • Volume on the signal candle must exceed the 20-bar average volume, confirming institutional participation
  • Mitigation is tracked: when price returns to the OB zone after at least 3 bars, the box is faded and its border becomes dashed


Institutional Signal Detection

Beyond structure and zones, the indicator detects several institutional candle patterns and order flow signals:

  • Volume-Confirmed Engulfing: Classic engulfing patterns where the engulfing candle's body exceeds the prior candle's body and volume is above average
  • Wyckoff Spring/Upthrust: Price sweeps below a swing low (Spring) or above a swing high (Upthrust) and closes back inside, with high volume — classic accumulation/distribution signals
  • Absorption: High volume with small range (Effort vs Result from Wyckoff theory) — indicates institutional absorption where large orders are being filled without moving price
  • CVD Divergence: When Cumulative Volume Delta diverges from price (price makes new high but CVD does not), suggesting hidden distribution or accumulation
  • Delta Surge: When the buy/sell volume ratio exceeds 40% in either direction, indicating strong directional conviction


All signals use a priority-based cooldown system to prevent label stacking. Higher-priority signals (liquidity grabs, springs) suppress lower-priority ones (engulfing, delta) within a configurable cooldown window.

Visual Design

The indicator uses an "Emerald Matrix" color theme — a cohesive palette built around matrix greens, jade, mint, amber warnings, and cyan highlights on a dark background:

  • FVG Boxes: Dotted-border boxes in jade (bullish) or red (bearish) with high transparency. Filled FVGs fade to grey.
  • OB Boxes: Solid-border boxes in cyan (bullish) or red (bearish) with "OB" text labels. Mitigated OBs become dashed grey.
  • BOS/CHoCH Labels: Small labels at the break level with dashed reference lines extending forward
  • EQH/EQL Lines: Dashed lines at equal high/low levels that auto-extend and auto-delete when swept
  • Premium/Discount Zones: Very subtle background shading (94% transparency) with text labels and a dotted equilibrium line
  • Displacement Markers: Small circles below (bullish) or above (bearish) displacement candles
  • Candle Coloring: Multi-factor coloring based on displacement > structure trend > neutral


snapshot

HUD Dashboard

A real-time table displays 16 metrics including:

  • Current regime state and structural trend direction
  • SMA alignment (20/50/200) and RSI value
  • Structure score (0-100) computed from trend state, swing patterns, active FVG/OB count, volume, alignment, and delta
  • Volume ratio and delta flow direction
  • Imbalance pressure classification
  • Wyckoff Effort/Result ratio
  • VWAP band position and volatility state
  • Active FVG and OB counts
  • Current swing high and low levels
  • Weighted institutional bias (BULL/BEAR/NEUTRAL) computed from all active signals


Input Parameters

Structure:
  • Swing Lookback: Pivot detection length (default: 5)
  • Confirmed Bars Only: Toggle to gate all signals behind bar close confirmation
  • Sensitivity: 1 (loose) to 3 (tight) — adjusts detection thresholds across all modules


Fair Value Gaps:
  • Show FVGs: Toggle visibility
  • Max FVG Zones: Maximum tracked (default: 10)
  • Track FVG Fill: Enable/disable fill detection
  • Min FVG Size: Minimum gap as ATR multiple (default: 0.3x)


Order Blocks:
  • Show OBs: Toggle visibility
  • Max OB Zones: Maximum tracked (default: 8)
  • OB Body Multiplier: Minimum engulfing ratio (default: 1.5x)


Advanced:
  • Show EQH/EQL: Equal highs/lows detection
  • EQ Tolerance: ATR-based tolerance for "equal" classification (default: 0.3x)
  • Show Premium/Discount Zones
  • Show Swing Level Lines
  • Show Displacement Markers
  • Show Institutional Signals with configurable cooldown
  • Bar Coloring toggle
  • HUD Panel toggle


How to Use This Indicator

Step 1: Identify the Structural Trend
Check the HUD for the current structure direction (Bullish/Bearish/Neutral). Look at the swing pattern — are you seeing higher highs and higher lows, or lower highs and lower lows?

Step 2: Watch for BOS or CHoCH
A BOS confirms the trend is continuing. A CHoCH warns that the trend may be reversing. CHoCH signals are particularly valuable when they occur at Premium/Discount zone boundaries.

Step 3: Identify Reaction Zones
Look for unfilled FVGs and unmitigated OBs in the direction of the structural trend. These are areas where price is likely to react. A bullish FVG in a bullish structure is a potential long entry zone.

Step 4: Confirm with Institutional Signals
Wait for confirmation signals like displacement candles, volume-confirmed engulfing patterns, or Wyckoff springs/upthrusts at your identified zones.

Step 5: Use EQH/EQL as Targets
Equal Highs and Equal Lows represent liquidity pools. In a bullish structure, EQH levels above price are likely targets. In a bearish structure, EQL levels below are targets.

Best Practices

  • Use on liquid instruments where volume data is meaningful (major forex pairs, large-cap stocks, crypto majors)
  • Higher timeframes (15m+) produce more reliable structure signals than very low timeframes
  • FVGs and OBs are most significant when they form during displacement candles
  • Not all BOS signals are equal — BOS with high volume and displacement carries more weight than a quiet break
  • CHoCH at Premium/Discount boundaries is a higher-probability reversal signal
  • The structure score in the HUD provides a quick read on overall market conviction — scores above 70 suggest strong directional conditions
  • Use the sensitivity input to adjust for different instruments — volatile instruments may need lower sensitivity


Limitations

  • Swing detection has an inherent delay equal to the lookback period — pivots are confirmed only after the right-side bars have formed
  • Volume-based filters (OB confirmation, delta, absorption) require reliable volume data. Instruments with poor volume reporting will produce less reliable signals
  • FVG and OB zones are probabilistic reaction areas, not guaranteed reversal points. Price can and does blow through zones
  • The buy/sell volume split is estimated from candle structure (close vs open), which is an approximation of true order flow
  • During low-liquidity periods (overnight, holidays), structure signals may be less reliable
  • The indicator works best when used as part of a broader analysis framework, not as a standalone entry system


Technical Implementation

Built with Pine Script v6 using:
  • All ta.* function calls at global scope for Pine v6 compliance
  • Array-based zone tracking with parallel arrays for FVG and OB properties
  • Automatic cleanup: oldest zones are deleted when max count is exceeded
  • barstate.isconfirmed gating on all signal generation to prevent repainting
  • request.security() with lookahead=barmerge.lookahead_off for prior day/week levels
  • Priority-based signal cooldown system to prevent visual clutter
  • Pre-computed boolean conditions with deferred drawing for performance
  • 14 alert conditions covering BOS, CHoCH, liquidity grabs, springs, absorption, delta surges, displacement, and regime changes


Originality Statement

This indicator is original in its unified architecture approach. While individual concepts like BOS/CHoCH, FVG, and OB detection exist in other scripts, this indicator is justified because:

  • It runs all structure concepts through a single swing engine, ensuring consistency between BOS/CHoCH classification and zone creation
  • The priority-based signal system with cooldowns prevents the visual clutter that plagues most multi-concept indicators
  • FVG and OB mitigation tracking provides dynamic zone lifecycle management — zones are not static; they evolve as price interacts with them
  • The structure score synthesizes swing patterns, zone activity, volume, alignment, and delta into a single 0-100 metric
  • EQH/EQL detection with automatic sweep deletion creates self-cleaning liquidity maps
  • Institutional signal detection (Wyckoff spring/upthrust, absorption, CVD divergence) is integrated with the structure engine rather than bolted on separately
  • The Emerald Matrix theme provides a cohesive visual identity where every color choice carries meaning (green = bullish structure, red = bearish, amber = warning, cyan = highlight)


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. Market structure analysis is a framework for understanding price behavior, not a prediction system. BOS, CHoCH, FVG, and OB signals do not guarantee future price movement. Past structural patterns do not guarantee they will repeat. Always use proper risk management and never risk more than you can afford to lose. The author is not responsible for any losses incurred from using this indicator.

-Made by officialjackofalltrades

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.