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



  • 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
    


  • How are you adding the data feed to cerebro?



  • try adding this to your datafeed:

    timeframe=bt.TimeFrame.Seconds,
    


  • @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
     )


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


Log in to reply
 

});