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/

    How to handle repeated code in next and prenext?

    General Discussion
    2
    2
    97
    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.
    • Eduardo De La Garza
      Eduardo De La Garza last edited by

      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!

      hghhgghdf dfdf 1 Reply Last reply Reply Quote 0
      • hghhgghdf dfdf
        hghhgghdf dfdf @Eduardo De La Garza last edited by

        @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

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors