Gap fill strategy

On ES futures from January 2016 to July 2026, the gap fill strategy lost $35,570 after costs and made money in 3 of 11 years.

Mean reversionIntraday1-second barsBacktested Nov 6, 2026

Gap fill backtest, the result

Contract

E-mini S&P 500

  • −$35.6K

    Net after costs

    After $76,057 in fees and slippage

  • 3 of 11

    Years that made money

    January 2016 to July 2026

  • −$78.2K

    Largest drawdown

    Peak to trough, 1 contract

  • −$13

    Average trade

    2,664 trades

Gap fill on ES, net after costs by month, from January 2016 to July 2026: −$35,570; buying and holding one ES contract: +$236,212

Net after costs by month, January 2016 to July 2026.

Gap fill rules

When the market opens away from the prior close, trade back toward it: sell a gap up, buy a gap down.

A drawing of the rules on a made-up day, not a result.

  1. The gap is the 9:30 New York open less the prior day session's last price before 16:00.
  2. A gap up is sold short at the open and a gap down bought.
  3. The target is the prior close; the stop is as far beyond the open as the gap is wide.
  4. Whatever is still open is closed at 15:45 New York; one trade a day, and no gap means no trade.
Decides on
1-second bars
Holds
Nothing overnight
Parameters
open minute 570, close minute 960, exit minute 945

Results by year

It made money in 3 of 11 years on ES. Its best year was 2025, +$19,609, and its worst 2021, −$16,923.

Net after costs by year on ES, with trades, win rate, largest drawdown and buying and holding the same contract
YearNetTradesWin rateDrawdownBuy and hold
2016−$8,77725048%−$15,887+$11,497
2017−$5,46925049%−$7,424+$21,936
2018−$6,05225143%−$16,014−$8,589
2019−$9,76225045%−$14,770+$35,436
2020−$14,15025548%−$23,056+$27,761
2021−$16,92325347%−$20,345+$51,361
2022+$1,33225350%−$21,890−$45,939
2023−$4,64525050%−$20,511+$38,435
2024−$4,03525450%−$16,298+$42,947
2025+$19,60925150%−$15,293+$37,010
2026, Jan to Jul+$13,30414749%−$15,378+$24,355

Gap fill backtest results

On ES it made $40,488 before costs. Fees and slippage took $76,057, more than all of it.

Net = before costs − fees − slippage
ES: $40,488 − $9,457 − $66,600 = −$35,570
Every figure of the Gap fill backtest, by contract
FigureESNQ
Net after costs−$35,570+$66,798
Before costs+$40,488+$130,095
Fees$9,457$9,517
Slippage$66,600$53,780
Trades2,6642,681
Trades a year254255
Win rate48%49%
Profit factor0.961.05
Average trade−$13$25
Average trade, 95% interval−$49 to $23−$38 to $90
Sharpe ratio-0.220.23
Largest drawdown−$78,248−$57,720
Time in the market6%5%
Buying and holding the contract+$236,212+$401,004

The interval holds zero: this test cannot tell the average trade from no edge.

Gap fill code and Pine Script

The strategy as the backtest ran it, and the Pine Script our compiler wrote from it for TradingView.

