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 set strategy's member externally

    General Discussion
    2
    3
    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.
    • Kas David
      Kas David last edited by

      How can I externally set a private member inside a strategy?

      class strategy(bt.Strategy):
        def __init__(self):
          self.title = "how to set this externally?"
      
      cerebro.addstrategy(strategy) # using strategy
      
      cerebro.strategy.setTitle("new title")
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        Strategy instances are created during backtesting execution and not before.. What you need is to pass a parameter with your desired title.

        1 Reply Last reply Reply Quote 0
        • Kas David
          Kas David last edited by

          Cool works for me, thanks.

          class firstStrategy(bt.Strategy):
              params = (
                  ('period',21),
                  )
             x= self.params.period
          
          cerebro.addstrategy(firstStrategy, period=14)
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors