Discussing the article: "Automating Trading Strategies in MQL5 (Part 45): Inverse Fair Value Gap (IFVG)"

 

Check out the new article: Automating Trading Strategies in MQL5 (Part 45): Inverse Fair Value Gap (IFVG).

In this article, we create an Inverse Fair Value Gap (IFVG) detection system in MQL5 that identifies bullish/bearish FVGs on recent bars with minimum gap size filtering, tracks their states as normal/mitigated/inverted based on price interactions (mitigation on far-side breaks, retracement on re-entry, inversion on close beyond far side from inside), and ignores overlaps while limiting tracked FVGs.

The Fair Value Gap (FVG) is a price action concept representing imbalances or gaps between candles where buying or selling pressure created an unfilled void, often seen as bullish FVGs (low of later candle above high of earlier) or bearish FVGs (high of later below low of earlier), acting as potential support/resistance zones that price may retrace to fill. An Inverse Fair Value Gap (IFVG) occurs when a mitigated FVG (price broke the far side) is retraced into and then inverted by price closing beyond the far side from inside, signaling a reversal: a mitigated bullish FVG inverting bearish (price closes below low after re-entry) or mitigated bearish inverting bullish (closes above high). States track progression — normal (initial gap), mitigated (far-side break), retraced (re-entry after mitigation), inverted (close beyond far from inside post-retrace) — with inversion as the key trade signal.

In a mitigated bearish FVG (original down gap), a bullish IFVG triggers when price re-enters after mitigation and closes above the high, entering buy with stop-loss below low and take-profit at fixed points. Conversely, for a mitigated bullish FVG (original up), a bearish IFVG on close below low enters sell with stop-loss above high. Have a look below at the different setups we could have.

INVERSE FAIR VALUE GAP (IFVG) SETUPS

Our plan is to detect FVGs on recent bars with minimum gap filtering, load historical FVGs on initialization, track/update states (normal/mitigated/inverted) based on price interactions, ignore overlaps, limit tracked FVGs with cleanup of expired, trade inversions with buys on bullish IFVGs (orig down inverted) or sells on bearish (orig up inverted), fixed trade levels, trade modes/counts per FVG, trailing stops, and visualize colored rectangles (normal/mitigated/inverted shades) with state/trade labels and mitigation icons.

Author: Allan Munene Mutiiria