# Fair Value Gap (FVG) Indicator for MT5

> Finds 3-candle fair value gaps (imbalances) and draws them as boxes that extend to the right until price fills them, with size filters and a box limit.

## At a glance

- What it is: A free Indicator for MetaTrader 5, written in MQL5.
- What it does: Finds 3-candle fair value gaps (imbalances) and draws them as boxes that extend to the right until price fills them, with size filters and a box limit.
- Shared by: Alex
- Licence: MIT
- Version: 1.0 (1 Dec 2026)
- Settings: 15 inputs
- Lab check: Compiled with MetaEditor build 6333 for MT5 on 1 Dec 2026: 0 errors, 0 warnings.
- Price: Free to download
- Page: https://hub.fxnook.com/fair-value-gap-fvg-indicator-for-mt5
- Download (compiled): https://hub.fxnook.com/download/84564516-ebde-4966-933c-f6c4fc047214/compiled
- Download (source): https://hub.fxnook.com/download/84564516-ebde-4966-933c-f6c4fc047214/source

## About

A fair value gap is a price area that one fast candle skipped, leaving no overlap between the candles on either side. Many traders watch these imbalances because price often comes back into them. This indicator marks every gap on closed candles and keeps it on the chart only while it is still open.

## How it works

Three closed candles are checked: candle 1, candle 2 (the fast one) and candle 3.

- **Bullish gap:** the low of candle 3 is above the high of candle 1. The box covers `high[1]` to `low[3]`.
- **Bearish gap:** the high of candle 3 is below the low of candle 1. The box covers `high[3]` to `low[1]`.
- A gap is kept only if it passes both size filters: at least `Minimum gap points` and at least `Minimum gap vs average range` x the average true range of the last `Average range bars` candles.
- Open boxes start at candle 2 and are extended to the right on every new bar.
- A box is **filled** when a later candle (including the forming one) trades into it as set by `Fill mode`: touch the edge, reach the middle, or trade through the whole gap. Filled boxes are deleted, or kept in grey and stopped at the fill candle.
- When more than `Maximum boxes` exist, the oldest box is removed first.

## Inputs

| Input | Default | What it does |
|---|---|---|
| Minimum gap points | 0 | Smallest gap in points (0 = off) |
| Minimum gap vs average range | 0.10 | Smallest gap as a fraction of the average range (0 = off) |
| Average range bars | 14 | Bars for the average true range |
| History bars | 1500 | Bars to scan (0 = all) |
| Maximum boxes | 40 | Most boxes kept on the chart |
| Fill mode | Full | Touch, half (middle) or full fill |
| Show bullish / bearish | true / true | Which gaps to draw |
| Keep filled gaps | false | Keep filled boxes in grey |
| Fill boxes | true | Solid boxes or outline only |
| Extend bars | 5 | How far past the current bar open boxes reach |
| Bullish / bearish / filled colour | green / red / grey | Box colours |
| Alert on new gap | false | One alert when a new gap forms on a closed candle |

## How to use it

1. In MetaTrader open **File > Open Data Folder**.
2. MT4: copy `FXN_FairValueGap.mq4` into `MQL4/Indicators`. MT5: copy `FXN_FairValueGap.mq5` into `MQL5/Indicators`.
3. Right-click **Indicators** in the Navigator and choose **Refresh** (or restart the terminal). The file compiles on first use; you can also open it in MetaEditor and press Compile.
4. Drag the indicator onto a chart and set the inputs.

A good start is the default 0.10 size filter on M15 to H4. Raise it to 0.25-0.5 to keep only clear imbalances. Use **Half** fill mode if you treat a return to the middle of the gap as "used". Combine with trend or structure: in an up-trend many traders only watch the bullish gaps below price.

## Good to know

- Gaps are detected on **closed** candles only, so a box never appears and then disappears because the forming candle changed. A box can be closed by the forming candle, because a traded high or low cannot be undone.
- Four hidden buffers (bullish top/bottom, bearish top/bottom) are set on the third candle of each gap, so an EA can read new gaps with iCustom.
- On markets with weekend gaps (indices, crypto on some brokers) the session gap itself can show up as a fair value gap.
- It marks areas only; it does not predict whether price will react there.

Trading carries risk. Test on a demo account first; past results do not predict future results.

## Settings (inputs)

| Input | Type | Default | Note |
|---|---|---|---|
| InpMinGapPoints | int | 0 | Minimum gap size in points (0 = off) |
| InpMinGapAtr | double | 0.10 | Minimum gap size as a fraction of average range (0 = off) |
| InpAtrPeriod | int | 14 | Bars used for the average range |
| InpMaxBars | int | 1500 | History bars to scan (0 = all bars) |
| InpMaxZones | int | 40 | Maximum boxes kept on the chart (oldest removed first) |
| InpFillMode | ENUM_FVG_FILL | FVG_FILL_FULL | When a gap counts as filled |
| InpShowBullish | bool | true | Show bullish gaps |
| InpShowBearish | bool | true | Show bearish gaps |
| InpKeepFilled | bool | false | Keep filled gaps on the chart (greyed, stopped at the fill bar) |
| InpFillBoxes | bool | true | Fill the boxes (false = outline only) |
| InpExtendBars | int | 5 | How many bars past the current bar open boxes reach |
| InpBullColor | color | C'38,110,80' | Bullish gap colour |
| InpBearColor | color | C'140,45,55' | Bearish gap colour |
| InpFilledColor | color | clrDimGray | Filled gap colour (when kept) |
| InpAlertNew | bool | false | Alert once when a new gap forms on a closed bar |

Tags: fair-value-gap, fvg, imbalance, smart-money, ict, supply-demand, indicator

Shared code is the author's work, not financial advice. Test on a demo account first.
