Multiple TimeFrames
-
I am adding multiple feeds with different timeframes to my strategy. My datetime buckets are standard and in UTC. For example -
2019-01-22 09:05:00 O H L C V represents the ticks that start at 09:05:00 and ends at 09:09:59, for a 5 min tick.
2019-01-22 09:00:00 O H L C V represents the ticks that start at 09:00:00 and ends at 09:04:59, for a 5 min tick.
2019-01-22 09:00:00 O H L C V represents the ticks that start at 09:00:00 and ends at 09:59:59, for a 1 hour tick.When I run the backtest on 5m(feed1) and 1H(feed2), it processes ticks in following order:
feed1: 2019-01-22 08:50:00 feed2: 2019-01-22 08:00:00 feed1: 2019-01-22 08:55:00 feed2: 2019-01-22 08:00:00 feed1: 2019-01-22 09:00:00 feed2: 2019-01-22 09:00:00 feed1: 2019-01-22 09:05:00 feed2: 2019-01-22 09:00:00
which means it assumes complete tick for feed2 at 09:00:00 while taking the decision.
Ideally, I would want the calculations to go like this:
feed1: 2019-01-22 08:50:00 feed2: 2019-01-22 07:00:00 feed1: 2019-01-22 08:55:00 feed2: 2019-01-22 08:00:00 feed1: 2019-01-22 09:00:00 feed2: 2019-01-22 08:00:00 feed1: 2019-01-22 09:05:00 feed2: 2019-01-22 08:00:00 ____ feed1: 2019-01-22 09:50:00 feed2: 2019-01-22 08:00:00 feed1: 2019-01-22 09:55:00 feed2: 2019-01-22 09:00:00 feed1: 2019-01-22 10:00:00 feed2: 2019-01-22 09:00:00
i.e. it should process the tick only when it is actually complete, otherwise it becomes a forward looking backtest.
This behaviour is fine when there is only one timeframe.
Is there an issue with my understanding? Can I change this behaviour with some parameter?
Thanks !
-
@mandark said in Multiple TimeFrames:
Is there an issue with my understanding?
Not an issue with your understanding. It is simply that the timestamp in backtrader is the end of the tick (as you name it, bar as others name it)
This is so because when resampling and especially with replaying, one has to consider the last available timestamp for synchronization and to understand where one is.
-
Thanks a lot. I solved this issue by resampling my pandas data feed with label="right" to ensure that timestamp is the end of bar(tick).