VALYNOXSTRATEGY RESEARCH TECHNOLOGY
AlphaPrimeAlphaPrime
ACADEMY / How AlphaPrime Computes

Range bar backtests: fixed range, variable time, and the fill you never got

A range bar closes when its high-to-low distance reaches a fixed size, so bars arrive quickly in fast markets and slowly in quiet ones. Range bar backtests flatter a strategy by filling at the bar's closing tick, the one price the move has already passed. AlphaPrime confirms a range bar at the close of the underlying time bar, fills at the next real price with doubled slippage, and judges stops on the underlying high and low.

By · Published · updated · Editorial policy

Contents
  1. What is a range bar, and why does a range bar backtest overstate results?
  2. How is a range bar built, and when is it actually known?
  3. Where does a range bar backtest see the future?
  4. The closing tick is the worst fill to assume
  5. Bars cluster where fills are worst
  6. Stops inside a multi-bar minute
  7. How does AlphaPrime backtest a range bar strategy?
  8. What range size should you backtest, and how does it interact with the underlying resolution?
  9. Which markets and strategies suit range bars?
  10. Frequently asked questions

What is a range bar, and why does a range bar backtest overstate results?

A range bar is a price bar that closes when the distance between its high and low reaches a fixed size, no matter how long that takes. Backtests overstate range bar strategies because they fill at the tick that closed the bar, and that tick, by definition, is the end of a move you had not yet seen finish.

Range bars were designed to make every bar carry the same amount of price movement. A 10-point range bar on an index future might take forty minutes to form at lunchtime and eight seconds after an economic release. The chart compresses quiet periods and stretches busy ones, which makes breakouts and pullbacks easier to read than on time bars. Time is not shown; the x-axis is simply one bar after another.

That property is also the trap. The bars that generate your signals are the bars that formed fastest, and those are the moments when the market was hardest to trade at a known price. This page covers the range-bar-specific version of the problem; the rules shared by every synthetic chart type are on the overview of why synthetic-bar backtests cheat.

How is a range bar built, and when is it actually known?

A range bar is known when a real trade has pushed the bar's high-to-low distance to the set size. A backtest built from minute data learns that at the close of the minute, and an honest engine lets the strategy see the bar then, not at the tick.

The rule itself is simple. The bar opens one tick beyond the previous bar's close, because a tick belongs to one bar only. Every new trade updates the high or the low. The moment high minus low equals the range size, the bar closes at that trade, at its high or its low, and the next bar starts. In a fast move one underlying minute can produce many bars; in a quiet one, none.

AlphaPrime (Valynox) builds range bars from the underlying time bars you choose, 1-minute for most intraday work, and a range bar becomes visible to the strategy only at the close of the underlying bar that completed it. Several range bars completed inside one minute appear together at the end of that minute, and every signal from them fills at the same next real price, which is what a live platform receiving a minute of data would let you do.

Two more rules decide how the bars are cut from a minute bar. A minute bar has an open, a high, a low and a close, and nothing about the order in which the high and low were made. AlphaPrime assumes the order that is worse for a strategy and longer as a path: open, then high, then low, then close when the bar closed up; open, low, high, close when it closed down. That path cuts more bars and more false signals than the friendlier order would, by a quarter to a half on ES and NQ 1-minute data, and it uses only the bar's own four prices, so nothing is borrowed from the future. On a gap between two minute bars nothing is drawn inside the gap: if the gap is smaller than the range it is absorbed into the current bar; if it is exactly the range the bar closes at the gap price; if it is larger, the current bar closes short at the last real price and a new bar opens at the gap price. No phantom bars are drawn where nothing traded.

Hypothetical example

Range size 8 points. A bar opens at 100 at 10:14:03. By 10:14:41 the bar has traded between 100 and 108, so it closes at 108 and a new bar opens at the next trade. The 10:14 minute closes at 10:15:00 at 110. A backtest that fills a breakout buy at the range bar's close puts you in at 108. AlphaPrime confirms the bar at 10:15:00 and fills at the first trade of 10:15, around 110, plus slippage.

Where does a range bar backtest see the future?

Mostly in the fill, and secondarily in the clustering of bars. The stop problem that haunts Renko is smaller here, because a range bar does record its real high and low, but it is not gone.

The closing tick is the worst fill to assume

Rule one for every synthetic bar: the bar exists only after its underlying data has closed. Why: the tick that completes a range bar is not known to be the completing tick until it prints, and your order goes out after that. What it avoids: a fill at the closing tick means you bought the exact end of an 8-point run every single time, which is not a fill, it is a wish. Over hundreds of trades the gap between the closing tick and the next real print adds up to most of the edge a fast-market breakout rule appears to have.

Bars cluster where fills are worst

A range bar strategy fires most of its signals in the few minutes a day when range bars are completing in bursts. Those minutes have wide spreads and thin books. If your backtest uses one average slippage figure for every trade, it has quietly assumed the lunchtime spread during the opening frenzy. The engine's own measurement on about three years of ES 1-minute data with an 8-tick range makes the point: close to a third of the minutes that produced a range bar produced three or more, and in those minutes the distance from a bar's close to the next real trade averaged about four times what it was in minutes with a single bar. That is why the slippage multiplier for range bars is two and can only be raised.

Stops inside a multi-bar minute

When three range bars complete inside one underlying minute, a brick-by-brick stop check can let you enter on the first bar and get stopped on the third, with a loss the size of one range. In reality you would have seen all three at the minute close, entered after them, and taken whatever came next. The honest version is to judge stops on the underlying bar's high and low after the entry is actually possible, which sometimes helps you and more often does not.

