OPEN-SOURCE SCRIPT

Imbalance Zone Classifier [JOAT]

2 423
Imbalance Zone Classifier [JOAT]

Introduction

The Imbalance Zone Classifier detects Fair Value Gaps (price imbalances where no two-sided auction occurred) and assigns each zone a 0–100 Strength Score based on four measurable factors: gap size relative to historical distribution, intrabar buy/sell volume composition, zone age, and mitigation status. Rather than drawing every FVG indiscriminately, this indicator filters by minimum score and renders only the zones most likely to attract institutional order flow on return visits.

The core problem this solves: nearly every FVG tool draws every gap, producing charts saturated with dozens of overlapping boxes that cannot be prioritized. A 0.03% gap on declining volume is not equivalent to a 0.8% gap formed on explosive institutional buying. The Strength Score quantifies that difference, letting the trader focus on the handful of zones that genuinely matter.

Snapshot

Core Concepts

1. Fair Value Gap Detection

An FVG (also known as an inefficiency or price imbalance) occurs when three consecutive candles leave a price gap:

Pine Script®
// Bullish FVG: candle[2] high is below candle[0] low bool bull_fvg = high[2] < low and close > open // Bearish FVG: candle[2] low is above candle[0] high bool bear_fvg = low[2] > high and close < open


Detection is confirmed on bar close — the gap is only registered after candle[0] closes — ensuring no repainting. The zone boundaries are the candle[2] high and candle[0] low for a bullish FVG (and their inverses for bearish).

2. The 0–100 Strength Score

Each FVG receives a composite score derived from four sub-scores:

Pine Script®
int vol_score = int(math.min(bull_pct / 0.7 * 50, 50)) // 0-50 pts int size_score = int(math.min(gap_rank * 0.35, 35)) // 0-35 pts int composite_score = vol_score + size_score // base // Age decay applied post-formation: score -= 1 per N bars


  • Size Score (0–35 pts): The gap size as a percentage of price is ranked against the last 1000 bars using a percentile rank. A gap in the top 10% of historical size scores near maximum. A tiny gap scores near zero.
  • Volume Score (0–50 pts): Lower-timeframe bars within the formation candle's time window are decomposed into buy and sell volume. A bullish FVG with 90% buy-side composition scores 50; one with 50% scores 25.
  • Age Decay: Zones accumulate bar age. The score decays over time, reflecting that older unmitigated zones become less relevant. Zones below the minimum score threshold fade and are removed.


3. Lower-Timeframe Volume Decomposition

Volume intelligence comes from requesting sub-bar data at the user-specified lower timeframe:

Pine Script®
array<float> ltf_bull_vol = request.security_lower_tf("", i_ltf, (close > open ? volume : 0.0)) array<float> ltf_bear_vol = request.security_lower_tf("", i_ltf, (close < open ? volume : 0.0)) float sum_bull_ltf = ltf_bull_vol.sum() float sum_bear_ltf = ltf_bear_vol.sum() float bull_pct = sum_bull_ltf / (sum_bull_ltf + sum_bear_ltf)


This decomposes the FVG formation candle's volume into directional sub-bar composition — giving a precise measure of whether the gap was formed by institutional buying pressure or merely a thin-volume vacuum.

4. Mitigation Logic

Zones are considered mitigated when price returns to the zone midpoint (or high/low depending on user setting). Mitigated zones do not disappear immediately — they change color and fade, providing a historical record. They are removed from the active list after a configurable bar count, and a counter increments in the dashboard.

5. Volume Bar Visualization Inside Zones

Each zone renders a proportional buy/sell volume bar inside the zone body — a thin inner box whose right edge shows the bull/bear volume ratio. A zone with 80% buy volume renders its inner bar nearly full green. This gives an immediate visual indication of the composition without requiring the dashboard.

Features

  • Fair Value Gap Detection: Bullish and bearish FVGs confirmed on bar close, non-repainting
  • 0–100 Strength Score: Composite score from gap size percentile rank and lower-timeframe volume composition
  • Minimum Score Filter: Only zones above the threshold are rendered — keeps the chart clean
  • LTF Volume Decomposition: True intrabar buy/sell ratio from lower-timeframe data
  • Volume Bar Inside Zone: Proportional buy/sell bar rendered within each zone body
  • Mitigation Tracking: Zones transition to faded color on mitigation; active vs mitigated count in dashboard
  • Zone Extension: Unmitigated zones extend rightward automatically until price returns
  • Age Decay: Score degrades over time, naturally purging stale zones below the threshold
  • 9-Row Dashboard: Active bullish zones, active bearish zones, total mitigated, highest current score, session FVG count
  • Alerts: Bullish FVG formed, bearish FVG formed, bullish FVG mitigated, bearish FVG mitigated


