> ## Content Index
> Fetch the complete content index at: https://stoic.ai/blog/llms.txt
> Use this file to discover other available public pages before exploring further.

# Fair Value Gap (FVG) Trading: What 7 Years of BTC and ETH Data Show
- URL: https://stoic.ai/blog/fair-value-gap-fvg-trading/
- Published: 2026-11-24T14:21:43.000Z
- Updated: 2026-11-24T14:22:44.000Z
- Description: Fair value gaps explained, with a test of every FVG on Bitcoin and Ethereum since 2019 and free code for TradingView, Python and Excel.
- Author: Alexander Schulz
- Tags: Trading Strategies

A fair value gap (FVG) is a three-candle pattern where the first and third candles don't overlap, leaving a price range that only the middle candle traded through. Traders expect price to come back and "fill" it. I tested every FVG on Bitcoin and Ethereum since 2019: price does come back, but trading the gap did not beat a random entry. Neither did any of the more than 50 variations I tried in search of an edge, from deeper entries and closer targets to betting on the fill itself.

**Key takeaways**

- On 1-hour and 4-hour BTC and ETH charts, 73–75% of fair value gaps were fully filled within 50 candles. Small gaps filled most often (83–84%), gaps wider than one average true range only 56–58% of the time.
- Small intraday gaps really are revisited more often than a random price zone at the same distance (83–84% against 71–72%). On the daily chart, gaps were no more "magnetic" than any other zone.
- Being revisited is not the same as being profitable. Buying bullish gaps and shorting bearish ones, with a stop beyond the first candle and a 2:1 target, broke even before fees and lost after them on every timeframe, the same as random entries with the same stop and target.
- Waiting for a deeper entry (the 50% level or a full fill) did not help. A trend filter helped on the 4-hour chart only, and lifted the result to breakeven, not to a profit.
- Inverse FVGs showed no edge either. Use gaps to map where price may react, and test any rule you add before you trade it. Free code with the exact rules, for Python, TradingView and Excel, is at the end.

## What Is a Fair Value Gap?

A fair value gap is a price range that the market crossed so fast that only one candle traded inside it. Take three consecutive candles:

- **Bullish FVG:** the low of the third candle is above the high of the first. The range between them is the gap.
- **Bearish FVG:** the high of the third candle is below the low of the first.

