Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Indicator | Fair Value Gaps | Trading Tool Update

Discover expert developed MetaTrader tools that can complement professional solutions.

Image for Fair Value Gaps


Detects bullish and bearish fair value gaps (three-candle imbalances) on closed bars only, so zones don't repaint, and tracks each zone until it's mitigated. Zone state and price levels are exposed through iCustom buffers, so an EA can read them without parsing chart objects.

Trade Renko charts automatically using the advanced Renko Expert Advisors. Clean trends, better entries. Discover them here.

A bullish gap is formed when the high of candle 1 is below the low of candle 3; a bearish gap is the mirror. Bar 0 is never used for detection or mitigation. Each zone is drawn as a rectangle that extends right until it's mitigated.

Input Default Meaning
InpMinSizeMode MIN_POINTS How the minimum gap size is measured: points, or a fraction of ATR.
InpMinSize 0.0 Minimum gap size (points, or ATR multiplier). 0 keeps every gap.
InpAtrPeriod 14 ATR period for MIN_ATR_FRACTION, 1–500.
InpMitigation MIT_FULL_FILL MIT_TOUCH: the zone is mitigated when price enters it. MIT_FULL_FILL: mitigated only when price crosses the whole zone.
InpBullColor clrLimeGreen Bullish zone color.
InpBearColor clrTomato Bearish zone color.
InpMitigatedColor clrGray Mitigated zone color.
InpShowMitigated true Keep mitigated zones on the chart (false deletes them).
InpMaxZones 100 Most recent zones tracked and drawn, 1–5000.
InpHistoryBars 3000 Bars scanned on the first calculation, 100–100000.

Zone states: 0 none, 1 active, 2 touched, 3 mitigated. "Touched" means partially filled: price entered the zone but didn't cross it. It only occurs in MIT_FULL_FILL mode; in MIT_TOUCH the first entry mitigates the zone.

iCustom buffers (not plotted, visible in the Data Window). Values are written on the bar of candle 3, the bar where the gap is confirmed:

  • 0: state (0–3), updated as the zone changes
  • 1: top price (EMPTY_VALUE if no gap)
  • 2: bottom price (EMPTY_VALUE if no gap)
  • 3: direction (+1 bullish, -1 bearish, 0 none)

Zones dropped by InpMaxZones keep their last buffer state.

int h = iCustom(_Symbol, _Period, "FairValueGaps");
double st[1], top[1], bot[1], dir[1];
if(h != INVALID_HANDLE &&
   CopyBuffer(h, 0, 1, 1, st)  == 1 && CopyBuffer(h, 1, 1, 1, top) == 1 &&
   CopyBuffer(h, 2, 1, 1, bot) == 1 && CopyBuffer(h, 3, 1, 1, dir) == 1 &&
   dir[0] != 0)
   PrintFormat("FVG on bar 1: dir %d, %.5f-%.5f, state %d", (int)dir[0], bot[0], top[0], (int)st[0]);

No alerts, no trading, no DLL or WebRequest. Chart objects use the FVGZ_ prefix and are removed with the indicator.


Level up your trading with professional RobotFX expert advisors and indicators. Visit robotfx.org for proven MT4/MT5 tools.

79079

Best MetaTrader Indicators + Profitable Expert Advisors