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/

    Multiple Indicators Help

    Indicators/Strategies/Analyzers
    help-needed plotting indicators
    2
    3
    296
    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.
    • S
      SSbilis last edited by

      ![Hello,
      I have an indicator class where I am calculating a couple of indicators. The reason I have them all in one class is that they are dependent on one another. The problem is that when I plot this class it plots all of the indicators. So specifically it is plotting the beta, spread, spread moving average, and spread std upper and lower lines. The beta value is so large, however, that it is making the rest of the indicators not visible.
      How do I plot all of the indicators within the same class except the beta value?
      I can't just say beta = model.fit().params instead of self.beta because I use the beta in my strategy Class.
      Any suggestions would be appreciated.

      class Beta(bt.Indicator):
          lines = ("beta"
                   , "spread"
                   , "spread_sma15"
                   , "spread_2sd"
                   , "spread_m2sd"
                   )
      
          params = (
              ("period_pct", 1),
              ("period_beta", 15),
          )
      
          def __init__(self, strat=None):
              """"initialize the line assign it to a variable
              Any operation involving lines objects during __init__ generates another lines object
              Whereas during next it yields regular Python types like floats and bools"""
      
              self.strategy = strat
              self.line0 = self.strategy.datas[0].close
              self.line1 = self.strategy.datas[1].close
      
              self.addminperiod(self.params.period_beta + 1)
      
          def next(self):
              (...)
              #beta
              self.l.beta[0] = model.fit().params
      
              #spread
              self.l.spread[0] = l0_pct_change[-1] - l1_pct_change[-1] * self.l.beta[0]
      
              #15 day Spread Moving Average
              datasum = math.fsum(self.l.spread.get(size=self.p.period_beta))
              self.l.spread_sma15[0] = datasum / self.p.period_beta
      
              #15 Day Standard Deviations
              self.l.spread_2sd[0] = ((((datasum - self.lines.spread_sma[link text](![link url](![image url](image url)))15) ** 2) / self.p.period_beta) ** 0.5) * 2
              self.l.spread_m2sd[0] = ((((datasum - self.lines.spread_sma15) ** 2) / self.p.period_beta) ** 0.5) * -2
      ```]([image url]([link url](```
      ~~
      * ![link url](![0_1619379742578_Untitled.png](Uploading 100%) image url)~~
      ```)))
      1 Reply Last reply Reply Quote 0
      • S
        SSbilis last edited by

        I apologize. I accidentally included the link to the image in the code block. Ignore that last part.
        Untitled.png

        run-out 1 Reply Last reply Reply Quote 0
        • run-out
          run-out @SSbilis last edited by

          @ssbilis In your indicator, usually below params, you can control all your plotlines. Review this chapter for more details.

          RunBacktest.com

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