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 Imbalance Inversion Retest strategy is a pure price-action, trend-continuation system built around the fair-value gap (FVG) — also called an imbalance — and what happens when that gap fails. A fair-value gap is a three-candle pattern where a fast middle candle moves so quickly that it leaves an "untraded void" between the wick of the first candle and the wick of the third. Many traders treat that void as a support or resistance zone that should hold. This strategy does the opposite: it waits for the void to break and then trades with the breaking move.
Critically, this approach uses no technical indicators. There are no moving averages, no RSI, no MACD — every level, filter, stop, and target is measured directly from raw candle highs and lows. The single "average" in the code is a plain mean candle range, calculated inline only to scale the strategy's thresholds to current volatility. In other words, it reads order flow through candle geometry alone, which makes it a clean teaching tool for understanding imbalance theory and displacement without the distraction of lagging indicators.
This is a momentum continuation strategy, designed with FX majors and gold (XAU) on the M15–H1 timeframes in mind, though it is not locked to any single timeframe. It is best suited to learners who already understand basic candlestick structure and want to study how "smart money" concepts like fair-value gaps, displacement, and inverted zones can be expressed as fully mechanical rules. It is framed here as a strategy analysis — a way to learn how the logic fits together — not as a profit opportunity.
How It Works
The strategy runs a small pipeline once per closed candle. Each step is pure candle geometry. Here is the logic in plain English:
- Volatility scaling first. The strategy measures the average candle range over a lookback window (
RangeLookback). This average sets the minimum gap size and the stop buffer, so the rules automatically adapt to whether the market is quiet or volatile.
- Detecting a fresh fair-value gap. Looking at the last three closed candles, the strategy identifies an imbalance. A bullish gap exists when the oldest candle's high is below the newest candle's low (an upward vacuum) and the middle candle is bullish. A bearish gap is the mirror image (a downward vacuum). The gap must be at least
MinGapFactor× average range to count — this filters out trivial, noise-sized gaps.
- Waiting for the inversion (the displacement gate). A gap only "inverts" when a strong displacement candle closes through it. A displacement candle is one whose body fills at least
DisplacementBodyPctof its total range — a sign of intentful order flow, not a drifting close. When a bullish gap is broken by a strong bearish candle that closes below it, that broken gap flips into a fresh supply (sell) zone. When a bearish gap is broken by a strong bullish candle that closes above it, it flips into a fresh demand (buy) zone.
- Entry — the equilibrium retest. Once a zone is inverted, the strategy waits for price to retrace back into the void and tag its 50% line (equilibrium). For an inverted supply zone, the strategy signals a SELL when price retraces up and the candle high tags the midpoint. For an inverted demand zone, it signals a BUY when price retraces down and the candle low tags the midpoint. This is a measured pullback entry in the direction of the break.
- Multi-zone tracking. Rather than holding a single bull/bear slot, the strategy tracks many candidate gaps and many inverted zones at once in rolling lists (capped at 16 each). Whichever level price retests first is the one that trades.
- Stop-loss logic. For a sell, the stop is placed just above the zone's top plus a buffer (
StopBufferFactor× average range). For a buy, the stop sits just below the zone's bottom minus the buffer. The buffer gives the trade room beyond the structural level.
- Take-profit logic. The target is a fixed reward-to-risk multiple (
RiskReward). The distance from entry to stop defines the risk, and the target is placed that same distance multiplied by the reward ratio in the trade's favor.
- Housekeeping. Gaps that never invert expire after
FvgExpirybars. Inverted zones expire afterRetestExpirybars or die early if price closes back through them (the gap is "reclaimed"). Only one position per magic number is held at a time.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| MinGapFactor | 0.25 | 0.05 | 1.50 | Minimum fair-value gap size as a fraction of the average candle range. Higher values demand larger, more significant gaps. |
| RangeLookback | 20 | 10 | 60 | Number of bars used to compute the mean candle range that scales all thresholds to volatility. |
| DisplacementBodyPct | 0.55 | 0.30 | 0.90 | Minimum body-to-range ratio for a candle to qualify as a displacement (break) candle. Higher values require more decisive moves. |
| FvgExpiry | 18 | 3 | 60 | Maximum number of bars a fresh gap may wait to invert before it is discarded. |
| RetestExpiry | 14 | 2 | 50 | Maximum number of bars an inverted zone waits for its equilibrium retest before expiring. |
| StopBufferFactor | 0.25 | 0.00 | 1.50 | Stop-loss buffer beyond the zone, as a fraction of the average candle range. |
| RiskReward | 2.0 | 1.0 | 6.0 | Fixed reward-to-risk ratio used to place the take-profit target. |
| Lots | 0.10 | 0.01 | 1.00 | Trade volume in lots. Should be adjusted to your account size and risk tolerance. |

