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/

    Based my code on Quickstart: would like to self.log the minutes

    General Code/Help
    2
    2
    644
    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.
    • D
      data-analyst last edited by

      Hello there,
      My data are minute based. What I changed in the code in order to do so is the following:
      timeframe=bt.TimeFrame.Minutes
      dtformat=('%Y-%m-%d %H:%M:%S')

      What I would like now is, when I run the script, it print the date, hour, minute at each stage. I should change something in the log function (
      dt = dt or self.datas[0].datetime.date(0)
      print('%s, %s' % (dt.isoformat(), txt)))

      But I am not sure what, any help? Thanks!

      1 Reply Last reply Reply Quote 0
      • E
        Emin Ozkan last edited by

        This works for me

        def log(self, txt, dt=None, doprint=False):
            ''' Logging function fot this strategy'''
            if self.params.printlog or doprint:
        
                dt = dt or self.datas[0].datetime.datetime(0)
                print('%s, %s' % (dt.isoformat(), txt))
        
        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors