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/

    Solution to Plotting Issue Regarding Indicator with Single Price Line Input

    General Code/Help
    1
    1
    15
    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.
    • P
      paul_lam last edited by

      Re: LinesCoupler is plotted on different figure when passing line instead of data to SMA indicator

      Although I did try to implement a custom plotter using plotly in order to solve the problem as I believed that it was caused by the default plotter matplotlib, I finally realized that the problem is caused by providing a price line as an input to the indicator.

      The final __init__ method shall look like the following.

      def __init__(self):
          self.sma = sma = btind.SMA(self.data1.open)  # use open price liz
          sma.plotinfo.plot = True  # show plotting
      
          if self.p.multi:
              self.sma1 = sma()  # couple the entire indicators
              '''
              By providing only a price line to the indicator,
              the clock of the `LinesCoupler` object `self.sma1` won't be updated,
              it shall be set manually.
              '''
              self.sma1._clock = self.data0
      
              self.sellsignal = self.data0.close < self.sma1.sma
          else:
              self.sellsignal = self.data0.close < sma.sma()
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors