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
- Pick a base timeframe that is the fastest one the strategy acts on.
- Build slower bars from the base bars as the run goes, or join precomputed slower bars only after they close.
- 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.
- 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.