Gap fill
gap_fill.py
1from atlantive import BUY, NEW_YORK, SELL, Bars, Session, Strategy2 3 4class GapFill(Strategy):5    """Fade the day session's opening gap, New York time, decided on one-second bars.6 7    The gap is the 9:30 open (the first one-second bar of the day session) less the prior day8    session's last price before 16:00. A gap up is sold short at the open and a gap down bought,9    with the prior close as the target and a stop as far beyond the open as the gap is wide. The10    target and the stop are tested on every one-second close; whatever is still open at 15:45 is11    closed. One trade a day; no gap, no trade.12    """13 14    data = "bars"15 16    class Params:17        open_minute: int = 57018        close_minute: int = 96019        exit_minute: int = 94520        clip: int = 121 22    class State:23        clock: Session(zone=NEW_YORK)24        bars: Bars(interval_ns=1_000_000_000)25        prior_close: float26        prior_day: int27        day_close: float28        day_close_day: int29        target: float30        stop: float31        traded_day: int32 33    def on_event(self, view, ev, orders):34        self.clock.update(ev)35        if not self.bars.update(ev):36            return37        minute = self.clock.prev_minute38        second = self.clock.prev_second39        day = self.clock.prev_day40        close = float(self.bars.prev_close)41        opening = float(self.bars.prev_open)42        # The one-second bar that just closed ends at second + 1.43        late = second + 1 >= self.p.exit_minute * 60 or day != self.traded_day44        if view.position < 0:45            if close <= self.target or close >= self.stop or late:46                orders.ioc(side=BUY, qty=self.p.clip)47        elif view.position > 0:48            if close >= self.target or close <= self.stop or late:49                orders.ioc(side=SELL, qty=self.p.clip)50        if minute >= self.p.open_minute and minute < self.p.close_minute:51            if self.day_close_day != day:52                # The first bar of a new day session: yesterday's last close becomes the prior close.53                if self.day_close_day != 0:54                    self.prior_close = self.day_close55                    self.prior_day = self.day_close_day56                self.day_close_day = day57                if self.prior_day != 0 and view.position == 0 and self.traded_day != day:58                    gap = opening - self.prior_close59                    if gap > 0:60                        orders.ioc(side=SELL, qty=self.p.clip)61                        self.target = self.prior_close62                        self.stop = opening + gap63                        self.traded_day = day64                    elif gap < 0:65                        orders.ioc(side=BUY, qty=self.p.clip)66                        self.target = self.prior_close67                        self.stop = opening + gap68                        self.traded_day = day69            self.day_close = close
1//@version=62// GapFill, exported from Atlantive.3// Chart simulation: decisions use completed bars; market orders fill at the next bar open.4// Native fills, fees, data gaps and session boundaries can differ. Re-test on the target symbol.5// Use standard time-based candles and the strategy's timeframe, not synthetic chart prices.6// Pine v6 trims old trade records at its order limit; the strategy keeps calculating.7// Margin is explicitly disabled to retain the native signal simulation's sizing.8strategy("GapFill", overlay=true, initial_capital=100000.0, commission_type=strategy.commission.cash_per_contract, commission_value=1.68, default_qty_type=strategy.fixed, default_qty_value=1, calc_on_every_tick=false, process_orders_on_close=false, slippage=0, margin_long=0, margin_short=0)9 10if timeframe.in_seconds() != 111    runtime.error("GapFill was exported for the 1 second timeframe; set the chart to 1S.")12 13open_minute = input.int(570, "open_minute", minval=-9007199254740991, maxval=9007199254740991)14close_minute = input.int(960, "close_minute", minval=-9007199254740991, maxval=9007199254740991)15exit_minute = input.int(945, "exit_minute", minval=-9007199254740991, maxval=9007199254740991)16clip = input.int(1, "clip", minval=-9007199254740991, maxval=9007199254740991)17 18_q_safe_int(x) =>19    if math.abs(x) > 900719925474099120        runtime.error("an integer left the exact chart range; this run cannot be compared faithfully")21    int(x)22_q_int(x) => _q_safe_int(x < 0 ? math.ceil(x) : math.floor(x))23_q_iadd(a, b) => _q_safe_int(a + b)24_q_imul(a, b) =>25    if a != 0 and math.abs(b) > 9007199254740991 / math.abs(a)26        runtime.error("an integer multiplication left the exact chart range; this run cannot be compared faithfully")27    _q_safe_int(a * b)28 29_q_open = _q_int(math.round(open * 1000000000.0))30_q_close = _q_int(math.round(close * 1000000000.0))31 32var float prior_close = 0.033var int prior_day = 034var float day_close = 0.035var int day_close_day = 036var float target = 0.037var float stop = 0.038var int traded_day = 039// clock: completed chart bar's opening timestamp (America/New_York).40_q_clock_prev_minute = hour(time, "America/New_York") * 60 + minute(time, "America/New_York")41_q_clock_prev_second = _q_clock_prev_minute * 60 + second(time, "America/New_York")42_q_clock_prev_weekday = (dayofweek(time, "America/New_York") + 5) % 743_q_clock_prev_day = int(timestamp("UTC", year(time, "America/New_York"), month(time, "America/New_York"), dayofmonth(time, "America/New_York"), 0, 0) / 86400000)44// Current clock: this chart bar's scheduled close, known without a future bar.45// A native next event after a data gap can carry a later time.46_q_clock_minute = hour(time_close, "America/New_York") * 60 + minute(time_close, "America/New_York")47_q_clock_second = _q_clock_minute * 60 + second(time_close, "America/New_York")48_q_clock_weekday = (dayofweek(time_close, "America/New_York") + 5) % 749_q_clock_day = int(timestamp("UTC", year(time_close, "America/New_York"), month(time_close, "America/New_York"), dayofmonth(time_close, "America/New_York"), 0, 0) / 86400000)50_q_clock_seen = 151int minute_l = na52int second_l = na53int day = na54float close_l = na55float opening = na56bool late = false57float gap = na58 59minute_l := _q_int(_q_clock_prev_minute)60second_l := _q_int(_q_clock_prev_second)61day := _q_int(_q_clock_prev_day)62close_l := _q_close * 1.063opening := _q_open * 1.064late := _q_iadd(second_l, 1) >= _q_imul(exit_minute, 60) or day != traded_day65if _q_int(strategy.position_size) < 066    if close_l <= target or close_l >= stop or late67        _q_qty1 = _q_int(clip)68        if _q_qty1 <= 069            runtime.error("market order quantity must be a positive whole unit")70        _q_pos1 = _q_int(strategy.position_size)71        if _q_pos1 > 0 or _q_pos1 < 0 and _q_qty1 < -_q_pos172            runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")73        strategy.order("q1", strategy.long, _q_qty1)74else if _q_int(strategy.position_size) > 075    if close_l >= target or close_l <= stop or late76        _q_qty2 = _q_int(clip)77        if _q_qty2 <= 078            runtime.error("market order quantity must be a positive whole unit")79        _q_pos2 = _q_int(strategy.position_size)80        if _q_pos2 < 0 or _q_pos2 > 0 and _q_qty2 < _q_pos281            runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")82        strategy.order("q2", strategy.short, _q_qty2)83if minute_l >= open_minute and minute_l < close_minute84    if day_close_day != day85        if day_close_day != 086            prior_close := day_close87            prior_day := _q_int(day_close_day)88        day_close_day := _q_int(day)89        if prior_day != 0 and _q_int(strategy.position_size) == 0 and traded_day != day90            gap := opening - prior_close91            if gap > 092                _q_qty3 = _q_int(clip)93                if _q_qty3 <= 094                    runtime.error("market order quantity must be a positive whole unit")95                _q_pos3 = _q_int(strategy.position_size)96                if _q_pos3 < 0 or _q_pos3 > 0 and _q_qty3 < _q_pos397                    runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")98                strategy.order("q3", strategy.short, _q_qty3)99                target := prior_close100                stop := opening + gap101                traded_day := _q_int(day)102            else if gap < 0103                _q_qty4 = _q_int(clip)104                if _q_qty4 <= 0105                    runtime.error("market order quantity must be a positive whole unit")106                _q_pos4 = _q_int(strategy.position_size)107                if _q_pos4 > 0 or _q_pos4 < 0 and _q_qty4 < -_q_pos4108                    runtime.error("this order would add to or partially reduce a position, so its trade ledger would not be faithful")109                strategy.order("q4", strategy.long, _q_qty4)110                target := prior_close111                stop := opening + gap112                traded_day := _q_int(day)113    day_close := close_l

How it was tested

The published rules, never tuned on the data, with real costs on every fill. Every strategy here is tested the same way.

Market data
CME Globex 1-second bars, Jan 2, 2016 to Jul 31, 2026
Rules
As published, with the published parameters, never tuned on this data
Size
1 contract on every trade
Contract
The most traded one, rolled as the market moved
Fees
The broker's $0.50 a side, plus CME's and the NFA's fees when the window opens
Slippage
1 tick a side on ES, 2 in NQ's regular session and 3 outside it, 1 on other markets, where it was not measured
Stops and entries
Tested on 1-second closes and filled at the next bar
Contracts traded
ES: 43 contracts, ESH6 to ESU6NQ: 43 contracts, NQH6 to NQU6
Costs paid
ES: $9,457 in fees, $66,600 in slippageNQ: $9,517 in fees, $53,780 in slippage
Warm-up
None: each contract reads only its own bars
Flagged days
ES: NoneNQ: None Days the data holds too few bars for. Flagged, not removed.

Could you pass
a prop firm challenge
with the gap fill strategy?

A backtest says whether a strategy makes money. Our AI runs its trades through the rules of every prop firm account, then tells you which one it would pass and at what size.

No card needed. Free credits every month.

  • Most money: Blue Guardian Futures Direct 50K, $5,084
  • Best payout odds: Funded Futures Family Straight to Funded 50K, 98%
  • Fastest pass: Phidias Express to Live 50K, 11 days
