FVG & IFVG Indicator: Fair Value Gaps and Inversions

Written by Dominic Walsh · Published · Last updated

The FVG & IFVG indicator finds fair value gaps on your price chart. Then it watches what happens when price trades back through one. A gap is the space that opens when a three-candle sequence runs far enough that candle one and candle three never overlap. Once price closes back through that space, the gap has inverted, and the tool re-colours it. It suits traders who already work with smart-money ideas and want the gaps found for them.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 4: FVG Bull Mid, FVG Bear Mid, iFVG Bull (flipped bear), iFVG Bear (flipped bull)
Alerts popup
Inputs 9

What the FVG & IFVG Indicator draws on the chart

FVG Bull Mid puts a lime arrow at the midpoint of a bullish gap, on the bar where the gap completes.

FVG Bear Mid does the same in red for a bearish gap, again at the midpoint rather than either edge.

iFVG Bull (flipped bear) shows a gold arrow where price has traded through a bearish gap, which then reads as support.

iFVG Bear (flipped bull) shows a magenta arrow for the opposite case, a bullish gap that has failed.

Rectangles fill each live zone so you see the whole gap, not just its midpoint.

  • FVG Bull Mid: arrow, lime, width 1, arrow code 233
  • FVG Bear Mid: arrow, red, width 1, arrow code 234
  • iFVG Bull (flipped bear): arrow, gold, width 2, arrow code 233
  • iFVG Bear (flipped bull): arrow, magenta, width 2, arrow code 234
FVG & IFVG indicator on EURUSD H1, gap midpoints arrowed and inverted zones re-coloured
FVG & IFVG indicator on EURUSD H1, gap midpoints arrowed and inverted zones re-coloured

How the FVG & IFVG Indicator calculates its values

Finding the gap across three candles

The scan walks back through history and compares candle one against candle three. It reads h_old from high[i+2] and l_old from low[i+2], then l_new from low[i] and h_new from high[i]. A bullish gap exists when the newer low clears the older high. A bearish gap mirrors that. Since the test spans three bars, one long candle never qualifies on its own.

Marking the midpoint

The code marks the centre of the gap rather than its edge. BullFvgMid takes (l_new + h_old) * 0.5 and BearFvgMid takes (l_old + h_new) * 0.5. Many traders expect the first reaction at the midpoint, so the arrow sits there.

Tracking the inversion

Each gap becomes a zone with a top and a bottom. On every new bar the code reads cl, hi and lo from the current candle and tests them against those zones. When price closes through a zone from the wrong side, the zone flips. The code then writes IfvgBullMid or IfvgBearMid at the centre of that same zone. It never deletes the old gap. It reclassifies it.

How to read the signals

A lime or red arrow means a fresh gap just completed. Nothing has tested it yet.

Rectangles that price has not revisited still carry an untested midpoint.

A gold or magenta arrow carries more information: a level that failed and may now work the other way.

Once the zone count hits its ceiling, the oldest zones drop off, so the newest boxes are the live ones.

Alert channels in this build: popup, one message per closed bar.

One channel runs here: a terminal popup. `InpAlertOnIFVG` controls it and ships as `true`, so the message fires when a gap inverts rather than when a new gap forms. The bar guard limits it to one message per closed bar.

Every FVG & IFVG Indicator input

Core settings

Setting What it does Default
InpLookbackBars Bars to scan back. Sets how far back the gap scan runs, default `600`. Lower it on a slow machine, or when only recent structure matters. 600
InpMaxActiveZones Max active zones drawn. Caps how many zones stay live at once, default `30`. Raise it on higher timeframes, where gaps form rarely and last longer. 30
InpObjPrefix Chart object prefix. Names every rectangle the tool creates, default `”FVGIFVG_”`. Change it only when another indicator on the chart uses the same prefix. FVGIFVG_

Display settings

Setting What it does Default
InpDrawRectangles Draw FVG rectangles. Set it to `false` when you want the arrows alone. on
InpBullFvgColor Bullish FVG fill. lime
InpBearFvgColor Bearish FVG fill. red
InpBullIfvgColor Bullish iFVG (was bearish). gold
InpBearIfvgColor Bearish iFVG (was bullish). magenta

Alert settings

Setting What it does Default
InpAlertOnIFVG Alert on iFVG flip. on
FVG & IFVG indicator inputs: InpLookbackBars, InpMaxActiveZones and the rectangle toggle
FVG & IFVG indicator inputs: InpLookbackBars, InpMaxActiveZones and the rectangle toggle

Settings that fit your chart

Gap logic ignores the timeframe, so the same rules hold from M15 up to the daily chart. The reference screenshot uses EURUSD on H1, dense enough to show several gaps without crowding the boxes. On very low timeframes the scan finds many small gaps and fills the 30 zone ceiling quickly, so higher timeframes read more cleanly.

When the FVG & IFVG Indicator fails

In a quiet range the three-candle test still fires on small gaps that carry no real imbalance, and boxes clutter the chart.

Price can fill a gap slowly over many bars. The inversion arrow needs a close through the zone, so a slow fill leaves no marker at all.

Zones expire once the active limit fills, so a level that matters weeks later may already have dropped off the list.

Copy the compiled FVG & IFVG Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Background reading on the method behind the FVG & IFVG Indicator: Atlantic Money on Wikipedia, Technical Analysis at StockCharts ChartSchool.

Download the FVG & IFVG Indicator for MT4 and MT5

The zip holds the compiled FVG & IFVG Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

What separates FVG Bull Mid from the iFVG Bull plot?

FVG Bull Mid marks a bullish gap the moment it completes, using the midpoint between candle one and candle three. iFVG Bull (flipped bear) marks something different: a bearish gap that price has since closed through, which the code then reads as possible support. One is a new imbalance, the other is a failed one.

Why does InpMaxActiveZones default to 30?

Thirty zones keep the chart readable while covering the gaps still plausibly in play. Once you hit that ceiling the oldest zone drops off. On H4 or daily charts, where gaps form slowly and stay relevant longer, raising the value makes sense. On M5 you reach the ceiling within an hour.

Does InpLookbackBars need candle bodies to overlap?

No, the opposite. The scan records a gap only when candle one and candle three fail to overlap at all. It compares high[i+2] against low[i] for a bullish gap, and low[i+2] against high[i] for a bearish one. Any overlap across that three-bar window means no gap.

Can I run it alongside another tool that uses InpObjPrefix style names?

Yes, as long as the object names differ. Every rectangle starts with the `InpObjPrefix` string, `”FVGIFVG_”` by default. When a second indicator writes objects under the same prefix, change one of them. Otherwise each tool deletes the other’s boxes on the next redraw.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the FVG & IFVG Indicator as one input. Always backtest before trading live.

Category: this is part of our Smart Money collection. Then, plainly, browse more Smart Money for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment