Blog / Strategy
Strategy

Inverse Fair Value Gap Retest

Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy – including backtests – does not guarantee future results. Never trade with money you cannot afford to lose.

What Is This Strategy?

The Inverse Fair Value Gap Retest is a price-action reversal strategy for MetaTrader 5. It is built around the Inverse Fair Value Gap (IFVG) pattern, and its only indicator is the Average True Range (ATR). A fair value gap is a three-candle imbalance: the middle candle moves so far that the wicks of the candles on either side never overlap, which leaves a "void" where price moved in one direction only. The inverse idea is that when a later candle closes completely through that gap, the gap has failed. The strategy then treats it as a zone of the opposite polarity, so failed support becomes possible resistance, and failed resistance becomes possible support.

The Expert Advisor (EA) automates the whole process. It finds gaps on closed candles, tracks up to 64 of them at once, and waits for price to return to a flipped zone for the first time. ATR plays no part in finding signals. It only adds a small buffer to the stop-loss.

The strategy is meant for markets that make sharp displacement moves and then pull back, as major forex pairs and gold often do. As a learning tool, it suits traders who want to see how Smart Money Concepts-style patterns can be written as strict, testable rules that you can backtest and check trade by trade.

How It Works

The strategy works in three stages: detect, flip and enter.

Step 1: Detect a fair value gap (checked on every closed candle)

Step 2: Flip the gap when a candle closes through it

Step 3: Enter on the first retest (checked on every tick)

Stop-loss and take-profit logic

Rules that keep the system disciplined

inverse fair value gap retest
Illustrative example of the strategy’s entry and exit logic — not real trading results.

Strategy Parameters

Parameter Default Min Max Description
MaxGapAge 30 5 80 Maximum age of a gap in bars, counted from the candle that completed the pattern. Older gaps are discarded whether or not they have flipped.
AtrPeriod 14 5 50 Number of bars used to calculate ATR. It only sizes the stop buffer and never generates entries.
StopAtrMult 0.25 0.0 2.0 Stop padding past the gap's far edge, as a multiple of ATR. 0 puts the stop exactly on the edge.
RiskReward 2.0 1.0 5.0 Take-profit distance as a multiple of the stop distance. 2.0 means a 2R target.
MinGapPct 0.10 0.0 0.60 Minimum gap size as a fraction of the middle candle's range. 0 accepts every gap.
MaxPositions 1 1 5 Maximum number of trades this EA can have open at once on the symbol.
Lots 0.10 0.01 1.0 Fixed order volume, rounded to your broker's lot step and limits.

The EA also has a Magic input (default 7317), an ID it uses to recognise its own trades. If you run more than one copy on the same account, give each copy a different Magic number.

inverse fair value gap retest — MQL5 source code

Recommended Chart Settings

The Inverse Fair Value Gap Retest was designed for EURUSD, GBPUSD and XAUUSD (gold) on the M15 (15-minute) timeframe, but it runs on whatever timeframe the chart uses. Lower timeframes produce more gaps and more noise, and the spread takes up a bigger share of each trade's risk. Higher timeframes produce fewer, larger gaps and wider stops. Gold moves in larger ranges than the currency pairs, so check what the default lot size means in money terms before you test it there.

Results will vary across market conditions, including trends, ranges and news-driven moves. Entries are detected tick by tick, so backtest with "Every tick based on real ticks" modelling.

How to Install on MetaTrader 5

To find the folder, go to File → Open Data Folder in MT5. The file is named InverseFairValueGapRetest.ex5. To read or change the logic, open InverseFairValueGapRetest.mq5 in MetaEditor.

What to Consider Before Using This EA

Strengths

Limitations

Risk Management Tips

Risk Warning

Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.

Downloads

← Back to Blog