Blue Guardian Futures Direct 50K
Most money

$5,084

Median net across 2,000 simulated runs

Evaluation
None
First payout
97%
Fees paid
$1,521

Median net across 2,000 simulated runs

Best 5%$13,143Worst 5%−$412
Day 060120180
Example: ES opening range breakout

Questions about the gap fill strategy

What is the gap fill strategy?

When the market opens away from the prior close, trade back toward it: sell a gap up, buy a gap down. Atlantive backtested it on CME futures from January 2016 to July 2026 after costs.

Is the gap fill strategy profitable on ES futures?

Not in this backtest: on ES futures from January 2016 to July 2026 it lost $35,570 after costs, over 2,664 trades, positive in 3 of 11 years; on NQ it made $66,798. Buying and holding one ES contract over the same window made $236,212. The average trade was −$13, its 95% interval −$49 to $23. These are hypothetical results of a backtest, not of trading.

What are the gap fill strategy's rules?

The gap is the 9:30 New York open less the prior day session's last price before 16:00. A gap up is sold short at the open and a gap down bought. The target is the prior close; the stop is as far beyond the open as the gap is wide. Whatever is still open is closed at 15:45 New York; one trade a day, and no gap means no trade. Its parameters are the published ones, never tuned on the data it was tested on.

How was the gap fill strategy backtested?

On CME Globex data from January 2016 to July 2026, one contract, on 1-second bars, rolled to the most traded contract as the market moved, with the broker's and CME's fees and the slippage measured on each market. Stops and entries were tested on 1-second closes and filled at the next bar. Nothing was fitted to the data.

Can I run the gap fill strategy in TradingView?

Yes. The page carries its Pine Script, written by Atlantive's compiler from the same code the backtest ran, for TradingView's strategy tester. A chart's fills and fees can differ from the backtest's, so test it again on the symbol you trade.

Can I change the gap fill strategy and test it again?

Yes. Rerun it in Atlantive: a new chat opens with the strategy's rules in the box, for you to read, change and send. The agent writes the code, backtests it on the market and window you name, and reports the result with its costs.

Rerun it in Atlantive. Change the market, the dates or a rule, then send it.

A new chat opens with this in the box

Backtest a gap fill strategy on ES, 2016-01-02 to 2026-07-31, one contract on a $100,000 account with default costs: at the 9:30 New York open, fade the gap from the prior day session's 16:00 close, target the prior close, stop as far beyond the open as the gap is wide, tested on one-second closes, flat at 15:45.

Never sent for you

May we measure this visit?

With your consent, Google Analytics and PostHog count visits to these pages. You can separately allow Google Ads to measure visits from our ads. Visit measurement starts only after you choose. Cookie policy