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 Fair Value Gap Stack Rider is a pure price-action strategy built around the Fair Value Gap (FVG) — also called a three-candle imbalance, one of the most discussed ideas in the "smart money" trading community. An FVG is the empty space left on a chart when a strong middle candle pushes price so quickly that the wicks of the candle before it and the candle after it never overlap. Because the strategy reads only raw candle highs, lows, and closes, it uses no technical indicators at all — no moving averages, no oscillators, no lagging filters.
What separates this approach from a basic gap strategy is its central idea: a single Fair Value Gap appears almost everywhere and is mostly noise. The Stack Rider only pays attention when two or more unfilled gaps point the same direction within a short window of bars — a cluster the strategy calls "the stack." A stack is treated as a footprint of genuine institutional displacement, since a truly strong move tends to leave several imbalances behind in quick succession. The strategy then waits for price to pull back into the freshest gap and react before it commits to a trade.
As a learning tool, this strategy suits traders who want to understand displacement, market structure, and continuation entries in a systematic, rules-based way. It is designed for liquid, impulsive markets and timeframes — gold (XAUUSD) or an index on the M5–M15 charts are natural fits — although the code itself is timeframe-agnostic and will run on whatever primary timeframe you select. Treat it as a framework for studying how imbalances and trend continuation interact, not as a profit opportunity.
How It Works
The strategy evaluates the market once per fully closed bar and processes everything from the most recent trio of candles. Here is the logic in plain English:
- Building the average range: The strategy first measures the mean high-to-low range over a lookback window (
RangeLookback). This becomes the yardstick for deciding whether a candle is "strong" and for sizing the stop buffer. - Detecting a Fair Value Gap: On the newest three closed candles, the middle candle is checked for displacement — its body must be at least
MinDisplacementFactortimes the average range. If that middle candle is bullish and the prior candle's high sits below the later candle's low, a bullish gap is recorded. The exact mirror (bearish middle candle, prior low above later high) records a bearish gap. - Keeping the gap list clean: Each stored gap is pruned if it goes stale (older than
ExpiryBars) or if price closes straight through it — a bullish gap is discarded when a bar closes below its lower edge, and a bearish gap is discarded when a bar closes above its upper edge. A filled gap is considered invalidated. - Reading market structure: Trend is judged purely by comparing the latest close against the close
StructureLookbackbars ago. A higher close signals an up-structure; a lower close signals a down-structure. - Requiring a stack: The strategy signals interest only when at least
RequiredStacksame-direction gaps exist and the oldest and newest of them sit withinStackWindowbars of each other. It then identifies the freshest settled gap as the retrace target and the far edge of the whole cluster for stop placement. - The entry trigger (long): In an up-structure with a valid bullish stack, the strategy signals a Buy when the current bar dips into the freshest gap (price tags it) and then closes back up above the gap's lower edge — a bullish reaction showing the gap held. Entry is taken at the ask.
- The entry trigger (short): The short side is the exact mirror — a down-structure, a valid bearish stack, price tags the freshest gap from below, and the bar closes back down. Entry is taken at the bid.
- Stop-loss logic: Stops are structure-based, not fixed. For a long, the stop sits just beyond the far (lowest) edge of the entire gap cluster, minus a buffer of
StopBufferMulttimes the average range, so that a genuine fill of the stack invalidates the trade idea. The short side places the stop just above the cluster's highest edge plus the buffer. - Take-profit logic: The take-profit is a fixed reward-multiple of the measured risk. The distance from entry to stop is multiplied by
TakeProfitRRand projected in the trade's direction. - Position management: Only one position per magic number is allowed at a time, and the stop-loss and take-profit handle the exit. Once a trade is sent, the gap list is cleared so a fresh stack must rebuild before the next signal.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| Lots | 0.10 | 0.01 | 1.0 | Fixed trade volume in lots for each position. |
| MinDisplacementFactor | 1.20 | 0.8 | 3.0 | How large the middle candle's body must be, as a multiple of average range, to qualify as displacement. |
| RequiredStack | 2 | 1 | 4 | Minimum number of same-direction unfilled gaps needed to form a valid "stack." |
| StackWindow | 10 | 3 | 40 | Maximum number of bars allowed between the oldest and newest gap in the stack. |
| TakeProfitRR | 2.00 | 1.0 | 5.0 | Reward-to-risk multiple used to project the take-profit from the measured risk. |
| StopBufferMult | 0.40 | 0.0 | 2.0 | Extra cushion beyond the gap cluster edge for the stop, as a multiple of average range. |
| ExpiryBars | 18 | 4 | 60 | Number of bars after which an unfilled gap is considered stale and removed. |
| StructureLookback | 20 | 5 | 60 | Bars back used to judge trend by comparing closes. |
| RangeLookback | 14 | 5 | 50 | Window for the mean high-low range that scales displacement and the stop buffer. |

Recommended Chart Settings
The Fair Value Gap Stack Rider was designed with liquid, impulsive instruments in mind — XAUUSD (gold) or a major stock index are natural candidates — on the M5 to M15 timeframes, where fast displacement legs commonly leave clusters of imbalances. That said, the code is timeframe-agnostic and runs on whichever primary symbol and timeframe you attach it to. Because the strategy depends on impulsive displacement, its behavior will vary considerably across different instruments and market conditions; quiet, range-bound sessions will produce far fewer qualifying stacks than active, trending ones.
How to Install on MetaTrader 5
- Download the .ex5 file 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
The strength of this approach is its discipline. By demanding a stack of gaps rather than a single one, the strategy filters out much of the noise that makes lonely Fair Value Gaps unreliable, and it only engages on continuation after a pullback and a confirming reaction. Its stops and targets are anchored to actual structure — the gap cluster — rather than arbitrary fixed distances, which keeps risk tied to the trade thesis.
There are real limitations to understand. Fair Value Gaps are a popular concept precisely because they are easy to spot, but popularity does not make them predictive; many gaps never get respected. The "stack" requirement reduces trade frequency, so in slow or choppy conditions the strategy may sit idle for long stretches, and during sharp reversals a continuation entry can be caught on the wrong side as price reverses through the cluster. Because trend is judged by a simple close-versus-close comparison, the structure filter can misread complex or transitional markets. The strategy also clears its gap list after each trade, meaning it deliberately steps back rather than stacking multiple positions. None of these traits are flaws to be hidden — they are trade-offs you should study and test thoroughly before relying on the logic.
Risk Management Tips
Sound risk management matters more than any single entry technique. Consider these general principles as part of your education:
- Position sizing: Size each trade so that a loss at the stop represents only a small, predefined fraction of your account.
- The 1–2% rule: Many educators suggest risking no more than 1–2% of account equity on any single trade, so a string of losses does not threaten your capital.
- Use a demo account first: Test the strategy and its parameters on a demo account across varied market conditions before considering any live use.
- Understand drawdown: Every strategy experiences losing streaks. Study the historical drawdown so you understand the emotional and financial swings you may need to withstand.
- Keep records: Journaling trades and reviewing them helps you learn how the strategy behaves and whether its assumptions hold for your chosen market.
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: FairValueGapStackRider.ex5 (0 downloads)
- Source Code: FairValueGapStackRider.mq5 (0 downloads)
- Documentation: FairValueGapStackRider.pdf (0 downloads)