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/

    access indicator member variables

    General Code/Help
    2
    4
    635
    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.
    • bb2
      bb2 last edited by

      In the indicator I populate a list defined on self:

      class SomeIndicator(bt.Indicator):
        def __init__(self):
          self.someList = []
        def next(self):
          self.someList.append('something')
      

      In the strategy I want to access the someList like that:

      class DummyStrategy(bt.Strategy):
        def __init__(self):
          self.someIndicator = SomeIndicator()
        def next(self):
          print(self.someIndicator.someList)
      

      The problem is that I always get the latest state of self.someIndicator.someList. As a result I get a print of the last someList over and over depending on the length of data.

      The question is how can I properly access a member variable of an indicator to be used in the next of a strategy?

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @bb2 last edited by

        @eduedix said in access indicator member variables:

        The question is how can I properly access a member variable of an indicator to be used in the next of a strategy?

        There seems to be some misunderstanding here. You are already accessing the member variable and you get the last value because you keep on appending things to it.

        Where is the problem?

        1 Reply Last reply Reply Quote 0
        • bb2
          bb2 last edited by

          The problem is I don't see the intermediate steps. For example, let's say len(data) is 3. In the print outs I see the latest step 3 times:

          ['something', 'something', 'something']
          ['something', 'something', 'something']
          ['something', 'something', 'something']
          

          instead of

          ['something']
          ['something', 'something']
          ['something', 'something', 'something']
          
          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @bb2 last edited by

            @eduedix said in access indicator member variables:

            The problem is I don't see the intermediate steps. For example, let's say len(data) is 3. In the print outs I see the latest step 3 times:

            ['something', 'something', 'something']
            ['something', 'something', 'something']
            ['something', 'something', 'something']
            

            instead of

            ['something']
            ['something', 'something']
            ['something', 'something', 'something']
            

            If the len(data) == 3 you are bound to see 3 somethings

            You'd be better off posting a complete working sample that makes sense.

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