FRENESDE

Multi-timeframe resampling

cerebro.resampledata(data, timeframe=bt.TimeFrame.Weeks, compression=1) builds weekly bars from daily bars: open of the first day, high and low of the week, close of the last day.
You first add the daily feed with adddata, then resample it: the daily feed becomes self.data0 and the weekly one self.data1. You can compute an indicator on each, for example bt.ind.SMA(self.data1, period=10).
Compression groups several units: timeframe=bt.TimeFrame.Minutes, compression=60 makes one-hour bars from one-minute bars. You can only go from a small timescale to a larger one, never the reverse.
A weekly bar is only complete at the end of the week. To decide on a Wednesday, rely on the last finished week, otherwise you use a close that did not exist yet. cerebro.replaydata(), on the other hand, lets you watch the bar form step by step.

Examples

Key terms

Resampling
Turning bars into bars of a larger timescale
timeframe
Time unit of the bars: minutes, days, weeks…
compression
Number of units grouped into one bar
replaydata
Variant that replays the bar while it forms
Take the mission on Doji Academy

← Back to the index