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/

    Hourly bars?

    General Code/Help
    2
    4
    3577
    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.
    • S
      Serp last edited by Serp

      Hi,
      I copy pasted the quickstart code under "The broker says: Show me the money!" and adjusted filename and following feed params:

          data = data = btfeeds.GenericCSVData(
          dataname='test_ForBacktraderHourly.csv',
      
          fromdate=datetime.datetime(2017, 1, 1),
          todate=datetime.datetime(2017, 1, 5),
      
          nullvalue=0.0,
          dtformat=('%Y-%m-%d %H'), # it is hourly data
          
          
          headers = True, 
          datetime=0,
          high=1,
          low=2,
          open=3,
          close=4,
          volume=5,
          openinterest=-1
      )
      

      The csv contains datal like this:
      Date, High, Low, Open, Close, Volume
      2011-09-13 15, 6.000000000000, 5.800000000000, 5.800000000000, 6.000000000000, 25.000000000000
      2011-09-13 16 , 5.950000000000, 5.760000000000, 5.950000000000, 5.760000000000, 22.353982380000

      So that should be hourly bars.
      But when executing the self.buy() the buy is not executed at next bar, but at next day.
      How to change from Daily to Hourly?
      I tried to add

          timeframe = bt.TimeFrame.Hours
      

      but 1) this is only used for Resampling (dont know yet what it is) and 2) does Hours not exist.

      edit:
      So question is not only about "hourly" it is about customized bars, so even 2 hourly or 0.5hourly and so on.

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

        @Serp said in Hourly bars?:

        timeframe = bt.TimeFrame.Hours

        but 1) this is only used for Resampling (dont know yet what it is) and 2) does Hours not exist.

        No, ``timeframe` is not only for resampling. It is a standard parameter for all data feeds. It is especially important when resampling because a target is needed.

        Which means that if your input is really not Days (the default value), you have to tell the platform what it is.

        1. does Hours not exist.

        You can still use Minutes and 60 which is 1 hour.

        1 Reply Last reply Reply Quote 2
        • S
          Serp last edited by Serp

          thank you very much. English is not my native language and I thought the sentence:
          "Informative unless Data Resampling/Replaying is used" would mean, that it is just for my personal informative use (like I could print that it is "daily", but it has no other purpose).

          Thanks, so to sum it up (for other people reading here) the solution was:

           timeframe = bt.TimeFrame.Minutes, 
           compression = 60,
          
          1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators last edited by

            You read it right and has been corrected. The platform was tightened around that area due to how users were actually addressing the multiple possible corners.

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