OPEN-SOURCE SCRIPT
Fair Value Gap Detector | AlphaScript

⚡ Fair Value Gap Detector
Most fair value gap indicators mark every three-candle gap on the chart — including the weak, meaningless ones. This tool only marks FVGs created by genuine displacement: a strong-bodied move that signals real institutional participation. Fewer gaps, but the ones that matter.
💡 What a fair value gap is
A fair value gap (FVG) is a three-candle imbalance where price moved so quickly that it left an unfilled gap. In a bullish FVG, the low of the third candle sits above the high of the first — the middle candle's move was so strong it skipped a price range where little trading occurred. Price often returns to "fill" these gaps before continuing, which is why traders watch them as potential entry and reaction zones.
🎯 Why displacement matters
A gap alone is not significant, gaps form constantly, most from weak or random price action. What makes an FVG worth trading is displacement: the middle candle being a large, decisive move that leaves the gap behind. This tool measures the middle candle's body against ATR and only registers the FVG when that body is large enough to qualify as real displacement, and when it moved in the gap's direction. The result is a chart showing institutional-grade gaps instead of noise.
🔍 How detection works
On each confirmed three-candle sequence the tool checks:
A valid gap exists (third candle's low above first candle's high for bullish; third's high below first's low for bearish).
The gap is at least a minimum size, measured as a multiple of ATR, so it is instrument-independent.
The middle candle's body is a genuine displacement — at least a configurable multiple of ATR — and pushed in the gap's direction.
Only sequences passing all three become FVG zones. The displacement requirement can be turned off if you prefer the classic "any gap" behavior.
🟩 Mitigation tracking
Each FVG zone stays active until price fills it. You choose how a fill is counted:
Touch — the gap is mitigated when price reaches its midpoint (the 50% level, where FVGs often react).
Close — the gap is mitigated only when price closes fully through it.
A midline marks the 50% level of every zone.
🎨 Customization
Bullish and bearish fill colors and opacity, midline display, and how far zones extend to the right (a configurable number of bars, so zones don't run infinitely across the chart, or fully infinite if you prefer). Separate toggles for bullish and bearish zones.
📈 How to use it
Treat an active bullish FVG below price as a potential demand zone and an active bearish FVG above price as potential supply. Watch for price returning to a zone — especially the 50% midline — as a possible reaction point, in the direction of the displacement that created it. Because only displacement gaps are shown, each zone represents a move with real momentum behind it rather than a random imbalance. Combine with your own structure and bias — the tool marks the zones, you make the decisions.
🔔 Alerts
Bullish FVG formed, bearish FVG formed, and mitigation alerts when a zone is filled.
⚙️ Settings
ATR length and minimum gap size, displacement requirement and strength, mitigation mode, zone extension length, colors, opacity, midline, and per-direction display toggles.
📌 Notes
FVGs are detected on confirmed bars only and do not repaint intrabar. Detection strictness depends on the gap-size and displacement settings — tune them to your instrument and timeframe. A fair value gap marks an area of potential interest, not a guaranteed reaction — always combine with your own analysis and risk management.
Most fair value gap indicators mark every three-candle gap on the chart — including the weak, meaningless ones. This tool only marks FVGs created by genuine displacement: a strong-bodied move that signals real institutional participation. Fewer gaps, but the ones that matter.
💡 What a fair value gap is
A fair value gap (FVG) is a three-candle imbalance where price moved so quickly that it left an unfilled gap. In a bullish FVG, the low of the third candle sits above the high of the first — the middle candle's move was so strong it skipped a price range where little trading occurred. Price often returns to "fill" these gaps before continuing, which is why traders watch them as potential entry and reaction zones.
🎯 Why displacement matters
A gap alone is not significant, gaps form constantly, most from weak or random price action. What makes an FVG worth trading is displacement: the middle candle being a large, decisive move that leaves the gap behind. This tool measures the middle candle's body against ATR and only registers the FVG when that body is large enough to qualify as real displacement, and when it moved in the gap's direction. The result is a chart showing institutional-grade gaps instead of noise.
🔍 How detection works
On each confirmed three-candle sequence the tool checks:
A valid gap exists (third candle's low above first candle's high for bullish; third's high below first's low for bearish).
The gap is at least a minimum size, measured as a multiple of ATR, so it is instrument-independent.
The middle candle's body is a genuine displacement — at least a configurable multiple of ATR — and pushed in the gap's direction.
Only sequences passing all three become FVG zones. The displacement requirement can be turned off if you prefer the classic "any gap" behavior.
🟩 Mitigation tracking
Each FVG zone stays active until price fills it. You choose how a fill is counted:
Touch — the gap is mitigated when price reaches its midpoint (the 50% level, where FVGs often react).
Close — the gap is mitigated only when price closes fully through it.
A midline marks the 50% level of every zone.
🎨 Customization
Bullish and bearish fill colors and opacity, midline display, and how far zones extend to the right (a configurable number of bars, so zones don't run infinitely across the chart, or fully infinite if you prefer). Separate toggles for bullish and bearish zones.
📈 How to use it
Treat an active bullish FVG below price as a potential demand zone and an active bearish FVG above price as potential supply. Watch for price returning to a zone — especially the 50% midline — as a possible reaction point, in the direction of the displacement that created it. Because only displacement gaps are shown, each zone represents a move with real momentum behind it rather than a random imbalance. Combine with your own structure and bias — the tool marks the zones, you make the decisions.
🔔 Alerts
Bullish FVG formed, bearish FVG formed, and mitigation alerts when a zone is filled.
⚙️ Settings
ATR length and minimum gap size, displacement requirement and strength, mitigation mode, zone extension length, colors, opacity, midline, and per-direction display toggles.
📌 Notes
FVGs are detected on confirmed bars only and do not repaint intrabar. Detection strictness depends on the gap-size and displacement settings — tune them to your instrument and timeframe. A fair value gap marks an area of potential interest, not a guaranteed reaction — always combine with your own analysis and risk management.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Gabriel R. | AlphaScript
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Script de código abierto
Fiel al espíritu de TradingView, el creador de este script lo ha convertido en código abierto, para que los traders puedan revisar y verificar su funcionalidad. ¡Enhorabuena al autor! Aunque puede utilizarlo de forma gratuita, recuerde que cualquier republicación del código está sujeta a nuestras Normas internas.
Gabriel R. | AlphaScript
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.