Input Parameters

FVG Detection:
  • Detect Bullish FVGs: Toggle bullish imbalance detection (default: on)
  • Detect Bearish FVGs: Toggle bearish imbalance detection (default: on)
  • Minimum Strength Score (0–100): Filter threshold — only zones above this are shown (default: 25). Higher = fewer, stronger zones.
  • Mitigation Source: close = mitigated when close crosses zone midpoint. high/low = wick breach removes the zone (default: close)
  • Max Active Zones: Maximum simultaneous rendered zones (default: 12, range: 3–30)


Volume Intelligence:
  • LTF Resolution: Lower timeframe for intrabar volume decomposition (default: 1m)


Visualization:
  • Bullish / Bearish / Mitigated colors: Fully customizable
  • Show Volume Bars Inside Zones: Display proportional buy/sell bar within each zone (default: on)
  • Extend Unmitigated Zones: Extend zone boxes rightward until mitigation (default: on)


Dashboard:
  • Position: Top Right, Top Left, Bottom Right, Bottom Left (default: Top Right)


How to Use This Indicator

Step 1: Set the Minimum Score
Start with the default score of 25. This filters out the weakest gaps while keeping meaningful zones. If the chart still shows too many zones, raise to 40–50. For maximum selectivity on higher timeframes, 60+ selects only the most institutionally significant gaps.

Step 2: Read the Volume Bar Inside Each Zone
A bullish FVG with a mostly green inner bar (80%+ buy volume) was formed by genuine institutional buying. One with a near-50% bar was formed in a thin, directionless push — much less likely to hold on retest. This distinction cannot be made from price action alone.

Step 3: Trade the Retest
Price frequently returns to fill FVG zones, particularly the highest-score zones. The midpoint of the zone (zone top + zone bottom / 2) is the primary retest level. Entry on a return to a high-score bullish FVG, with a stop below the zone low, is a clean risk-defined setup.

Step 4: Monitor Mitigation
Once a zone changes to the mitigated color, it no longer has predictive value as a support/resistance level — it has been filled. Remove it from your analysis. The dashboard count of mitigated zones tells you how efficiently the market is clearing imbalances.

Originality Statement

This indicator is original in its composite strength scoring system applied to Fair Value Gaps using lower-timeframe volume decomposition. Its publication is justified because:

  • Gap size percentile rank against 1000-bar history normalizes the score across different instruments and timeframes — a 0.5% gap on EURUSD scores the same as a 0.5% gap on BTCUSD regardless of absolute price level
  • Lower-timeframe volume decomposition provides true intrabar buy/sell composition of each FVG formation candle — a dimension of analysis unavailable from chart-timeframe OHLCV data alone
  • The visual volume bar inside each zone encodes directional conviction directly within the zone's screen space, creating a two-dimensional information display (price level + volume direction) without additional panels
  • Age decay combined with minimum score filtering creates a self-organizing, self-cleaning zone map that requires no manual zone management from the trader


Snapshot

Limitations

  • LTF volume requests add computation overhead. On 1-minute chart timeframes, requesting 1-minute LTF data is a no-op; the function falls back to chart-timeframe volume for those bars.
  • The strength score is a relative ranking, not an absolute predictive probability. A score of 80 does not mean an 80% chance of holding — it means this zone is stronger than most, not that it is guaranteed to act as support or resistance.
  • Mitigation is detected on bar close (or high/low depending on setting). Intrabar wicks that return to the zone but close outside it will not trigger mitigation in the default setting.
  • The maximum zone count is a performance and visual constraint. On timeframes where FVGs form frequently, older lower-score zones are removed to stay within the limit.


Disclaimer

This indicator is provided for educational and informational purposes only. It does not constitute financial advice or a recommendation to buy or sell any instrument. All trading involves risk of loss. Fair Value Gap zones do not guarantee price reversal or support. Always use proper risk management.

-Made with passion by jackofalltrades

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.