Skip to content

Free MT5 Expert Advisor

FVG Retest EA

MT5 Expert Advisor that trades the first retrace into a fair value gap left by a displacement candle in the trend direction, with ATR-based stops.

Smart moneyv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
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:

  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.
  2. The gap stays active for up to 30 bars. A close below the gap bottom invalidates it.
  3. 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.
  4. 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

InputDefaultWhat it changes
Displacement body (x ATR)1.2Strength of the middle candle
Minimum gap (x ATR)0.15Smallest gap the EA keeps
Gap max age (bars)30How long a gap stays valid
Require rejection closetrueEntry candle must close in trade direction
Stop buffer (x ATR)0.2Room beyond the pattern
Max stop (x ATR)3.0Skips very wide patterns
Trend EMAon, 200Direction filter
Risk % / Fixed lots1.0 / 0Position sizing
Take-profit (R)2.0Target distance (0 = none)
Max spread / hours30 points / 7 to 20Entry filters
Break-even / Trailingon at 1 R / offTrade 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.

Key inputs

Key inputs of FVG Retest EA
InputDefaultDescription
Displacement body (x ATR)1.2Minimum body of the middle candle of the three-candle pattern.
Minimum gap (x ATR)0.15Gaps smaller than this are ignored.
Gap max age (bars)30A gap that is not revisited within this many bars expires.
Require rejection closetrueThe retrace candle must close in the trade direction.
Trend EMA period200Only gaps in the EMA trend direction are traded.
Risk per trade (%)1.0Share of balance risked between entry and stop-loss.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors