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/

    Time doesn't change but Date does

    General Code/Help
    2
    2
    66
    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.
    • Drew Clayman
      Drew Clayman last edited by

      I have been following examples, but whatever I do, the time won't change along with the date. My code looks as follows:

      class MyStrategy(bt.Strategy):
              def __init__(self):
                  self.dataclose = self.datas[0].close
          
              def next(self):
                  print(self.datas[0].datetime.date(0), self.datas[0].datetime.time(0))
      
      cerebro = bt.Cerebro()
      
      data = btfeeds.GenericCSVData(
          dataname='data.csv',
      
          dtformat=('%Y-%m-%d'),
          tmformat=('%H.%M.%S'),
          
          datetime=0,
          time=1,
          open=2,
          high=3,
          low=4,
          close=5,
          volume=6,
          openinterest=-1
      )
      

      cerebro.adddata(data)

      cerebro.addstrategy(MyStrategy)

      cerebro.run()

      The output looks as follows:

      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989
      2010-03-22 23:59:59.999989

      continuing like this all the way through. The csv file looks like this:

         date 	          time 	  open 	  high 	 low 	  close 	ticks
      

      0 2010-03-01 00.24.00 0.89887 0.89887 0.89886 0.89886 2
      1 2010-03-01 00.25.00 0.89884 0.89888 0.89870 0.89881 20
      2 2010-03-01 00.26.00 0.89878 0.89883 0.89878 0.89883 7

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

        https://community.backtrader.com/post/13058

        • 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 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors