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).
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
Fair Value Gap (FVG) Detector with Auto-Removal When Filled
Break of Structure (BOS) and Change of Character (CHoCH) Labels
Detects swing highs and lows and labels every break of market structure: BOS (Break of Structure) when the trend continues and CHoCH (Change of Character) when the trend reverses.
Premium and Discount Zones Based on the Current Swing Range
Splits the current swing range (last swing high to last swing low) into a Premium zone above 50% and a Discount zone below 50%, with an equilibrium line and a live label that shows where the price is inside the range.