Log in Start free

How to backtest futures manually: costs, fills and the test window

A BTC breakout rule made +0.030R per trade before costs and lost 0.074R after fees and slippage. How to backtest futures so the test sees that.

Published
· upd.
Reading
8 min
Sections
8
By
Backcandle team
Feed
RSS →

A backtest answers one question: would these rules have made money on this data, at these costs. Most of the ways a backtest goes wrong come from the last two parts of that sentence, not the rules.

To make that concrete we took one plain rule and ran it on six and a half years of Bitcoin perpetual futures, changing nothing but the data window, the fill assumption and the costs. The same rule came out anywhere from +0.098R to −0.171R per trade. The method below is built around the things that moved it.

What data do you need to backtest futures?

Futures data comes in shapes that matter for a test:

  • Dated contracts expire. A test longer than one contract needs a continuous series stitched from consecutive contracts, and the stitching (raw or back-adjusted) changes the price levels you see. Know which one you have.
  • Crypto perpetuals never expire, but longs and shorts pay each other a funding rate at fixed times (every 8 hours in the Binance data we replay). A position held for days pays or earns it several times; a test that ignores it is testing a different instrument.
  • Markets with sessions (stocks, metals, energy) have overnight and weekend gaps. A stop that sits inside a gap fills at the next open, not at the stop.

Get candles at least one timeframe below the one you trade. You will need them for the fill question below.

How do you backtest futures manually?

A script needs code; a manual backtest needs a chart that reveals one bar at a time and a log. The steps are the same either way.

  1. Write the rules down before the first bar. Entry condition, invalidation, exit, position size, specific enough that a stranger could apply them. "Buy the pullback" is not a rule. "Buy the first higher low after a break of the prior day's high, stop below that low" is.
  2. Fix the costs and the fill rules before the first trade. Fee per side, slippage on stops, what happens when a bar touches both your stop and your target. These are part of the rules, and the next section shows why.
  3. Pick the window by date, not by the chart. Choose it before you look, or let something random choose it.
  4. Log every time the rules fire, including the trades you skip. If the rules fired forty times and you took twelve, you tested a discretionary filter you never wrote down.
  5. Read the result in R and as a distribution, not as a total. More on both below.

How much do fees and fills change the result?

The rule: on 1-hour BTC bars, when a bar closes above the highest high of the previous 24 bars, buy at the next open; below the lowest low, sell. Stop 1%, target 2%, one position at a time. Binance BTC perpetual, 1 January 2020 to 20 August 2026, 2,578 trades.

Costs were Backcandle's default rates: 0.04% per side for market orders, 0.02% for a target that fills as a limit order, plus 0.05% of adverse slippage on a stop. Results are in R, the profit per trade divided by the amount risked; R-multiples and expectancy has the formula.

Bar touching both levels counts as Costs Win rate Expectancy Total
Target first none 35.0% +0.051R +131R
Resolved on 5m candles none 34.3% +0.030R +77R
Resolved on 5m candles fees + slippage 34.3% −0.074R −191R
Stop first fees + slippage 33.5% −0.100R −258R

Two things happened.

The fill rule moved it by 0.021R. Only 40 of the 2,578 trades ended on a 1-hour bar that touched both the stop and the target, but each one swings 3R between a win and a loss. Counting all of them as wins, instead of checking the 5-minute candles, added 54R to the total. Stop and target hit in the same candle measures how often this happens and which assumption is closest to the truth.

Costs moved it by 0.104R and flipped the sign. The arithmetic is simple once you write it in R. With a 1% stop, 1R is 1% of the position. A winner pays 0.04% to enter and 0.02% to exit: 0.06R. A loser pays 0.04%, 0.04% and 0.05% of slippage: 0.13R. In the data, the average winner fell from 2.00R to 1.94R and the average loser grew from 1.00R to 1.13R. A rule that wins a third of the time pays the larger cost two times in three.

Costs in R scale with the inverse of the stop. Halve the stop to 0.5% and the same fees become 0.12R per winner and 0.26R per loser. Tight stops on short timeframes need a much larger gross edge to survive.

Funding on a perpetual is a further cost or credit this table leaves out. A rule that holds positions across several funding times should include it.

Does the window you choose change the result?

The same rule, gross (no fees), resolved on 5-minute candles, by calendar year:

Year Trades Expectancy, gross Expectancy, net
2020 393 +0.084R −0.018R
2021 513 −0.064R −0.171R
2022 408 −0.007R −0.112R
2023 295 +0.098R −0.003R
2024 389 +0.064R −0.039R
2025 351 +0.060R −0.043R
2026 (to 20 Aug) 229 +0.022R −0.082R

Test it on 2023 alone without costs and it looks like a tenth of an R per trade. Test it on 2021 and it looks broken. Neither is the rule; both are the window. After costs it lost money in every year, which is the honest summary.

Choosing the window after looking at the chart is how a backtest ends up on the 2023 row. Hindsight bias in backtesting measures how much picking with the answer visible inflates a result.

How many trades do you need?

More than feels necessary. Each trade of this rule is roughly +2R or −1R, and the standard deviation of the net results was 1.46R. Over 100 trades that leaves a standard error of about 0.15R on the average, larger than the whole difference between a good-looking result and a losing one.

We split the 2,578 net trades into 25 consecutive blocks of 100. The block averages ran from −0.360R to +0.162R, and 9 of the 25 blocks showed a profit, from a rule that lost money overall. A 100-trade manual test of this rule would have called it profitable a bit more than one time in three. How many trades to backtest goes further into sample size.

Can you backtest futures on TradingView?

Yes, two ways. The strategy tester runs a rule written in Pine Script, and by default it resolves each bar with the same nearest-extreme path described in the same-candle post; its Bar Magnifier, on the higher plans, uses lower-timeframe data instead. Bar Replay is the manual route: it starts at a past point you pick and steps forward one bar at a time, and you keep the log. The costs, the fill question and the window choice apply to both.

Reading the result

The total is the least informative number. Read, in this order:

  • Expectancy in R after costs. Is the average trade positive at all?
  • The spread. Best and worst 100-trade stretch, longest losing streak. Losing streak probability gives the streak your win rate should expect.
  • Max drawdown against what you would sit through. If the test's drawdown is larger than the one that would make you stop, you will not trade the rule as tested.
  • Exits by reason. A result carried by a few trades closed by hand, not by the stop or target, is a result about your discretion.

Running it as a manual backtest

A replay simulator does the bookkeeping and leaves you the decisions. In Backcandle, crypto sessions replay Binance perpetual-futures candles, the engine charges the session's fees, slips stops and applies the historical funding rates, and you can start from a random date range so the window is not yours to choose. You can switch timeframe mid-session to watch an exit on 5-minute bars.

Every session then has its own journal: win rate, profit factor, expectancy, max drawdown and the equity curve, exits by reason, and a trade table with exit type, MAE, duration and your notes. The arithmetic is not what takes the time. Following the rules when the next bar is unknown is.

Per-session statistics in Backcandle's journalPer-session statistics in Backcandle's journal
The numbers computed for every session: win rate, profit factor, average win and loss, max drawdown, expectancy.
Cumulative P&L of a replay sessionCumulative P&L of a replay session
The equity curve of the same 12 trades, trade by trade, ending at −$478.24.

How to structure a replay session covers the constraints worth fixing before the first bar. The script behind the tables is in our repository.

Practice it

Try it on
a real chart.

Read it, then replay it — bar by bar, with the right side of the chart hidden.

See all historic days → See all markets →
Keep reading

More from
the team.