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)



  • 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?



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



  • 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.



  • 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.


Log in to reply
 

});