OPEN-SOURCE SCRIPT

Volumetric Inverse Fair Value Gap (IFVG) [Kodexius]

100
The Volumetric Inverse Fair Value Gap (IFVG) indicator detects and visualizes inverse fair value gaps (IFVGs) zones where previous inefficiencies in price (fair value gaps) are later invalidated or “inverted.”

Unlike traditional FVG indicators, this tool integrates volume-based analysis to quantify the bullish, bearish, and overall strength of each inversion. It visually represents these metrics within a dynamically updating box on the chart, giving traders deeper insight into market reactions when liquidity imbalances are filled and reversed.

لقطة

Features

Inverse fair value gap detection

The script identifies bullish and bearish fair value gaps, stores them as pending zones, and turns them into inverse fair value gaps when price trades back through the gap in the opposite direction. Each valid inversion becomes an active IFVG zone on the chart.

Sensitivity control with ATR filter and strict mode

A minimum gap size based on ATR is used to filter out small and noisy gaps. Strict mode can be enabled so that any wick contact between the relevant candles prevents the gap from being accepted as a fair value gap. This lets you decide how clean and selective the zones should be.

Show Last N Boxes control

The indicator can keep only the most recent N IFVG zones visible. Older zones are removed from the chart once the number of active objects exceeds the user setting. This prevents clutter on higher timeframes or long histories and keeps attention on the most relevant recent zones.

Ghost box for the original gap

When the ghost option is enabled, the script draws a faint box that marks the original fair value gap from which the inverse zone came. This makes it easy to see where the initial imbalance appeared and how price later inverted that area.

Volumetric bull, bear and strength metrics

For each IFVG, the script estimates how much of the bar volume is associated with buying and how much with selling, then computes bull percentage, bear percentage and a strength score that uses a percentile rank of volume. These values are stored with the IFVG object and drive the visualization inside the zone.

لقطة

Three band visual layout inside each IFVG

Each active IFVG is drawn as a container with three horizontal sections. The top band represents the bull percentage, the middle band the bear percentage and the bottom band the strength metric. The width of each bar reflects its respective value so you can read the structure of the zone at a glance.

Customizable colors and label text

Colors for bull, bear, strength, the empty background area, the ghost box and label text can be adjusted in the inputs. This allows you to match the indicator to different chart themes or highlight specific aspects such as strength or direction.

Automatic invalidation and cleanup

When price clearly closes beyond the IFVG in a way that breaks the logic of that zone, the script marks it as inactive and deletes all boxes and labels linked to it. Only valid and active IFVGs remain on the chart, which keeps the display clean and focused.

Calculations

1. Detecting Fair Value Gaps (FVGs)

A fair value gap is identified when price action leaves an imbalance between candle wicks. Depending on the mode:

Bullish FVG: When low[0] > high[2]

Bearish FVG: When high[0] < low[2]

Optionally, the strict mode ensures wicks do not touch.
The gap’s significance is filtered using the ATR multiplier input to exclude minor noise.

Once detected, FVGs are stored as pending zones until inverted by opposite movement (price crossing through).

Pine Script®
bool bull_cond = strict_mode ? (low[0] > high[2]) : (close[0] > high[2]) bool bear_cond = strict_mode ? (high[0] < low[2]) : (close[0] < low[2]) float gap_size = 0.0 if bull_cond and close[1] > open[1] gap_size := low[0] - high[2] if bear_cond and close[1] < open[1] gap_size := low[2] - high[0]


2. Creating IFVGs (Inversions)

When price later moves through a previous FVG in the opposite direction, an Inverse FVG (IFVG) is created.

For example:

A previous bearish FVG becomes bullish IFVG if price moves upward through it.

A previous bullish FVG becomes bearish IFVG if price moves downward through it.

The IFVG is initialized with structural boundaries (top, bottom) and timestamp metadata to anchor visualization.

Pine Script®
if not p.is_bull_gap and close > p.top inverted := true to_bull := true if p.is_bull_gap and close < p.btm inverted := true to_bull := false


3. Volume Metrics (Bull, Bear, Strength)

Each IFVG calculates buy and sell volumes from the current bar’s price spread and total volume.

Bull % = proportion of upward (buy) volume

Bear % = proportion of downward (sell) volume

Strength % = normalized percentile rank of total volume

These are obtained through a custom function that estimates directional volume contribution:

Pine Script®
calc_metrics(float o, float h, float l, float c, float v) => float rng = h - l float buy_v = 0.0 if rng == 0 buy_v := v * 0.5 else if c >= o buy_v := v * ((math.abs(c - o) + (math.min(o, c) - l)) / rng) else buy_v := v * ((h - math.max(o, c)) / rng) float sell_v = v - buy_v float total = buy_v + sell_v float p_bull = total > 0 ? buy_v / total : 0 float p_bear = total > 0 ? sell_v / total : 0 float p_str = ta.percentrank(v, 100) / 100.0 [p_bull, p_bear, p_str]

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.