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



  • 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?


  • administrators

    @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?



  • 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']
    

  • administrators

    @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.