OPEN-SOURCE SCRIPT

Real Fair Value Gaps [GBB]

4 555
Real Fair Value Gaps [GBB]

A fair value gap is a three-candle imbalance: the wicks of candle 1 and candle 3 do not overlap, leaving a price range that was never traded. This script finds those gaps on the chart timeframe and on one higher timeframe, tracks each one through its full life (fresh, touched, midpoint tapped, mitigated or inverted), and draws only the ones that matter right now.

What it does differently than other Fair Value Gap indicators


Consumed vs. remaining: As price trades into a gap, the drawn zone shrinks to the unfilled remainder. The consumed part is shown as a dashed fill from the entered edge to the deepest penetration, so you see how much of the gap is actually left, not a full box that price already went through.

Spotlight: Only the N active gaps closest to price carry the full glow (gradient bands, dotted midpoint, origin notch, price chip). Everything else is a thin outline. The chart stays readable with dozens of live gaps.

Freshness: Glow decays to half strength over a set number of bars and then holds. A gap from 300 bars ago looks different from one made ten bars ago.

Inversions: A close beyond the far edge flips the gap into an inverted FVG (IFVG) with the opposite bias instead of retiring it. This is an optional setting

Visibility window: Gaps farther than X ATR from price are tracked but not drawn, so far-away zones do not stretch your price scale.

Higher timeframe without repainting: HTF gaps are built only from completed HTF candles (values are read with a [1] offset) and are anchored to the exact HTF candle times. Auto mode picks one step above your chart (1m→15m, 5m→1H, 15m→4H, 1H→D, 4H→W, D→W).
Everything on confirmed bars. Detection, state changes and alerts all fire on bar close.

Inputs

Detection


Min size (ATR ×): ignore gaps smaller than a multiple of ATR(14) on the gap's own timeframe. 0 = off.

Auto threshold: keep a gap only if its height relative to price is above the running mean of all candidates seen so far. Overrides Min size.

Require displacement: candle 2 must close beyond candle 1's extreme.

Mitigation

Source: Wick or Close.
Point: Near edge, Midpoint or Far edge (fully filled).
Track inversions: on/off.

Higher timeframe

Enable, and the timeframe (empty = automatic).

Look

Palette: (GBB / Calm blue-amber / Custom), glow intensity, spotlight count, fade length, how long mitigated outlines stay, label mode, and the ATR visibility window.

Display

Info table: active gap counts, nearest gap above and below price, HTF status, and a running fill rate over the loaded bars.

Alerts


New bullish / bearish FVG (chart TF), new HTF bullish / bearish FVG, price entered a gap, midpoint tapped, gap mitigated, gap inverted. All on confirmed bars.

Data window

Active bull count, active bear count, mitigated count, HTF active count, and a last-event code (1 new bull, 2 new bear, 3 touch, 4 midpoint, 5 mitigated, 6 inverted) are exposed as hidden plots for use in your own scripts.

How to read it

The dotted midpoint line is the consequent encroachment level; it disappears once price has consumed it. The small solid notch marks the birth candle. The chip on the right edge shows the midpoint price and tags the gap as HTF or IFVG. A mitigated gap collapses to a grey dashed outline frozen at the bar where it was filled, then drops off after the configured number of bars.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.