Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Multiple TimeFrames

    General Code/Help
    2
    3
    404
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mandark last edited by mandark

      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 !

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        @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.

        1 Reply Last reply Reply Quote 0
        • M
          mandark last edited by

          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).

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors