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/

    len(self) in notify_timer is less than len(self.data)

    General Discussion
    1
    4
    62
    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.
    • Li Mike
      Li Mike last edited by

      Hi, this is my code:

      class SmaCross(bt.Strategy):
      
          def __init__(self):        
              self.add_timer(  
                  when=bt.Timer.SESSION_START,
                  monthdays=[1],  
              )
      
          def notify_timer(self, timer, when, *args, **kwargs):  
              print('notify', len(self),len(self.data)) 
      

      When executed, I found that len(self) in notify_timer is less than len(self.data). Is this correct?

      1 Reply Last reply Reply Quote 0
      • Li Mike
        Li Mike last edited by

        When executed, I found that len(self) in notify_timer is less than len(self.data) by 1. Is this correct?

        1 Reply Last reply Reply Quote 0
        • Li Mike
          Li Mike last edited by

          In my strategy, in the notify_timer method, I need
          self.datetime.date(0), which gives an error because of the above problem.

          Any help is apperaciated.

          Li Mike 1 Reply Last reply Reply Quote 0
          • Li Mike
            Li Mike @Li Mike last edited by

            In my strategy, in the notify_timer method, I need
            self.datetime.date(0), which gives an error because of the above problem. That is, at the first bar, len(self) is 0, which result in an error when using self.datetime.date(0).

            Any help is apperaciated.

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