For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

How to handle repeated code in next and prenext?



  • I have been developing a couple of strategies with bt. For monitoring purposes I've defined some functions that need to run on next and prenext. Right now I have to manually call the relevant functions from every strategy in next and prenext. I want to find a way in which the functions run automatically on next and prenext even if prenext and next are not defined in a given strategy. Im not sure how can I handle that. I was thinking that I could have a MyBaseStrategy in which I could have those functions but then im not sure how I would add functionality to those functions if I decide to use them in my strat. From what I understand that would overload the function and the parent code wouldn't run. Is there a way to simple do what im trying to do? Thanks!



  • @Eduardo-De-La-Garza said in How to handle repeated code in next and prenext?:

    From what I understand that would overload the function and the parent code wouldn't run.

    inside of MyBaseStrat

    def next2(self):
        pass
    
    def next(self):
        *universal functionality*
       
        self.next2()
    
    

    then overwrite next2 for your strategy specific functionality


Log in to reply
 

});