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/

    Extracting variables defined in strategy

    Indicators/Strategies/Analyzers
    2
    2
    1027
    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.
    • J
      JohnShiu last edited by

      Hi,
      There are usually a bunch of variables defined in a strategy. For example, what I would like to do is:

      class MyStrategy(Strategy):
          def __init__(self):
              self.sstc = indicators.Stochastic(data, ....)
              self.sma = indicators.SimpleMovingAverage(data, ...)
      
              self.indicators_log = {"sstc": self.sstc, "sma": self.sma}
      

      To extract the variables in the strategy, e.g. indicators_log, I tried to add analyzer:

      class MyAnalyzer(Analyzer):
          def get_analysis(self):
              indicators_log = self.indicators_log
              ... do something ...
              return indicators_log
      

      But obviously it doesn't work
      So my question is..
      (1) Is it possible to extract the variables defined in the strategy, e.g. indicator_log, in analyzer?
      (2) If not, are there any recommendations to get the variables? (better including their name, for me to do further analysis in some later time)

      Thanks

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

        @JohnShiu said in Extracting variables defined in strategy:

        (1) Is it possible to extract the variables defined in the strategy, e.g. indicator_log, in analyzer?

        See Docs - Analyzers

        Each analyzer has automatically an attribute named strategy which obviously points to the strategy in which the analyzer is inserted.

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