Phantom Structure Engine [JOAT]Phantom Structure Engine
Overview
Phantom Structure Engine is a comprehensive Smart Money Concepts (SMC) framework built entirely in Pine Script v6 using typed User-Defined Types and methods. It maps institutional price structure across five dimensions simultaneously: swing Break of Structure (BOS), Change of Character (CHoCH), Order Blocks (OB), Fair Value Gaps (FVG), Equal Highs/Lows (EQH/EQL), Liquidity Sweeps, and dynamic Premium/Discount/Equilibrium zones — all rendered with an institutional-grade dark visual palette and managed via object arrays.
Why a Unified SMC Framework?
SMC concepts are deeply interconnected. A BOS creates the context for a valid Order Block. A CHoCH signals a structural regime shift that invalidates existing OBs. A liquidity sweep above an EQH often precedes a reversal into a Discount zone. Displaying these concepts in isolation (as separate indicators) breaks the logical chain between them. Phantom Structure Engine fuses all layers into a single coherent visual, so each element is always read in its correct structural context.
Core Engine — Swing Structure
Two separate pivot engines run concurrently:
- Swing pivots (configurable left/right bars, default 10/10): define the major structure highs and lows used for BOS and CHoCH detection
- Internal pivots (default 3/3): track minor structure shifts for shorter-term intrabar analysis
BOS Detection with Confirmation Counter
Rather than firing on the first close beyond a swing level, the engine counts consecutive closes above the last swing high (or below the last swing low). A BOS only registers when the close count reaches or exceeds the configurable confirmation threshold (default 1, max 5). This suppresses false breaks caused by wicks and momentary spikes while remaining responsive.
- BOS (Break of Structure): Close beyond swing level, structure direction confirmed. Displayed as a horizontal line from the pivot bar to the break bar, with a BOS label.
- CHoCH (Change of Character): BOS that occurs against the prevailing structural direction (e.g., a bullish break when the prior confirmed direction was bearish). Displayed in gold with a dashed line and CHoCH label.
Order Block Detection
When a BOS or CHoCH fires, the engine scans backward (configurable lookback, default 10 bars) for the last opposing candle — a bearish candle before a bullish BOS, or a bullish candle before a bearish BOS. This candle becomes the Order Block zone.
Each OB is drawn with a two-layer box: a wide semi-transparent outer box and a tighter inner highlight. The OB extends forward on every bar and automatically invalidates (turns grey) when price closes through the opposite boundary — the exact behaviour seen when an OB has been mitigated by institutional flow.
Fair Value Gap Detection
A bullish FVG is identified when bar .low > bar .high (a gap in price between the current bar's low and two bars ago's high), indicating that price moved so fast upward that no trading occurred in that range. Bearish FVG is the mirror. FVGs are drawn as dotted-border boxes that extend forward and auto-fill (turn grey) when price returns to close the gap.
Equal Highs / Equal Lows (EQH / EQL)
At each new swing pivot, the engine compares the current pivot value against the previous pivot of the same type. If the absolute percentage difference is less than 0.15%, they are classified as equal and an EQH or EQL label is stamped at the midpoint. These levels represent liquidity pools resting above or below price — targets for institutional sweeps.
Liquidity Sweeps
A sweep is detected when price wicks beyond the last confirmed swing high or low but closes back on the opposite side. This is the classic liquidity grab: price hunts stops above a high (or below a low), then reverses. Sweep labels fire at the wick extreme in gold — one of the highest-probability reversal signals in institutional analysis.
Premium / Discount / Equilibrium Zones
After each confirmed BOS, the engine identifies the full range between the last confirmed swing high and swing low. This range is divided into three zones:
- Premium (top 38.2%): Statistically expensive — short bias in a bearish structure
- Equilibrium (38.2%–61.8%): Fair value — reduce exposure
- Discount (bottom 38.2%): Statistically cheap — long bias in a bullish structure
Previous zones are deleted and redrawn on each new BOS, keeping the chart clean.
Periodic Levels (PDH / PDL / PWH / PWL)
Previous Day High/Low and Previous Week High/Low are fetched via request.security() with lookahead disabled (barmerge.lookahead_off), preventing any future-bar contamination. These levels render as step-line plots and represent the primary reference levels used by institutional order desks at open.
Institutional Funding Candles
Bars where the true range exceeds 1.5× ATR(14) AND volume exceeds 2× the 20-bar volume SMA are highlighted as funding candles. These represent institutional participation bars and are coloured based on the current structural direction: teal (bullish structure), red (bearish structure), gold (neutral).
Dashboard (Top Right)
A compact 2-column, 8-row table displays: current structural direction, active OB count, open FVG count, last confirmed swing high/low values, and current sweep status for both sides.
Inputs Reference
Structure Settings
- Swing Pivot Left/Right Bars (10/10) — major swing sensitivity
- Internal Pivot Left/Right (3/3) — minor structure sensitivity
- BOS Confirmation Closes (1–5) — consecutive closes needed to confirm BOS
- Show BOS Labels / CHoCH Labels / HH-HL-LH-LL labels
Order Blocks
- Show Order Blocks
- OB Lookback Candles (10) — how far back to scan for the OB candle
- Max Active OBs (6) — older OBs are deleted when limit is reached
Fair Value Gaps
- Show Fair Value Gaps
- Max Active FVGs (5)
Premium / Discount
- Show PD Zones / EQH-EQL / Liquidity Sweeps
Periodic Levels
- Show Prev Day H/L / Prev Week H/L
Visual
- Theme: Dark, Light, Auto
- Show Funding Candles
How to Use
1. Apply on any liquid instrument. Allow the warmup period (driven by pivot lookback) before trusting the signals.
2. Read structure direction from the dashboard. BOS labels in teal confirm a bullish shift; CHoCH in gold signals a potential trend reversal.
3. Look for price to pull back into a valid (not invalidated) OB or into the Discount zone before considering long entries. Reverse for shorts.
4. FVG zones often act as magnets — price tends to revisit them before continuing in the BOS direction.
5. Treat Liquidity Sweep labels as potential reversal alerts, particularly when they align with OBs or Discount/Premium zones.
Non-Repainting Design
All BOS, CHoCH, sweep, and FVG signals are gated by barstate.isconfirmed. Periodic levels use close with lookahead_off. No pivot value is read until the required right-bar confirmation period has elapsed. Historical labels never shift position.
Limitations
- SMC is a discretionary framework. This indicator automates detection but cannot replace contextual judgment on higher-timeframe bias.
- In extremely fast-moving markets, FVGs may form and fill within the same session, reducing their relevance as future targets.
- EQH/EQL detection uses a 0.15% price equality threshold — this may need adjustment for very low-priced or highly volatile instruments.
- OBs are detected from the most recent opposing candle before a BOS. On some instruments, the true institutional OB may be further back.
Disclaimer
This indicator is provided for educational and informational purposes only. SMC concepts describe price behaviour patterns and do not guarantee any future market outcome. Always conduct your own analysis and use proper risk management.
Made with passion by officialjackofalltrades
Pine Script® indicator






















