Backtrader Community

    • 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 / what is "current" data for larger timeframes?

    General Code/Help
    3
    4
    492
    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.
    • Pierrot
      Pierrot last edited by Pierrot

      Hi,

      I intend to use multiple timeframes as indicated in another post, and I would like to know what is backtrader behavior when calling "current" data of larger timeframes?

      Basically, let say I have 2 timeframes: 1H (1 hour) & 4H (4 hours).

      • "next()" is called to process timestamp 2019/05/06 02:00:00
      • at this time, the "current" bar of the larger timestamp is not finished (started at at 2019/05/06 00:00:00 & will close at 2019/05/06 04:00:00)

      If I call data for current 4H bar, what will backtrader give me?

      • OHLCV of the last closed bar (timestamp 2019/05/05 20:00:00)
      • O of the current non-finished bar (timestamp 2019/05/06 00:00:00) & NaN for the HLCV data?
      • O of the current non-finished bar (timestamp 2019/05/06 00:00:00) & current values for HLCV derived from the 2 1H closed bars as current projection:
      • H from highest of the 2 1H closed bars
      • L from lowest of the 2 1H closed bars
      • C from close of 2nd 1H closed bar
      • V from sum of the 2 1H bar Vs
        ?

      Is there a way to chose between these different behaviors? (I would like to use basically the 3rd option)

      I thank you in advance for your help.
      Have a good afternoon.
      Best regards,
      Pierre

      B 1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by ab_trader

        You may want to study documentation related to data feeds -

        Docs - Multiple timeframe
        Docs - Data resampling
        Docs - Data - replay

        Part of the questions (maybe even all of them) will be answered.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @Pierrot last edited by

          @pierrot said in Multiple timeframes / what is "current" data for larger timeframes?:

          at this time, the "current" bar of the larger timestamp is not finished (started at at 2019/05/06 00:00:00 & will close at 2019/05/06 04:00:00)

          There isn't such a thing as "not finished". You have the bar and it has a timestamp. You may know when the bar starts and ends, the system doesn't. The system can only see the incoming timestamp, which by convention is the latest timestamp of the entire period. The system cannot know if that bar has been constructed from 1 million ticks in 4 hours or it has been generated with 4 ticks during the last nanosecond of the 4 hour period. You may want to assume something, the system assumes nothing.

          A larger timeframe will only be delivered to you when the timestamp is smaller or equal than the timestamp of the next smaller timeframe (now you can recurse downwards until you find the smallest timeframe)

          Any timestamp larger than that cannot be delivered, because it hasn't been reached.

          As suggested by @ab_trader in another post, you probably need to write a next method and use some print statements and read about resampling and replaying as also suggested.

          1 Reply Last reply Reply Quote 0
          • Pierrot
            Pierrot last edited by

            Hi,
            Thanks for your help.
            Yes I did started playing with some print statements. Things start to be clearer.
            Thanks for your help!
            Bests,
            Pierre

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