Range bar featureClosing-tick backtestAlphaPrime
Bar completionKnown at the closing tickKnown at the close of the underlying bar
Entry fillThe bar's closing tickNext real price plus doubled slippage
Stop and target checkEach range bar separately, even several per minuteReal highs and lows of the underlying bars, stop first
Order of high and low inside a minuteWhichever order the engine prefersAlways the longer, less favourable path
Gap larger than the rangePhantom bars drawn across the gap, each tradeableCurrent bar closes short at the last real price; new bar opens at the gap price; nothing inside the gap
Three range bars that completed inside one minute are confirmed together at the minute close; the fill is the next real trade, not the closing tick of the first bar.
Three range bars that completed inside one minute are confirmed together at the minute close; the fill is the next real trade, not the closing tick of the first bar. AlphaPrime generation settings · chart type panel

How does AlphaPrime backtest a range bar strategy?

The strategy reads range bars; the money is settled on the underlying real bars. Each rule below is stated with the reason it exists and the error it removes.

  • A range bar is confirmed at the close of the underlying bar that completed it. Why: the completing tick is not known to be the last until the next trade prints, and a minute-built engine only knows at the minute close. Avoids: acting on a bar's second half as if the first half had already told you how it ended.
  • Market orders fill at the open of the next underlying bar, plus slippage. Why: that is the first price available after the signal exists. Avoids: fills at the closing tick, the one price the move had just left.
  • Stops and targets are judged against the real highs and lows of the underlying bars, and the stop comes first. Why: the real bar contains every price the range bars were cut from, and the order of events inside it is unknown. Avoids: winners that only exist because the engine assumed the target was touched before the stop.
  • The path inside a minute bar is always the longer, less favourable one. Why: the true path is unknown, and choosing the kinder one is choosing the result. Avoids: bar counts and signals that depend on a guess in the strategy's favour.
  • Slippage is multiplied by two; you can raise the multiplier, never lower it. Why: range bars complete in bursts when spreads are widest. Avoids: pricing a frenzy at a lunchtime spread.
  • Nothing is drawn inside a gap. Why: nothing traded there. Avoids: entries inside a gap at prices that never existed.

The practical effect is that a range bar breakout rule loses a roughly fixed amount per trade compared with the chart version: the distance from the closing tick to the next print, plus the extra slippage, at entry and at exit. For the general method of choosing a slippage figure and comparing it with your average trade, see trading costs in backtests.

What range size should you backtest, and how does it interact with the underlying resolution?

Choose a range the underlying bars can resolve: a range smaller than a typical 1-minute bar's own high-to-low distance will produce several range bars per minute almost all day, and the bars' shape then comes mostly from the assumed path inside the minute rather than from the market. Pick a range that takes a few minutes to form on an ordinary day and completes in one minute only during real moves. The chart-type panel shows the average bars per day and the busiest hour for the setting you chose, which is the quickest way to see whether the range is too small.

  1. Start from the average 1-minute range of the session you trade, measured on completed data. A range size of two to four times that number usually gives bars that form over several minutes in normal conditions.
  2. Check the bars-per-minute distribution. If more than a small share of range bars complete in the same minute as another, either widen the range or move to a finer underlying resolution.
  3. Keep it fixed across in-sample and out-of-sample. A range size tuned on the test data is a fitted parameter, however natural the number looks.

Range bars count only the distance between a bar's own high and low. If you want the jump from the previous bar's close to count as well, Kase bars measure true range instead; if you want a bar that must reverse before it closes, see reversal bars. Both share the rules on this page.

Which markets and strategies suit range bars?

Range bars suit breakout and momentum rules on liquid markets with a steady tick size: index futures, major currency pairs, large-cap crypto in active hours. They are a poor choice for thin contracts, for overnight sessions where the spread itself can span the range, and for any rule whose edge is a few ticks wide.

Two things to check before you trust a range bar result. First, look at where the trades sit in the day. If most of the profit comes from a handful of sessions where bars were completing every few seconds, the doubled slippage is a floor, not a ceiling, and you should test with more. Second, run the same rule on time bars of similar average duration. A rule that works on both is a rule. A rule that works only on range bars is usually a fill assumption wearing a strategy's clothes.

What this means if you use AlphaPrime: pick range bars as the chart type in strategy generation, set the range and an underlying resolution fine enough to resolve it, and let the search run. Every candidate is tested with bars confirmed at the underlying close, next-real-price fills, doubled slippage and real-bar stop checks, in Classic and in Reserve. What survives did not depend on the closing tick.

Frequently asked questions

Are range bars better than time bars for backtesting?

Neither is better; they answer different questions. Range bars make movement-based rules easier to express. Time bars make the timing of fills honest by default. AlphaPrime lets you write the rule on range bars and settles the trades on the underlying time bars, which keeps the first advantage without giving up the second.

Do range bars repaint?

A completed range bar does not change. The forming bar updates with every tick, and a backtest that trades the forming bar as if its close were known is using a number that did not exist yet. AlphaPrime shows the strategy a range bar only after the underlying bar that completed it has closed.

What is a phantom range bar?

On many charts, when price gaps by more than the range size, the builder fills the gap with one or more bars at levels where nothing traded. Those are phantom bars, and a backtest that fills inside them is filling at prices that never existed. AlphaPrime does not draw them: the current bar closes short at the last real price, the next bar opens at the gap price, and the first available fill is the real price after the gap.

Can I use range bars on forex and crypto?

Yes. Set the range in pips for forex and in price units or a percentage for crypto. Crypto range bars cluster heavily around liquidation cascades, so test with slippage above the doubled starting point before trusting a result there.