- Strategy
- Buys when price first retraces into a bullish fair value gap created by a strong bullish candle above the trend EMA and closes back up; sells on the mirror image in a downtrend.
- Risk model
- 1% of balance per trade (configurable), stop-loss beyond the three-candle pattern on every order, one position per symbol and magic number
What it does
A fair value gap (FVG) is a three-candle pattern where a strong middle candle moves so fast that the first and third candles do not overlap. The empty space between them is often revisited. FVG Retest EA marks those gaps when they form in the trend direction and trades the first retrace into each one.
Every order carries a stop placed beyond the whole pattern, and size comes from your risk percentage.
How it works
The EA works on closed candles at the start of each new bar. Call the three most recent closed candles 3 (oldest), 2 and 1:
- Bullish gap: candle 2 is bullish with a body of at least 1.2 ATR, and the low of candle 1 is above the high of candle 3. The gap runs from candle 3's high (bottom) to candle 1's low (top) and must be at least 0.15 ATR tall. With the trend filter on, candle 1 must close above the 200 EMA.
- The gap stays active for up to 30 bars. A close below the gap bottom invalidates it.
- The first candle whose low enters the gap uses it up. If that candle closes above the gap bottom, and (by default) closes bullish, the EA buys at market.
- The stop is placed below the lower of candles 2 and 3, minus 0.2 ATR. The target is 2 R.
Bearish gaps are the exact mirror. One gap per direction is tracked; a new gap replaces the previous one.
How to use it
FVGs appear most clearly on M5 to H1 charts during active sessions. A higher displacement multiple keeps only strong moves; switching off the rejection requirement gives more trades but enters against momentum more often. Use the trading-hours input to avoid quiet periods, when gaps are small and spreads are relatively large.
Settings
| Input | Default | What it changes |
|---|---|---|
| Displacement body (x ATR) | 1.2 | Strength of the middle candle |
| Minimum gap (x ATR) | 0.15 | Smallest gap the EA keeps |
| Gap max age (bars) | 30 | How long a gap stays valid |
| Require rejection close | true | Entry candle must close in trade direction |
| Stop buffer (x ATR) | 0.2 | Room beyond the pattern |
| Max stop (x ATR) | 3.0 | Skips very wide patterns |
| Trend EMA | on, 200 | Direction filter |
| Risk % / Fixed lots | 1.0 / 0 | Position sizing |
| Take-profit (R) | 2.0 | Target distance (0 = none) |
| Max spread / hours | 30 points / 7 to 20 | Entry filters |
| Break-even / Trailing | on at 1 R / off | Trade management |
Limitations
Gaps are common, and many are filled completely without any reaction. Entries happen at the close of the retrace candle, so the price can be some distance inside the gap. The stop beyond the full pattern can be wide after big candles, which shrinks position size. Low-timeframe gaps are sensitive to spread and data quality.
Before you run it live
Test the EA in the Strategy Tester on real-tick data and then on a demo account for several weeks. Check your broker's spread at the hours you trade and set the spread limit accordingly. Keep the risk per trade small at first, and read about volatility since all the ATR-based settings scale with it. Trading carries a substantial risk of loss.