Recommended Chart Settings
The Imbalance Inversion Retest strategy was tuned with FX majors (such as EUR/USD, GBP/USD) and gold (XAU/USD) in mind, on the M15 to H1 timeframes. These timeframes tend to produce fair-value gaps that are large enough to be meaningful while still occurring frequently enough to study. That said, the logic is deliberately not locked to any timeframe — it runs on whatever primary timeframe the chart provides.
Remember that results will vary significantly across different instruments, brokers, and market conditions. A setting that behaves well on one pair during a trending phase may behave very differently during a ranging or low-volatility phase. Always test on the specific symbol and timeframe you intend to study before drawing any conclusions.
How to Install on MetaTrader 5
- Download the
ImbalanceInversionRetest.ex5file from the link below. - Copy it to your MT5
MQL5\Expertsfolder. - Restart MetaTrader 5 or refresh the Navigator panel.
- Drag the EA onto a chart matching the recommended symbol and timeframe.
- Configure the input parameters and enable Algo Trading.
What to Consider Before Using This EA
Strengths of this approach. Because the strategy is pure price action, it is transparent and easy to reason about — every decision traces back to a candle high or low you can see on the chart. The displacement gate is a thoughtful filter: by requiring a strong-bodied candle to close through a gap, it ignores weak, drifting breaks and focuses on moments that historically reflect genuine order-flow shifts. The equilibrium retest also offers a structured, repeatable entry rather than chasing price, and the fixed reward-to-risk target enforces discipline on exits.
Known limitations. Fair-value gap and inversion concepts are popular, but they are interpretive — there is no universal definition, and this strategy's mechanical rules are one specific interpretation. Continuation trades can suffer in choppy, range-bound markets where gaps form and fail repeatedly without follow-through, producing a series of small losing trades. The fixed-R target means the strategy does not adapt its exit to changing momentum, so it may give back open profit on a target that never fills, or exit before a larger move completes. Slippage and spread — especially on gold — can also affect the precise fill at the equilibrium line.
Conditions where it may underperform. Low-volatility sessions, news-driven whipsaws, and tightly ranging markets are the classic challenges for any continuation system. The strategy may indicate signals that historically would have worked in a trend but struggle when no trend is present. Treat it as a framework for study, and observe how it behaves across many different market regimes before forming any view.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Consider these general principles as you study this or any strategy:
- Risk a small, fixed percentage per trade. Many educational sources suggest never risking more than 1–2% of your account on a single position. Adjust the
Lotsparameter so the distance to your stop reflects that percentage, rather than using an arbitrary lot size. - Use a demo account first. Test the strategy in a risk-free demo environment until you fully understand its behavior, its frequency of signals, and its typical drawdown.
- Understand drawdown. Every strategy experiences losing streaks. Know how many consecutive losses you could psychologically and financially tolerate before committing real capital.
- Diversify and avoid over-leverage. Concentrating risk in one instrument or using excessive leverage can amplify losses quickly.
- Keep a trading journal. Recording why each signal triggered and how it resolved is one of the most effective ways to learn from a mechanical system.
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
- Expert Advisor: ImbalanceInversionRetest.ex5 (5 downloads)
- Source Code: ImbalanceInversionRetest.mq5 (1 downloads)
- Documentation: ImbalanceInversionRetest.pdf (2 downloads)