DEV Community

Cover image for Grid Trading Bot Backtest: How to Test One Honestly
Bot LAB
Bot LAB

Posted on Originally published at botlab.org.uk

Grid Trading Bot Backtest: How to Test One Honestly

A grid trading bot backtest is only useful if it models how grid orders actually fill, charges every fee and funding payment, and includes the moment price leaves your range. Most grid backtests look smooth because they skip at least one of those, so the honest test is less about the profit line and more about what happens at the edges.

This guide shows how to backtest a grid bot properly, where grid backtests usually lie, and how to read the result before you risk real money.

What a grid trading bot backtest has to prove

A grid bot places buy orders below the current price and sell orders above it, at fixed spacing. Each time price drops to a buy level and then rises back to the next sell level, the bot completes a "round trip" and books a small gain.

That design makes two promises your backtest must check:

  • In a range: many small round trips add up to more than fees.
  • Out of a range: the losses from holding inventory while price trends away do not erase everything the range earned.

A backtest that only shows the first part is half a test. Grid bots tend to look excellent in sideways data and fail in trending data, so the question is never "did it make money in this window?" but "what did it do in the windows it was not designed for?"

How to run a grid trading bot backtest step by step

1. Use data fine enough to see the fills

Grid levels are often 0.5–2% apart. On 1-hour or 4-hour candles, price can touch several levels inside one bar, and you cannot know the order in which it touched them.

  • If a single candle's high and low cross both a buy level and the sell level above it, a naive backtest books a full round trip. In reality the order may have been sell-first, or only one side filled.
  • Use 1-minute candles or trade data where you can. If you only have coarse candles, adopt a conservative rule: at most one fill per level per bar, and never a buy and its matching sell in the same bar.

2. Define a realistic fill rule

A limit order "touched" is not a limit order "filled". There is a queue in front of you.

  • Count a buy as filled only if price trades through the level (for example, one tick below), not just to it.
  • Run the test twice: once with touch-fills and once with trade-through fills. If the result collapses under the stricter rule, the edge was in the fill assumption, not the strategy.

3. Charge every cost

Grid bots trade a lot for small gains, so costs decide the outcome.

  • Fees: use your real maker and taker rates, both sides of every round trip. If some of your orders end up as taker (re-entries, stop-outs, market rebalances), charge taker for those.
  • Slippage: small on limit fills, real on any market order, especially exits during fast moves.
  • Funding: if you run a grid on perpetual futures, inventory held across funding times pays or receives funding. In a long trend against you, this adds up quietly. Include it from historical funding data, not an average guess.

4. Pick the range without peeking

This is the most common hidden bias in grid backtests. If you look at a chart, see that price stayed between two levels for three months, and then set your grid to exactly that range, you have used future information. Of course it worked: you drew the box around the answer.

Instead, set the range with a rule that only uses past data at the time, for example "range = last 30 days' high and low, recalculated weekly". Our guide on detecting look-ahead bias covers more ways this sneaks in.

5. Decide what happens at the edges

Your backtest must include an explicit rule for when price leaves the grid:

  • Stop the bot and close inventory at a loss?
  • Hold inventory and wait?
  • Shift the grid to follow price?

Each choice gives a very different equity curve. Whatever you choose, test it as part of the strategy, not as an afterthought.

6. Cover more than one market regime

Include at least one strong uptrend, one strong downtrend and one sideways period. A single calm month is a sample of one regime, as we put it in One sunny week isn't a climate.

Worked example: why the edges matter

Illustration only. These are made-up round numbers to show the arithmetic. They are not BOTLAB results and not a forecast.

Imagine a spot grid on a coin priced at 100 USDT:

  • Range 90 to 110, levels every 2 USDT (about 2% apart).
  • 1,000 USDT split into 10 orders of 100 USDT each.
  • Fee 0.1% per side.

Inside the range. One round trip on a 100 USDT order with a 2-point gap earns about 2 USDT gross. Fees on both sides cost about 0.20 USDT. Net is about 1.80 USDT. If the backtest shows 40 round trips in a month, that is roughly 72 USDT net.

Then price breaks down to 80. Five buy orders filled on the way down, at 98, 96, 94, 92 and 90. At a price of 80, each is now worth less:

| Buy price | Loss at 80 (per 100 USDT order) | |---|---| | 98 | about 18.4 USDT | | 96 | about 16.7 USDT | | 94 | about 14.9 USDT | | 92 | about 13.0 USDT | | 90 | about 11.1 USDT | | Total | about 74 USDT |

One move of 20% wipes out the whole month of round trips, before any slippage on an exit. If this were a leveraged futures grid, the same move could hit liquidation and add funding costs.

The lesson: a grid backtest that ends while price is still inside the range is showing you the 72 USDT and hiding the 74.

How to read the results honestly

Trade count overstates your sample

A grid bot can log hundreds of round trips in a few weeks. That looks like a big sample, but those trades are highly correlated: they all depend on the same thing, price staying in the range. Three hundred round trips inside one sideways month are closer to one observation of "sideways market" than to 300 independent tests. See how many trades a backtest needs for why the number of independent outcomes matters.

Win rate will look high, and mean little

Grid bots close winners often and hold losers as open inventory. A 90% win rate on closed trades can sit next to a large unrealised loss. Always judge on:

  • Equity including open positions, marked to market every bar.
  • Maximum drawdown, including unrealised losses.
  • Profit after all costs, divided by the worst drawdown.

Check for overfitting

If you tested 50 combinations of range width, grid count and spacing, then the best one will look good partly by luck. Signs of overfitting:

  • Results change sharply when you move spacing slightly (say 1.8% vs 2.0%).
  • The best settings differ a lot between one year and the next.
  • Performance depends on one or two big trending bars landing at the right moment.

Use walk-forward testing: choose settings on one period, then test them unchanged on the next. Our honest backtesting guide walks through the process.

Then forward test on paper

A backtest is a hypothesis. The next step is paper trading on live prices for long enough to see a range break, then comparing paper fills with what the backtest predicted. The gap between them, from fills, latency and fees, is information you cannot get from historical data.

How we judge bots at BOTLAB

We run every bot through 6 statistical gates (G1–G6), defined on the site, and publish paper trading (simulated money, real prices) results, losers included. Of 204 bots tracked as of 26 Oct 2026, 202 are NOT_READY. One, mr4h/long, has passed all 6 gates with 110 paper trades between 16 Aug and 26 Oct 2026, and even there our verdict is "sample too small to conclude". That is the standard we suggest for any grid bot: passing tests is a reason to keep watching, not proof of an edge.

If you already have a bot's trade log, you can run it through our free tool: Check your bot. Details of the hosted software and plans are on /platform.

FAQ

Is a grid trading bot profitable?

It can make money in ranging markets and lose money in trending ones, and nobody can know in advance which regime is coming. A backtest can tell you how the bot behaved in past regimes after costs. It cannot tell you future results. Our article on whether a trading bot is profitable explains how to test that question.

Can I backtest a grid bot for free?

Yes. You can use free historical candle data and a spreadsheet or open-source backtesting library, as long as you apply strict fill rules and real fees. Free paper trading on live prices is a good second step before any real money.

What is the best grid trading bot strategy?

There is no single best setting. A useful grid strategy is one whose range rule, spacing and exit rule survive walk-forward testing across several regimes, with acceptable drawdown when price leaves the range. Be cautious of any setting that only works on one period.

Should a grid bot use spot or futures?

Futures add leverage, funding costs and liquidation risk, which a backtest must model explicitly. Spot grids avoid liquidation but still carry inventory risk when price trends down. This is a general description, not a recommendation for your situation.

Key takeaways

  • A grid trading bot backtest must model fills, fees, slippage and funding, or it will overstate results.
  • Set the range with a rule that only uses past data; drawing the range on a chart is look-ahead bias.
  • Always test what happens when price leaves the range; that is where grid losses come from.
  • Hundreds of grid trades in one regime are not a large independent sample.
  • Judge on equity including open positions and max drawdown, then forward test on paper.

Not available in restricted jurisdictions (see the Service Agreement). You trade with your own exchange account; BOTLAB never holds funds.

Paper trading results are simulated. Past results don't predict future results. Crypto trading can lose money, including all capital. Not financial advice.

Want these checks run on your own strategy? See the strategy and backtest audit.


Originally published on BOTLAB. Score your own bot's trade log free: Check your bot.

Top comments (0)