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/

    Backtrader not showing hours

    General Discussion
    2
    5
    59
    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.
    • Z
      zer02 last edited by

      Hello,

      I am using a custom CSV and would like to output the datetime. It outputs the date correctly, but the time is always 23:59:59. What am I doing wrong? Thanks

      CSV settings:

      data = btfeeds.GenericCSVData(
           dataname="d_comma.csv",
           nullvalue=0.0,
           dtformat=('%d/%m/%Y %H:%M:%S'),
           datetime=0,
           time=-1,
           high=2,
           low=3,
           open=4,
           close=5,
           volume=6,
           openinterest=-1
       )
      

      Data source:

      datetime,time,open,high,low,close,volume
      03/04/2018 06:00:00,06:00:00,11980.0,11994.5,11965.5,11985.0,687
      03/04/2018 06:01:00,06:01:00,11984.0,12000.0,11982.5,11997.5,236
      03/04/2018 06:02:00,06:02:00,11997.0,11997.5,11992.5,11993.0,153
      

      Next function:

      def next(self):
      cur_dt = self.data.datetime.datetime(0)
      print(cur_dt)
      

      Output:

      2018-04-09, Close, 12339.50
      2018-04-09 23:59:59.999989
      2018-04-09, Close, 12340.00
      2018-04-09 23:59:59.999989
      
      1 Reply Last reply Reply Quote 0
      • B
        benmercerdev last edited by

        How are you adding the data feed to cerebro?

        1 Reply Last reply Reply Quote 0
        • B
          benmercerdev last edited by

          try adding this to your datafeed:

          timeframe=bt.TimeFrame.Seconds,
          
          B 1 Reply Last reply Reply Quote 0
          • B
            benmercerdev @benmercerdev last edited by

            @benmercerdev

            looks like you're using minute resolution, so maybe:

            data = btfeeds.GenericCSVData(
                 dataname="d_comma.csv",
                 nullvalue=0.0,
                 dtformat=('%d/%m/%Y %H:%M:%S'),
                 timeframe=bt.TimeFrame.Minutes,
                 datetime=0,
                 time=-1,
                 high=2,
                 low=3,
                 open=4,
                 close=5,
                 volume=6,
                 openinterest=-1
             )
            Z 1 Reply Last reply Reply Quote 2
            • Z
              zer02 @benmercerdev last edited by

              @benmercerdev Great! Thanks just ```
              timeframe=bt.TimeFrame.Minutes

              1 Reply Last reply Reply Quote 1
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }