Fair Value Gap (FVG) Detector with Auto-Removal When Filled
A Fair Value Gap is a price imbalance left by a fast move. It is formed by three consecutive candles: the first and the third candle do not overlap, so the range between them was crossed by the middle candle only, with no trading from both sides. Many traders expect price to come back to such a gap to "fill" it, and use it as a zone for entries, targets or as a sign of strong momentum.
The indicator finds these gaps on closed bars, draws a box for each one and checks every active gap against new prices. When the gap is filled (you choose what "filled" means), the box is deleted, so the chart shows only gaps that are still open.
The indicator keeps a list of active gaps. At the start it scans a limited number of bars; after that, each new closed bar is processed once and each tick only checks the active gaps against the current bar. The full history is never rescanned.
The fill rule is set by InpFillMode:
The check uses High and Low prices (wicks) of the bars after the pattern.
| Input | Default | Purpose |
|---|---|---|
| Detection | ||
| InpMinGapPoints | 10 | Minimum gap size in points; smaller gaps are ignored (0 = any gap) |
| InpLookbackBars | 500 | Number of bars scanned when the indicator starts (10 to 5000) |
| InpMaxZones | 30 | Maximum number of zones kept; the oldest is dropped first (1 to 200) |
| Fill rule | ||
| InpFillMode | FVG_FILL_FULL | When a gap is considered filled: FVG_FILL_TOUCH, FVG_FILL_HALF or FVG_FILL_FULL |
| InpDeleteFilled | true | Delete filled zones; if false they stay as gray dotted boxes that stop at the fill bar |
| InpFilledColor | clrDimGray | Color of filled zones when they are kept |
| Appearance | ||
| InpBullColor | clrWhite | Color of bullish gaps |
| InpBearColor | clrGray | Color of bearish gaps |
| InpZoneStyle | STYLE_DASH | Border style of the zones |
| InpZoneWidth | 1 | Border width (1 to 5) |
| InpFillZones | false | Fill the zones with color |
| InpExtendBars | 20 | Number of bars the zones extend to the right of the last bar (0 to 200) |
| Alerts | ||
| InpAlertNew | false | Show an alert when a new gap forms on a closed bar |

Fig. 1. FvgDetector on an M15 chart with default settings: open bullish gaps in white and a bearish gap in gray (black and white image per Code Base guidelines).
Index Gap Marker – daily opening gaps and fill status
Shows the daily opening gaps for stock indices and indicates whether each one has been filled.
News Event Marker
Marks built-in economic calendar events on the chart with time lines, optional windows, labels, a panel and alerts.
Order Block Marker with Mitigation Tracking
Marks bullish and bearish order blocks (the last opposite candle before a strong impulse) and tracks their state: fresh, mitigated when price returns, and removed when broken.
Fair Value Gap (FVG) Detector with Auto-Removal When Filled
Detects bullish and bearish Fair Value Gaps (three-candle price imbalances), draws them as boxes extending to the right and automatically removes each box once the price fills the gap.