Skip to content
FXNook HubBeta

Alex / Fair Value Gap (FVG) Indicator for MT5

MetaTrader 5IndicatorMITCompiled · build 6333
AlexFirst version.build 6333v1.08 hours ago1 version
  • FXN_FairValueGap.mq5First version.11 KB
  • FXN_FairValueGap.ex5Compiled by the Lab with MetaEditor build 633326 KB
README

Overview

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.

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

InputDefaultWhat it does
Minimum gap points0Smallest gap in points (0 = off)
Minimum gap vs average range0.10Smallest gap as a fraction of the average range (0 = off)
Average range bars14Bars for the average true range
History bars1500Bars to scan (0 = all)
Maximum boxes40Most boxes kept on the chart
Fill modeFullTouch, half (middle) or full fill
Show bullish / bearishtrue / trueWhich gaps to draw
Keep filled gapsfalseKeep filled boxes in grey
Fill boxestrueSolid boxes or outline only
Extend bars5How far past the current bar open boxes reach
Bullish / bearish / filled colourgreen / red / greyBox colours
Alert on new gapfalseOne 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.

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

Settings read from the code

InputTypeDefaultNote
InpMinGapPointsint0Minimum gap size in points (0 = off)
InpMinGapAtrdouble0.10Minimum gap size as a fraction of average range (0 = off)
InpAtrPeriodint14Bars used for the average range
InpMaxBarsint1500History bars to scan (0 = all bars)
InpMaxZonesint40Maximum boxes kept on the chart (oldest removed first)
InpFillModeENUM_FVG_FILLFVG_FILL_FULLWhen a gap counts as filled
InpShowBullishbooltrueShow bullish gaps
InpShowBearishbooltrueShow bearish gaps
InpKeepFilledboolfalseKeep filled gaps on the chart (greyed, stopped at the fill bar)
InpFillBoxesbooltrueFill the boxes (false = outline only)
InpExtendBarsint5How many bars past the current bar open boxes reach
InpBullColorcolorC'38,110,80'Bullish gap colour
InpBearColorcolorC'140,45,55'Bearish gap colour
InpFilledColorcolorclrDimGrayFilled gap colour (when kept)
InpAlertNewboolfalseAlert once when a new gap forms on a closed bar

How to use it

  1. Download the compiled file (or the source and compile it in MetaEditor).
  2. Put it in MetaTrader: File → Open Data Folder → MQL5 → Indicators, then refresh the Navigator.
  3. Test it on a demo account before any real money.
  4. Want changes? Open a copy in your Lab and ask for them in plain words.