The middle candle is usually a large, fast one. In [Smart Money Concepts](https://stoic.ai/blog/smart-money-concepts-crypto/) it is called displacement, a sign that one side was in a hurry. The gap is the "imbalance" it left behind: a zone where buyers and sellers barely traded against each other, so the price there was never properly tested.

A real example from the Bitcoin daily chart (Binance BTC/USDT):

| Candle | Date             | High      | Low       |
| ------ | ---------------- | --------- | --------- |
| 1      | 24 February 2026 | 65,026.75 | 62,510.28 |
| 2      | 25 February 2026 | 69,988.83 | 63,913.27 |
| 3      | 26 February 2026 | 68,860.00 | 66,500.00 |

The low of candle 3 (66,500) stayed above the high of candle 1 (65,026.75), so 65,026.75–66,500 is a bullish fair value gap, about 2.2% of price wide. We will come back to how it played out.

Some traders call the gap a liquidity void or an imbalance. The term was popularised by ICT (Inner Circle Trader) teaching, which SMC grew out of; our [SMC guide](https://stoic.ai/blog/smart-money-concepts-crypto/) covers that background and the other concepts.

## How to Spot an FVG: The Exact Rule

Most charts show dozens of tiny gaps. If every one counts, the pattern means nothing, so I used one fixed rule for the whole test:

1. Bullish gap: low of candle 3 > high of candle 1\. Bearish gap: high of candle 3 < low of candle 1.
2. The gap must be at least **0.25 × ATR(14)**, the 14-period average true range of the middle candle. This drops gaps that are just noise.
3. The gap is known only at the close of candle 3\. Nothing before that close may use it.
4. A gap is **touched** when price trades back to its near edge (the top of a bullish gap), and **fully filled** when price reaches the far edge (the bottom of a bullish gap).

The same rule as ready-to-use code for Python, TradingView and Excel is at the end of this article.

Two traders using this rule will mark the same gaps. That is what makes FVGs testable, unlike [order blocks](https://stoic.ai/blog/smart-money-concepts-crypto/), where choosing the "right" candle is a judgement call.

## Do Fair Value Gaps Get Filled?

The most common claim about FVGs is that price "always comes back to fill the gap". To check it, I measured how often each gap was fully filled within 5, 20 and 50 candles. Then I added a control: for every gap, I placed a zone of the same width, at the same distance from price, on a random candle, and measured how often that was reached. If gaps attract price, they should be filled more often than random zones.

**Method:** Binance spot candles for BTC/USDT and ETH/USDT on the 1-hour, 4-hour and daily charts, gaps from 1 January 2019 to 31 October 2026\. That is 12,132 gaps on the 1-hour chart, 3,391 on the 4-hour and 633 on the daily.

**Share of gaps fully filled within 50 candles**

| Gap size (× ATR)                     | BTC 1h  | ETH 1h  | BTC 4h  | ETH 4h  | BTC daily | ETH daily |
| ------------------------------------ | ------- | ------- | ------- | ------- | --------- | --------- |
| 0.25–0.5 (small)                     | 83%     | 84%     | 84%     | 83%     | 76%       | 76%       |
| 0.5–1                                | 75%     | 77%     | 73%     | 73%     | 63%       | 71%       |
| More than 1 (large)                  | 56%     | 56%     | 56%     | 58%     | 45%       | 53%       |
| **All gaps**                         | **75%** | **75%** | **73%** | **74%** | **64%**   | **70%**   |
| Random zone, same width and distance | 65%     | 65%     | 66%     | 66%     | 68%       | 66%       |

**How to read it**

1. **The folklore is mostly true.** About three quarters of intraday gaps were fully filled within 50 candles, and more than a third within 5.
2. **Small gaps carry the effect.** Small 1-hour and 4-hour gaps were filled 83–84% of the time, against 71–72% for random zones of the same size. Large gaps filled about as often as random zones.
3. **On the daily chart there was no effect.** Daily gaps were filled 64–70% of the time, the same as random zones (66–68%).
4. **Most of the "magic" is just that markets retrace.** A random zone a similar distance away is reached two times out of three anyway. On intraday charts gaps were filled 7–10 percentage points more often than random zones; the effect is strongest for small gaps and gone for large ones.

## How Traders Trade an FVG, and What Each Entry Did

Knowing that price returns is not a strategy. The question is what happens after you enter there. I simulated the common textbook trade on every gap:

- **Direction:** long at a bullish gap, short at a bearish gap.
- **Entry:** a limit order, valid for 20 candles after the gap forms, at one of three levels: the near edge of the gap, its 50% level (ICT calls it "consequent encroachment"), or the far edge (a full fill).
- **Stop:** beyond the first candle of the pattern (its low for a bullish gap, its high for a bearish one).
- **Target:** 2R, twice the risk. If neither stop nor target was hit within 50 candles, the trade closed at the market.
- **Costs:** 0.1% per side. When a candle touched both the stop and the target, I counted a loss.
- **Control:** for every trade, five entries on random candles in the same direction, with the same stop distance (in %) and the same 2R target.

Results are in R, the risk per trade: +2 is a winner, −1 a full loss. A strategy needs a positive average R to make money.

**Average result per trade, in R (after fees unless stated)**

| Chart     | Trades (edge entry) | Entry at the edge | At 50% | At a full fill | Random entry, same stop and target | Edge entry before fees |
| --------- | ------------------- | ----------------- | ------ | -------------- | ---------------------------------- | ---------------------- |
| BTC 1h    | 4,683               | −0.25             | −0.31  | −0.49          | −0.24                              | −0.01                  |
| ETH 1h    | 5,155               | −0.16             | −0.21  | −0.34          | −0.18                              | +0.01                  |
| BTC 4h    | 1,324               | −0.09             | −0.10  | −0.16          | −0.12                              | +0.01                  |
| ETH 4h    | 1,411               | −0.07             | −0.11  | −0.15          | −0.05                              | +0.01                  |
| BTC daily | 228                 | −0.10             | −0.23  | −0.24          | −0.03                              | −0.07                  |
| ETH daily | 243                 | +0.03             | −0.06  | −0.11          | +0.09                              | +0.06                  |

**How to read it**

1. **Before fees, FVG trades broke even.** Across all 18 combinations the average was between −0.18R and +0.06R before costs. About a third of trades won (27–35%), which is exactly what a 2:1 trade needs just to break even.
2. **Random entries did the same.** With the same stop and target, entering on any candle gave a result statistically indistinguishable from entering at the gap in 17 of 18 cases. The gap told the trade nothing that a random entry didn't.
3. **Fees decide the outcome on low timeframes.** On the 1-hour chart the typical stop was only about 0.6–1.5% away, so a 0.2% round trip costs a big slice of each R. That is why the 1-hour rows lose most.
4. **A deeper entry does not save the trade.** Waiting for the 50% level or a full fill meant fewer fills and a stop closer to the entry. Each trade lost more, not less.
5. **A closer target did not help either.** With a 1:1 target instead of 2R, about half the trades won (41–52%), but the average still lost 0.05–0.57% per trade after fees on every chart, whether the entry was at the edge or at a full fill.

## Does Trading With the Trend Help?

A common answer to results like these is "you need confluence": only take bullish gaps in an uptrend and bearish gaps in a downtrend. I tested the simplest version, using the 200-candle moving average to define the trend.

| Chart     | With the trend: trades / average R | Against the trend: trades / average R |
| --------- | ---------------------------------- | ------------------------------------- |
| BTC 1h    | 2,998 / −0.25                      | 1,685 / −0.25                         |
| ETH 1h    | 3,294 / −0.18                      | 1,861 / −0.13                         |
| BTC 4h    | 859 / −0.01                        | 465 / −0.23                           |
| ETH 4h    | 899 / −0.03                        | 512 / −0.13                           |
| BTC daily | 134 / −0.21                        | 88 / +0.06                            |
| ETH daily | 153 / −0.00                        | 83 / +0.08                            |

On the 4-hour chart the trend filter clearly helped: on BTC it cut the loss from −0.23R to −0.01R per trade. But that is breakeven, not a profit. On the 1-hour chart it made no difference, and on the daily chart trend-following gaps did slightly worse (with few trades). A filter that works on one timeframe and not the others is a reason to keep testing, not to start trading.

## Inverse Fair Value Gaps

An inverse fair value gap (IFVG) is a gap that failed: price closed straight through it. Traders then flip the zone. A broken bullish gap becomes resistance, and a broken bearish gap becomes support, much like old support turning into resistance on a [support and resistance chart](https://stoic.ai/blog/how-to-identify-bitcoin-support-and-resistance-levels-trading-guide/).

I tested it the same way. If a candle closed beyond the far side of a gap within 20 candles, I placed a limit order at that far edge in the new direction, with the stop beyond the other edge of the gap and a 2R target.

| Chart     | Inverse FVG trades | Average R | Random entry, same stop and target |
| --------- | ------------------ | --------- | ---------------------------------- |
| BTC 1h    | 2,590              | −0.82     | −0.83                              |
| ETH 1h    | 2,825              | −0.60     | −0.59                              |
| BTC 4h    | 666                | −0.30     | −0.35                              |
| ETH 4h    | 778                | −0.26     | −0.28                              |
| BTC daily | 120                | −0.31     | −0.19                              |
| ETH daily | 126                | +0.01     | −0.24                              |

Inverse gaps lost about as much as random entries. On the 1-hour chart the stop (the width of the gap) is so tight that fees alone make the trade a clear loser. The ETH daily row looks better than random, but with 126 trades and dozens of comparisons in this test, one such result is what chance alone produces.

## Can You Trade the Gap Fill?

If three gaps in four get filled, why not bet on the fill itself? Sell right after a bullish gap appears, and take profit when price comes back down into it. I tested this "fade" in more than 50 versions on the same gaps.

**Method:** enter against the gap (short after a bullish gap, long after a bearish one) in one of three ways: at the close of the third candle, at the close of the first candle that turns back toward the gap, or with a limit order 0.5 ATR further in the gap's direction. Exit when price touches the near edge of the gap or fills it completely. Stop: just beyond the third candle, 1, 2 or 3 ATR away, or none at all (exit after 50 candles). Fees 0.1% per side, and every version has a random-entry control with the same stop and target distances. Because I tried so many versions, I picked the best one on 2019–2023 and judged it only on 2024 – October 2026.

**Fading the gap, average result per trade after fees (BTC and ETH, 1-hour, 4-hour and daily together)**

| Version                                                                               | 2019–2023 (random) | 2024–2026 (random) |
| ------------------------------------------------------------------------------------- | ------------------ | ------------------ |
| Best on 2019–2023: limit 0.5 ATR further, stop 2 ATR, exit at a full fill, small gaps | −0.09% (−0.25%)    | −0.19% (−0.23%)    |
| Third candle's close, stop 3 ATR, exit at a full fill, small gaps                     | −0.19% (−0.27%)    | −0.22% (−0.25%)    |
| Third candle's close, no stop, exit at the near edge, all gaps                        | −0.58% (−0.34%)    | −0.37% (−0.31%)    |
| First candle back, stop 1 ATR, exit at a full fill, all gaps                          | −0.39% (−0.21%)    | −0.30% (−0.20%)    |

**How to read it**

1. **A high hit rate is not an edge.** Without a stop, the trade reached the edge of the gap 87% of the time, and so did random entries with the same distances. When the target is close and the stop is far, you win often and lose big, and the average stays negative.
2. **The real edge is small, and it shrank.** On small gaps the target was reached 3–6 points more often than with random entries in 2019–2023, and only 1–2 points more often in 2024–2026\. Before fees, the best version made +0.11% per trade in the first period and +0.01% in the second, less than the 0.2% round-trip fee.
3. **Fading a fresh gap goes against momentum.** With the stop just beyond the third candle, every version lost money even before fees (−0.03% to −0.72% per trade) and usually did worse than random entries. Right after a gap, price usually keeps moving the gap's way first, and the fill comes only later.

**Using the fill to time an entry.** There is one more way to use it: if you plan to buy after a bullish gap anyway, place a limit order at the gap's edge instead of buying at the close. That order was touched within 20 candles 73–85% of the time and gave a better price: by a median 0.3–0.4% on the 1-hour chart, 0.6–0.8% on the 4-hour and 1.5–2.1% on the daily. But the trades you miss are the ones that run. When the limit was not touched, price had moved on by a median 1.8–2.5% (1-hour), 4.1–5.8% (4-hour) and 16–17% (daily) twenty candles later. Patience buys a better price on the weaker trades and costs you the strongest ones.

The fill is a fact about where price tends to go, not a free trade. I found no way to trade it that beat random entries after fees.

## Two Real Trades: One Worked, One Failed

Both are bullish gaps on the Bitcoin daily chart in 2026, traded with the exact rules above: a limit order at the top of the gap, a stop below the first candle, a 2R target.

**It worked: the gap of 24–26 February 2026.** This is the gap from the example above, 65,026.75–66,500\. The limit order at 66,500 filled on 27 February, when BTC dipped to 64,914 and went straight through the whole gap. The stop sat at 62,510 (the low of 24 February). BTC came within 520 dollars of it on 28 February (low 63,030), then turned up and hit the 2R target of 74,479 on 16 March. Result: **+12.0%**, or +2R.

**It failed: the gap of 3–5 March 2026.** After a rally to 74,050 on 4 March, BTC left a bullish gap between 69,258 (the high of 3 March) and 70,645 (the low of 5 March). The limit order at 70,645 filled on 6 March. The stop at 66,158 (the low of 3 March) was hit on 8 March, when BTC fell to 65,618\. Result: **−6.4%**, or −1R. A week later, on 16 March, BTC closed at 74,885.

The two trades look the same on the chart. One needed a stop 6% away and survived a scare; the other was stopped out by 540 dollars before the market went the "right" way. Over hundreds of gaps, these outcomes balanced out to roughly zero before fees. The stop still did its job: it kept the loser to the planned 1R. My [risk management framework](https://stoic.ai/blog/risk-management-in-crypto-battle-tested-framework-for-protecting-digital-assets/) covers how to size positions so that a 1R loss stays small.

## What This Test Does Not Cover

- **The mechanical pattern only.** Discretionary traders combine gaps with higher-timeframe structure, liquidity sweeps, session timing and their own judgement. A good trader may add real value; this test cannot see it.
- **A few stops and targets.** The main test used a stop beyond the first candle with 1:1 and 2:1 targets; the fade section adds ATR stops and gap-edge exits. Other exits would give other numbers, though the breakeven-before-fees results make a large hidden edge unlikely.
- **Many comparisons.** I ran about 30 comparisons in the main test, and two came out "significant" (above two standard errors). That is what chance alone would produce. For the fade I tried more than 50 versions, so I chose the best on 2019–2023 and judged it only on 2024–2026.
- **Overlap and correlation.** Gaps and trades overlap in time, and BTC and ETH move together, so the two coins are not independent proofs.
- **Spot only, assumed fills.** No funding costs, no slippage beyond the 0.1% fee, and limit orders are assumed to fill at the exact level.
- **One period.** January 2019 to October 2026, a rising market overall. Results by year were similar, with no year clearly profitable on the 4-hour chart.

## Can You Automate Fair Value Gaps?

Yes, easily: the rule is mechanical, which is why it was possible to test it. That also means a bot that trades FVGs on their own would have traded the tables above. Automation does not create an edge; it only applies a rule faster and without hesitation, so test the rule first. Our guide to [backtesting trading strategies](https://stoic.ai/blog/backtesting-trading-strategies/) covers how to do that without fooling yourself.

**Disclosure:** I work at Stoic AI. We run quantitative strategies built by professionals, not chart-pattern setups like FVGs, and we don't sell an FVG indicator or signal. This post has no affiliate links. Stoic connects to your exchange through API keys with trading permissions only, so your funds stay in your own account. If you would rather run a tested systematic strategy than mark gaps by hand, [see how Stoic AI works](https://stoic.ai/).

## Free Code: Find Fair Value Gaps in Python, TradingView or Excel

The same rule as above, ready to copy. I checked the Python code and the Excel formulas against the test data: they find exactly the same gaps, all 16,156 of them. The TradingView script applies the same rule on your chart.

PythonTradingViewExcel

Standard library only (Python 3.9 or newer), no pandas and no API key. The example downloads the last 1,000 four-hour BTC/USDT candles from Binance's public API and prints the five most recent gaps. Pass your own candles to `find_fvgs` to use another market or timeframe.

```python
# Find fair value gaps with the exact rules from Stoic AI's FVG test.
# Standard library only (Python 3.9+): no pandas, no API key.
import json
import urllib.request
from datetime import datetime, timezone

def find_fvgs(candles, min_atr=0.25):
    """candles: list of dicts with "high", "low", "close", oldest first.
    Returns (index of candle 3, side, bottom, top) for every gap."""
    atr = [None] * len(candles)
    first_trs = []
    for i in range(1, len(candles)):
        h, l, prev_close = candles[i]["high"], candles[i]["low"], candles[i - 1]["close"]
        tr = max(h - l, abs(h - prev_close), abs(l - prev_close))
        if i <= 14:
            first_trs.append(tr)
            if i == 14:
                atr[i] = sum(first_trs) / 14        # first ATR(14): simple average
        else:
            atr[i] = (atr[i - 1] * 13 + tr) / 14    # then Wilder's smoothing

    gaps = []
    for i in range(2, len(candles)):
        c1, c3, a = candles[i - 2], candles[i], atr[i - 1]  # candle 1, candle 3, ATR of candle 2
        if a is None:
            continue
        if c3["low"] > c1["high"] and c3["low"] - c1["high"] >= min_atr * a:
            gaps.append((i, "bullish", c1["high"], c3["low"]))
        if c3["high"] < c1["low"] and c1["low"] - c3["high"] >= min_atr * a:
            gaps.append((i, "bearish", c3["high"], c1["low"]))
    return gaps

if __name__ == "__main__":
    # The last 1,000 four-hour BTC/USDT candles from Binance's public API
    url = "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=4h&limit=1000"
    rows = json.load(urllib.request.urlopen(url))
    candles = [{"time": r[0], "high": float(r[2]), "low": float(r[3]), "close": float(r[4])} for r in rows]
    candles = candles[:-1]  # the last candle is still open
    for i, side, bottom, top in find_fvgs(candles)[-5:]:
        when = datetime.fromtimestamp(candles[i]["time"] / 1000, timezone.utc)
        print(f"{when:%Y-%m-%d %H:%M} UTC  {side:8}  {bottom:,.2f} – {top:,.2f}")
```

Open the Pine Editor in TradingView, paste the script and click Add to chart. It marks bullish gaps in green and bearish gaps in red, each at least 0.25 × ATR(14). Every gap stays on the chart; its box stops growing once price fills it completely.

It also replays the test's trades on your chart: ▲ or ▼ marks the entry (hover it for the stop and target), a line runs from entry to exit, dotted lines show the stop and the 2R target, and a label gives the result in R after fees. A table in the corner sums up all closed trades. It covers only the history loaded on your chart and TradingView's data feed, so expect numbers close to, but not the same as, my test.

In the settings you can switch the entry to the 50% level or a full fill, change the target, the fee and how long gaps are tracked, hide the trades, and set alerts for new gaps.

```pine
//@version=5
// Fair Value Gaps + test trades — the exact rules from Stoic AI's FVG test (stoic.ai/blog/fair-value-gap-fvg-trading/)
// Gaps: bullish if the low of candle 3 > the high of candle 1, bearish if the high of candle 3 < the low of candle 1,
// at least (min size x ATR14 of the middle candle). Every gap stays on the chart in its colour; it stops extending
// once price fills it completely or after N bars.
// Trades: a limit order at the gap edge (or 50% / far edge), valid for 20 bars; stop beyond candle 1; target 2R;
// exit at the close after 50 bars. A stop touched on the entry bar, or stop and target touched on one bar, counts
// as a loss (the test's conservative rule). Every gap is traded on its own, so several trades can be open at once.
// The table sums up the closed trades on the history loaded on your chart.
indicator("Fair Value Gaps + test trades", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500)

grpG    = "Gaps"
minAtr  = input.float(0.25, "Min gap size (x ATR14)", minval = 0, step = 0.05, group = grpG)
maxBars = input.int(50, "Track a gap for N bars", minval = 1, group = grpG)
bullCol = input.color(color.new(color.teal, 80), "Bullish FVG", group = grpG)
bearCol = input.color(color.new(color.red, 80), "Bearish FVG", group = grpG)

grpT       = "Trades (test rules)"
showTrades = input.bool(true, "Show entries and exits", group = grpT)
entryMode  = input.string("Gap edge", "Entry", options = ["Gap edge", "50%", "Full fill"], group = grpT)
rr         = input.float(2.0, "Target (R)", minval = 0.5, step = 0.5, group = grpT)
entryBars  = input.int(20, "Limit order valid for N bars", minval = 1, group = grpT)
holdBars   = input.int(50, "Close the trade after N bars", minval = 1, group = grpT)
feePct     = input.float(0.1, "Fee per side, %", minval = 0, step = 0.01, group = grpT)
showStats  = input.bool(true, "Show results table", group = grpT)

// Signed number for labels and the table, e.g. "+2.0" / "-1.0".
signed(x, fmt) => (x >= 0 ? "+" : "") + str.tostring(x, fmt)

atr14 = ta.atr(14)

// The gap is known at the close of the current bar (candle 3). Candle 1 = [2], candle 2 = [1].
bullGap = low > high[2] and (low - high[2]) >= minAtr * atr14[1]
bearGap = high < low[2] and (low[2] - high) >= minAtr * atr14[1]

// ---------- Gaps on the chart ----------
var array<box> gaps = array.new<box>()
var array<int> dirs = array.new<int>()
var array<int> born = array.new<int>()

if bullGap
    array.push(gaps, box.new(bar_index - 2, low, bar_index, high[2], border_color = na, bgcolor = bullCol))
    array.push(dirs, 1)
    array.push(born, bar_index)
if bearGap
    array.push(gaps, box.new(bar_index - 2, low[2], bar_index, high, border_color = na, bgcolor = bearCol))
    array.push(dirs, -1)
    array.push(born, bar_index)

// Walk backwards so removing an element does not skip the next one.
if array.size(gaps) > 0
    for i = array.size(gaps) - 1 to 0
        g   = array.get(gaps, i)
        d   = array.get(dirs, i)
        age = bar_index - array.get(born, i)
        box.set_right(g, bar_index)
        filled = age > 0 and (d == 1 ? low <= box.get_bottom(g) : high >= box.get_top(g))
        if filled or age >= maxBars
            array.remove(gaps, i)               // fully filled or stale: keep the box, stop extending it
            array.remove(dirs, i)
            array.remove(born, i)

// ---------- Trades ----------
var array<int>   tDir   = array.new_int()
var array<float> tEntry = array.new_float()
var array<float> tStop  = array.new_float()
var array<int>   tBorn  = array.new_int()
var array<int>   tFill  = array.new_int()      // -1 = the limit order is still waiting

var int   nTrades = 0
var int   nWins   = 0
var float sumR    = 0.0
var float sumRnet = 0.0
fmtR(total) => nTrades > 0 ? signed(total / nTrades, "0.00") + "R" : "—"

if showTrades and bullGap
    lvl = entryMode == "Gap edge" ? low : entryMode == "50%" ? (low + high[2]) / 2 : high[2]
    if lvl > low[2]
        array.push(tDir, 1)
        array.push(tEntry, lvl)
        array.push(tStop, low[2])
        array.push(tBorn, bar_index)
        array.push(tFill, -1)
if showTrades and bearGap
    lvl = entryMode == "Gap edge" ? high : entryMode == "50%" ? (high + low[2]) / 2 : low[2]
    if lvl < high[2]
        array.push(tDir, -1)
        array.push(tEntry, lvl)
        array.push(tStop, high[2])
        array.push(tBorn, bar_index)
        array.push(tFill, -1)

if array.size(tDir) > 0
    for i = array.size(tDir) - 1 to 0
        d    = array.get(tDir, i)
        e    = array.get(tEntry, i)
        s    = array.get(tStop, i)
        f    = array.get(tFill, i)
        risk = d * (e - s)
        tgt  = e + d * rr * risk
        done = false
        if f < 0
            age = bar_index - array.get(tBorn, i)
            if age > entryBars
                done := true                    // the limit order expired unfilled
            else if age > 0 and (d == 1 ? low <= e : high >= e)
                f := bar_index
                array.set(tFill, i, f)
                label.new(bar_index, e, d == 1 ? "▲" : "▼", style = label.style_none, size = size.normal,
                     textcolor = d == 1 ? color.teal : color.red,
                     tooltip = (d == 1 ? "Long " : "Short ") + str.tostring(e, format.mintick) + "\nStop " +
                     str.tostring(s, format.mintick) + "\nTarget " + str.tostring(tgt, format.mintick))
        if not done and f >= 0
            hitStop = d == 1 ? low <= s : high >= s
            hitTgt  = bar_index > f and (d == 1 ? high >= tgt : low <= tgt)
            float exitPx = na
            float r = na
            if hitStop
                exitPx := s
                r := -1.0
            else if hitTgt
                exitPx := tgt
                r := rr
            else if bar_index - f >= holdBars
                exitPx := close
                r := d * (close - e) / risk
            if not na(exitPx)
                done := true
                rNet = r - 2 * feePct / 100 * e / risk
                nTrades += 1
                nWins += rNet > 0 ? 1 : 0
                sumR += r
                sumRnet += rNet
                col = rNet > 0 ? color.teal : color.red
                line.new(f, s, bar_index, s, color = color.new(color.red, 30), style = line.style_dotted)
                line.new(f, tgt, bar_index, tgt, color = color.new(color.teal, 30), style = line.style_dotted)
                line.new(f, e, bar_index, exitPx, color = col, width = 2)
                label.new(bar_index, exitPx, signed(rNet, "0.0") + "R", style = label.style_label_left,
                     color = col, textcolor = color.white, size = size.small)
        if done
            array.remove(tDir, i)
            array.remove(tEntry, i)
            array.remove(tStop, i)
            array.remove(tBorn, i)
            array.remove(tFill, i)

// ---------- Results table ----------
var table stats = table.new(position.top_right, 2, 4, bgcolor = color.new(chart.bg_color, 10), border_width = 1)
if showStats and showTrades and barstate.islast
    table.cell(stats, 0, 0, "Closed trades", text_color = chart.fg_color, text_size = size.small, text_halign = text.align_left)
    table.cell(stats, 1, 0, str.tostring(nTrades), text_color = chart.fg_color, text_size = size.small)
    table.cell(stats, 0, 1, "Win rate (after fees)", text_color = chart.fg_color, text_size = size.small, text_halign = text.align_left)
    table.cell(stats, 1, 1, nTrades > 0 ? str.tostring(100.0 * nWins / nTrades, "0") + "%" : "—", text_color = chart.fg_color, text_size = size.small)
    table.cell(stats, 0, 2, "Avg per trade, before fees", text_color = chart.fg_color, text_size = size.small, text_halign = text.align_left)
    table.cell(stats, 1, 2, fmtR(sumR), text_color = chart.fg_color, text_size = size.small)
    table.cell(stats, 0, 3, "Avg per trade, after fees", text_color = chart.fg_color, text_size = size.small, text_halign = text.align_left)
    table.cell(stats, 1, 3, fmtR(sumRnet), text_color = chart.fg_color, text_size = size.small)

alertcondition(bullGap, "Bullish FVG", "New bullish fair value gap on {{ticker}} {{interval}}")
alertcondition(bearGap, "Bearish FVG", "New bearish fair value gap on {{ticker}} {{interval}}")
```

Works in Excel and Google Sheets. Put your candles in columns A–E (date, open, high, low, close), one candle per row, oldest first, with headers in row 1\. Column F is the true range, column G the ATR(14), and gaps appear in columns H (bullish) and I (bearish). Enter each formula in the cell shown, then fill F3, G17, H18 and I18 down to the last row; G16 holds the first ATR only. If your spreadsheet uses a comma as the decimal separator, use semicolons between the arguments.

```
F3   =MAX(C3-D3, ABS(C3-E2), ABS(D3-E2))
G16  =AVERAGE(F3:F16)
G17  =(G16*13+F17)/14
H18  =IF(AND(D18>C16, D18-C16>=0.25*G17), "Bullish "&C16&" to "&D18, "")
I18  =IF(AND(C18<D16, D16-C18>=0.25*G17), "Bearish "&C18&" to "&D16, "")
```

## Conclusion

Fair value gaps are a precise, testable way to describe fast moves, and the popular claim behind them is partly right: small intraday gaps are revisited more often than random price zones. But a revisit is not an edge. When I traded every gap on Bitcoin and Ethereum since 2019, the result was breakeven before fees and a loss after them, on every timeframe and every entry level, just like random entries with the same stop and target. Use gaps to map where price may react, combine them with a plan you have tested, and keep the stop where the idea is wrong. For the wider framework, see our [Smart Money Concepts guide](https://stoic.ai/blog/smart-money-concepts-crypto/); for timing intraday trades, my guide to [the best times to trade crypto](https://stoic.ai/blog/crypto-trading-24-7-best-times-market-overlaps-stoic-ai/).

## Frequently Asked Questions

### What is a fair value gap in trading?

A fair value gap (FVG) is a three-candle pattern where the first and third candles don't overlap, so only the middle candle traded through that price range. A bullish FVG forms when the third candle's low is above the first candle's high; a bearish FVG is the mirror image. Traders see it as an imbalance that price may revisit.

### Do fair value gaps always get filled?

No. In my test on BTC and ETH from 2019 to October 2026, about 73–75% of gaps on 1-hour and 4-hour charts were fully filled within 50 candles, and 64–70% on the daily chart. Large gaps (wider than one ATR) were filled only about half the time.

### Can you make money trading the gap fill?

Not in my test. I tried more than 50 ways to bet on the fill, with different entries, stops and exits. None beat random entries after the 0.2% round-trip fee, and the best version chosen on 2019–2023 lost 0.19% per trade in 2024–2026\. The fill happens often, but mostly because a nearby price level gets touched anyway.

### Are fair value gaps real?

The pattern is real and easy to define, and small intraday gaps were filled more often than random price zones. But trading them did not make money in my test: entering at the gap broke even before fees and lost after them, the same as entering at a random time with the same stop and target.

### What is an inverse fair value gap?

An inverse FVG is a gap that price closed straight through. Traders then use it from the other side: a broken bullish gap becomes resistance, a broken bearish gap support. In my test, trading inverse gaps on BTC and ETH did no better than random entries.

### What is the best timeframe for FVG trading?

In my test no timeframe gave an edge on its own. The 4-hour chart came closest: with a 200-candle trend filter, BTC gaps broke even after fees. On the 1-hour chart, fees on tight stops made FVG trades lose the most.

### What is the difference between an FVG and an order block?

A fair value gap is the price range a fast move skipped; an order block is the last opposite candle before that move, where large orders are thought to sit. FVGs follow a strict rule anyone can apply the same way, while choosing an order block takes judgement. Our [Smart Money Concepts guide](https://stoic.ai/blog/smart-money-concepts-crypto/) explains both.

## Sources

- [Binance spot API: market data endpoints (klines)](https://developers.binance.com/docs/binance-spot-api-docs/rest-api/market-data-endpoints): BTC/USDT and ETH/USDT 1-hour, 4-hour and daily candles used for the test and the examples (retrieved 17 and 24 November 2026)
- [TradingView Pine Script v5 documentation](https://www.tradingview.com/pine-script-docs/): the language of the indicator above
- [Our Smart Money Concepts guide](https://stoic.ai/blog/smart-money-concepts-crypto/): the earlier test of fair value gaps and liquidity sweeps on the 4-hour and daily charts