FAQ · Getting systematic research right

How do I backtest a strategy across several timeframes?

Run the strategy on the fastest timeframe it trades on and build the slower ones from it, using only completed higher-timeframe bars. The most common mistake is reading an hourly or daily bar before it has closed, which gives the strategy prices it could not have known.

Run the strategy on the fastest timeframe it trades on and build the slower ones from it, using only completed higher-timeframe bars. The most common mistake is reading an hourly or daily bar before it has closed, which gives the strategy prices it could not have known.

Why it goes wrong

A typical multi-timeframe rule reads the trend on daily bars and times entries on 15-minute bars. If the backtest joins the two tables on date, every 15-minute bar on a given day can see that day's daily close, which will not exist until the day ends. The strategy then appears to know the day's direction from its first bar. Results look excellent and do not repeat live.

The same problem appears with any resample: an hourly bar labelled 10:00 holds prices up to 10:59, and a weekly bar labelled Monday holds Friday's close.

The safe pattern

  1. Pick a base timeframe that is the fastest one the strategy acts on.
  2. Build slower bars from the base bars as the run goes, or join precomputed slower bars only after they close.
  3. Use the last completed slower bar. At 14:15, the current hourly bar is still forming; the last completed one is 13:00–13:59. In pandas, that means shifting the resampled series by one period before joining it back.
  4. Decide whether to use the forming bar. Some rules deliberately use the current day's high so far. That is fine if it is computed only from base bars already seen.
hourly = minute.resample('1h', label='left').agg({'open': 'first', 'high': 'max',
                                                  'low': 'min', 'close': 'last'})
hourly_known = hourly.shift(1).reindex(minute.index, method='ffill')   # last closed hour

How Reamer Research handles it

Reamer Research runs one bar at a time, and the window passed to on_bar holds only closed bars. A higher timeframe can be built inside the strategy from that window, so it can only ever use what has closed:

import numpy as np
import reamer_research as rr

class HourlyTrendMinuteEntry:
    lookback = 600                                    # ten hours of minute bars
    ticker = 'SPY'
    def on_bar(self, d):
        tv = d[self.ticker]
        if tv.close[0] == 0:
            return None
        hour = tv.ts // 3600
        closed = hour < hour[-1]                     # minutes of hours that have finished
        last_close = {h: c for h, c in zip(hour[closed], tv.close[closed])}
        closes = np.array(list(last_close.values()))
        if len(closes) < 5:
            return None
        trend_up = closes[-1] > closes[-5:].mean()
        if trend_up and tv.close[-1] > tv.high[-16:-1].max() and d.position(self.ticker) == 0:
            return rr.buy_market(10, ticker=self.ticker)

The same rule runs as a function on_bar(data) or a configured object as well. Each ticker's window carries its bar times as epoch seconds UTC in ts, so any clock-aligned bucket (hour, session, day) is integer arithmetic on the window.

A precomputed slower series can also be passed as a second named series beside the base one, and the strategy trades only the base series. Every series runs on one wall clock: a bar reaches on_bar when it closes, at its series' next timestamp, so an hourly bar stamped at the start of its hour is seen when the hour ends. tv.valid tells you whether a series has a fresh bar this step.

Limits to know

  • Your bar timestamps are trusted. Bars stamped at the end of their period are seen one period later; bars stamped at the start are seen when they close.
  • Two series in one run need a licence. Evaluation Mode runs one ticker, so the build-from-the-window pattern is the one to try there.

A $20 month includes the full kit, so you can run your own multi-timeframe rule and check each entry in the visual trade diagnostics tool.

Next questions

What is look-ahead bias and how do I find it in my backtest?Look-ahead bias is a backtest using information that was not available when the decision was made, such as filling at the close of the bar that produced the signal or reading data published later. Find it by checking when each value was known, shifting signals by one bar, and seeing whether results collapse.How do I backtest a portfolio of several tickers?Run every ticker in one backtest against one shared account, so positions compete for the same capital and margin. Process bars in time order across all tickers, act on each ticker only when it has a fresh bar, and size each position against total equity. Testing tickers one at a time and adding the results misses the shared capital constraint.Can Reamer Research backtest tick, volume or dollar bars?Yes. Reamer Research takes bars of any type: time, tick, volume, dollar, imbalance or your own custom rule. You build the bars and the engine treats every type the same way. Each bar's real trade count can drive its fills, and instruments sampled at different moments can share one portfolio.How do I backtest years of minute data that won't fit in RAM?Store the bars in a compact binary file and memory-map it, so the operating system loads only the pages the backtest reads. Converting once from CSV to a fixed-width binary format removes the parse step and the memory limit together. Chunking a CSV by hand also works but breaks indicators and open positions at every chunk edge.

Every answer here restates the documents that ship in the kit, which are authoritative. All questions.

Reamer Research

Your first backtest in a minute

Backtesting and live trading in Python and C++. Free to install in Evaluation Mode, with no key or sign-up.

pip install reamer-research

A licence at $20 a month removes every limit. The same code runs unchanged.

Reamer Server

The order-management core for your firm

Your venues, your risk rules on every order, one strategy per CPU core, on your own Linux servers.

$24,000 / year

Or start with a 30-day trial at $2,000.