OPEN-SOURCE SCRIPT

Fair Value Gap Indicator with Fill Tracking and HTF Gaps

563
🔵 OVERVIEW


Fair Value Gap Indicator with Fill Tracking and HTF Gaps [Viprasol] is an indicator that draws only the fair value gaps (FVG) created by real displacement, tracks how much of each gap has been filled in real time, and keeps statistics on how gaps get revisited and mitigated. It cuts out the clutter of plotting every three-candle gap, and shows how FVGs actually behave on your market instead of leaving you to guess.


🔵 HOW IT WORKS


The indicator detects qualified gaps, follows each one until it is mitigated or expires, and records the outcome:

1 — Gap Detection

  • Three-Candle Imbalance: A bullish FVG forms when the low of the current candle is above the high of the candle two bars back, with a bullish middle candle. Bearish is the mirror. The gap is the untraded price area between candle 1 and candle 3.
  • Size Filter: The gap height must be at least Minimum gap size × ATR.
  • Displacement Filter: The middle candle body must be at least Displacement × ATR, so only gaps created by a decisive move are kept.


2 — Fill Tracking

  • Deepest Fill: For every open gap the indicator records the deepest price that traded back into it.
  • Live Fill %: The distance traded into the gap divided by the gap height, printed on the box.
  • 50% Line: An optional dotted line at the middle of the gap (consequent encroachment).


3 — Mitigation

  • Full fill: The whole gap has been traded through.
  • 50% fill: Price reached consequent encroachment.
  • Close through: A candle closed beyond the far edge.
  • Expiry: Gaps left unfilled for longer than the bar limit are removed. Mitigated gaps can stay on the chart, faded.


4 — Higher-Timeframe Gaps

  • Completed Candles Only: HTF gaps use the last three completed candles of the Higher timeframe (no lookahead), so a daily fair value gap appears once the daily candle that completes it has closed.



🔵 HOW TO USE


Beyond marking imbalances, you can use the indicator in several ways:

  1. Support and Resistance Zones: Watch fresh bullish FVGs as possible support on pullbacks, and bearish FVGs as possible resistance.
  2. Fair Value Gap Entries: Many traders watch the first return into a gap and its 50% line. The "% filled" label shows how deep price has already gone.
  3. Multi-Timeframe Map: Turn on HTF gaps (for example 4H on a 15m chart) to see which gaps matter on the bigger picture.
  4. Match Your Definition: Pick the mitigation rule that fits how you trade gaps. "Close through" keeps gaps longer than "50% fill".
  5. Read the Statistics: If most gaps on your symbol get fully filled within a few bars, trading away from them is less reliable there.



🔵 SETTINGS


  • Detection: Minimum gap size, Displacement, ATR length, Gap is mitigated on, Max active gaps per side, Expire unfilled gaps after.
  • Higher-timeframe gaps: on/off and Higher timeframe.
  • Display: bullish/bearish toggles, colours, 50% line, live fill %, keep mitigated gaps, statistics table and position.



🔵 ALERTS


  • New bullish / bearish FVG: a qualified gap has just formed.
  • Price returned to bullish / bearish FVG: the first touch back into a gap.
  • FVG mitigated: a gap met your mitigation rule.


All alerts fire once per bar close.


🔵 NOTES


Why this implementation is unique:

  • Displacement and ATR-size filters remove most of the noise that plain FVG scripts plot.
  • A live fill percentage on every open gap, not just an on/off state.
  • Three mitigation definitions in one tool.
  • Non-repainting higher-timeframe gaps built only from completed candles.
  • A revisit and mitigation record, so you can judge FVG behaviour on your own market.


Limitations:

  • A gap is confirmed only when its third candle closes, so it appears one bar after the displacement candle.
  • Higher-timeframe gaps are drawn from the moment their HTF candle closes, not back in time.
  • The statistics count chart-timeframe gaps only. They describe this chart's past and do not predict future fills.
  • The maximum number of active gaps per side caps the boxes, and the oldest gaps are removed first.


This script is for education and analysis. It does not give financial advice.

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.