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 access the "params" tuple?

    General Discussion
    3
    3
    591
    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.
    • N
      niklay last edited by

      Hi there,
      I started with the Quickstart tutorials and found some confusing code (see attached). The "params" tuple is created with two separate tuples inside. However, I can access these inside tuples by typing params.maperiod . However, if I rename params to another name I cannot access them anymore.

       class TestStrategy():
        params = (
            ('maperiod', 15),
            ('printlog', False),
        )
      
      def log(self, txt, dt=None, doprint=False):
          if self.params.printlog or doprint:
              dt = dt or self.datas[0].datetime.date(0)
              print('%s, %s' % (dt.isoformat(), txt))
      B 1 Reply Last reply Reply Quote 0
      • L
        Laurent Michelizza last edited by Laurent Michelizza

        I don't think you should rename the variable params as it is part of the default strategy that you are inheriting. You can also access it simply with .p like below:

        self.p.printlog
        
        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @niklay last edited by

          @niklay said in How to access the "params" tuple?:

          I started with the Quickstart tutorials and found some confusing code (see attached). The "params" tuple is created with two separate tuples inside. However, I can access these inside tuples by typing params.maperiod .

          What's exactly the confusing part? You declare params (which you can also declare as a dict) and you can access them. It's a declarative style. As pointed out by @Laurent-Michelizza , there is a shorhand notation where params is shortened to p

          @niklay said in How to access the "params" tuple?:

          However, if I rename params to another name I cannot access them anymore.

          Of course. How are you expecting the platform to know which params have been defined if you give the declaration a different name?

          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(); }); }