Help ›

Strategy Lab: Grid Backtest

Strategy Lab > Grid Backtest tests a grid on one asset over its past candles. A grid puts buy orders at steps below the price and a sell order one step above each buy. Every time the price goes down a step and back up, that step's profit is kept. It earns while the market moves sideways, and loses when the price falls out of its range. The page shows how one grid would have done, next to simply holding the coin. Like the Signal Backtest, it is open to admins only for now. Past results do not promise future ones.

How a grid works

  • Range and steps: the range from a low to a high price is cut into steps. With 20 steps there are 21 levels, and the money is split into 20 equal parts, one per step.
  • The start: for every step above the price, the coin is bought at once (at the market), so it can be sold one step higher. The other steps wait with their money to buy at their level. Or choose Start: in cash, buy level by level: nothing is bought at the start; a step above the price waits until the price has been above it, then buys at its level when the price comes back down. It buys only on the way down, so it holds less coin when the price falls, and earns nothing while the price only rises. Test both on the same coin and period to compare.
  • A buy fills when a candle's low goes below its level; then a sell waits one step higher. A sell fills when a candle's high goes above its level; that is one round trip, and its money waits to buy again. A price that only touches a level does not fill it.
  • One change per step per candle: a candle's high and low do not say which came first, so a step bought in a candle sells in a later one. The test counts fewer round trips than a real grid would make, never more. Shorter candles (1m, 5m, 15m) come closer to real, but cover fewer days: a test reaches back about 40 days on 1m, 200 on 5m and 600 on 15m; 1H reaches back years.
  • The fee is paid on every buy and sell. A step must be wider than the fee paid twice, or it keeps nothing: the page shows the smallest step and what it keeps under Steps, and refuses a grid that keeps nothing.

The range

  • The price +- %: from the price at the start, e.g. +- 10 %. It follows the price, so a grid tested on 2022 means something today. The algo brain searches it, the last days and the area.
  • The last days' low and high: the lowest and highest price of the last days before the start (e.g. 30). The candles before From are needed, so From must be that many days after the history begins. When those days were too quiet for the fees, the grid waits in cash until the range is wide enough.
  • The area where the price goes up and down: is the price now in a place where it keeps going up and down? Over the last days (e.g. 30) the page counts how many times the hourly closes crossed the price now, and how far they went above and below it between two crossings. With at least the Crossings you ask for (e.g. 10), the range runs from the price minus the fall that 80 % of the swings stayed within to the price plus the rise 80 % stayed within. With fewer, there is no area: the grid waits in cash and looks again each hour. Example: BTC at 100,000 crossed 100,000 fourteen times in 30 days, its swings mostly within -2 % and +3 %: the range is 98,000 to 103,000. A rebuild looks for a new area around the new price; in a long trend that buys high and sells low again and again, so try wait too.
  • Fixed prices: a low and a high in USDT, e.g. 60,000 to 70,000 for BTC. Good to try today's idea, but a fixed range found on old prices says little about the future. Saved and started later, after the price has left it, the Trading Strategies page warns you at Start.
  • Spacing: the same % apart (each step the same share of the price) or the same USDT apart (the steps near the top are then a smaller %) or from the ATR: each step is Step = ATR x times the coin's ATR, its average move in an hour over the last 14 hours, measured each time the grid is built. The levels are laid out from the price, one step apart, up to the range's edges, and Steps then means at most that many. A step is never smaller than one that keeps 0.1 % after the fee paid twice. Example: ETH moving 0.8 % an hour, ATR x 1, +- 10 %: steps of 0.8 %, about 12 above and 12 below the price, so Steps 20 keeps the 10 nearest on each side.

When the price leaves the range

  • Wait: nothing changes. Above the range the grid holds only cash. Below it, it holds only the coin. It goes on when the price comes back.
  • Rebuild around the price: when a candle closes out of the range, a new range is built around the close with all the money. Only the difference in the coin is bought or sold at the market, and a fall sells some coin at the low. Not for a fixed range.
  • Sell everything and end: sells at the close and the grid ends.
  • Follow the price: when a candle closes above the range, the lowest step is dropped and a new one is added above, one step at a time, until the price is inside again. The step at the price is bought at the market, so it sells one step higher. Nothing else is sold and started again. Tick Follow it down too to do the same below the range: the top step's coin is then sold at a loss and a buy is added below. The stop moves up with the range, never down. The result counts the range moves.
  • Stop below the range (optional): when the price falls this % below the range's low, the grid sells everything at the stop and ends. In that candle the buys it passed fill first, the worst case.
  • Take-profit on the whole grid (optional): when the grid's value (its cash and its coin at the close) is this % above the money put in, it sells everything and ends. Example: 1,000 USDT and 20 %: it ends at 1,200.
  • Trailing stop on the whole grid (optional): when the grid's value falls this % below the best value it has had, it sells everything and ends. It counts from the start, so it is also a stop-loss: with 10 %, a new grid of 1,000 ends at 900; one that went up to 1,300 ends at 1,170.

Money and costs

Money is pretend money: what the grid starts with, as if you put it in. Nothing is bought. It is split over the steps (1,000 USDT over 20 steps is 50 a step), so the profit shows in USDT, and each step must reach Binance's smallest order (5 USDT). Big money on a small coin also costs more with Real costs.

Resting orders pay only the fee (0.1 % a side by default, as the Paper Bot). With Real costs, the orders at the market (the start, a rebuild, the stop, a sell) also pay the spread and the market impact, estimated per coin and order size, as the Signal Backtest does.

The result

  • Return and Holding the coin: the money at the end, against the same money put into the coin at the start, and both on the unseen last 30 % of the period.
  • Grid profit: what the round trips kept after the fees. The return also counts the coin the grid still holds, so a grid can keep a good grid profit and still lose when the coin fell.
  • Worst drop: the biggest fall of the money from a high, day by day, and holding's.
  • Costs paid, Closes in the range and how many times it was rebuilt.
  • Price and fills: the price with the newest 300 fills; The money each day against holding (dashed); Levels at the end.

The grid pass rule

A grid passes when both of these hold: at least 30 round trips (enough to be a grid, not one lucky move), and a worst drop of at most 30 %. The money it made is not a condition: the return, holding the coin and the unseen last 30 % are shown for you to judge, but a grid that made less than holding, or lost, can still pass.

Save as strategy

Under the result, name the grid and press Save as strategy: it is tested again on the server and saved with its numbers and the pass rule's verdict, its money as its stake, in Trading Strategies. Only a grid that passed can be started there (on paper).

From the algo brain

The algo brain can search grids too (Algo Brain > Idea builder, kind A grid): every mix of the ranges, steps, spacings, out-of-range choices and stops you type, on a group of the top assets, each asset with 1,000 USDT. Each asset is judged on its own by the grid pass rule: a mix of settings goes on when at least one asset passed, and the tables show its best asset and how many passed. A grid has no luck bar: it is ranked by its best asset's money at the end of the unseen part against holding it. Its final exam on the locked candles takes each asset that passed, again on its own, and needs a worst drop of at most 30 % (no money checks). A grid with at least one asset through both shows under the brain's candidates with a line per asset: its search and final exam numbers, whether it passed, and two links that open this page filled in with that asset (the search's period and the final exam's). Save it from there.

The area kind is in the idea builder too (Or the area where the price goes up and down: the last days, and the crossings at least). To see which coins are in an area today, use the Grid Finder (below).

Grid Finder: the coins in an up-and-down area now

The Grid Finder page (Strategy Lab menu, admins) looks at many coins at once and lists the ones whose price keeps going up and down around its price now - the ones a grid suits today. For each coin it takes its price now (the last hourly close) against its hourly closes of the last days and counts the crossings, as the area range above does.

  • The coins: the top coins by 24-hour trading (1 to 200), or one of your watchlists; the last days (1 to 90) and the crossings at least (2 to 1,000).
  • The grid to test: steps, spacing, out of the range, a stop, the candles, how many days back the test goes and the fee. They give the step numbers in the table and fill in the Grid Backtest when you press Test.
  • Show: hide the ranges narrower than a % or the coins whose price was in its range less of the time than a %, and sort by the most crossings, the most kept a step, the most time inside, the widest range or the newest crossing.

Each row: the coin's place by 24-hour trading (#), its price, the crossings and crossings a day, when it last crossed, the range low and high and how far each is from the price, the range width, Inside (the share of the last days' hourly closes in the range), the smallest Step of your grid and Kept a step (what one buy and sell one step apart keeps after the fee on both; 0 or less means use fewer steps). Over the table: how many coins are in an area, their median width and time inside, and how many keep nothing a step. Under it, Not shown lists the other coins and why: too few crossings, no candles or under the Show filters.

Example: the top 50 coins, the last 30 days, 10 crossings at least, 20 steps: a coin with 18 crossings, a range of -12 % / +15 % and 95 % inside keeps about 1.1 % a step - press Test to see its last year as a grid. The list is today's picture: a coin in an area now can break out of it tomorrow.

Example

BTCUSDT, 1H candles from 2024-01-01, the price +- 10 %, 20 steps the same % apart, wait out of the range, 1,000 USDT. Each step is about 1 % wide and keeps about 0.8 % after the fees. Run it, then compare Return with Holding the coin and look at the dashed line to see where the grid fell behind.