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/

    AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Indicat' object has no attribute '_addobserver'

    Indicators/Strategies/Analyzers
    1
    2
    798
    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.
    • M
      marsario last edited by

      Hi, I'm learning to make a new indicator.

      I've been following these two pages:

      • https://medium.com/@danjrod/custom-indicator-development-in-python-with-backtrader-bc775552dc3e

      • https://www.backtrader.com/docu/inddev/

      When I paste the code, I get the same error message:
      AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Indicat' object has no attribute '_addobserver'

      What is the problem?

      This is my full code:

      import datafeeds.yf as yf
      import backtrader as bt
      import datetime
      
      
      enddate=datetime.date.today()
      startdate = enddate - datetime.timedelta(days=(365*10))
      cerebro = bt.Cerebro()
      #Adding apple datafeed to cerebro:
      cerebro = yf.apple(cerebro,startdate,enddate)
      cerebro.broker.setcash(100000.0)
      print("Launching the strategy")
      cerebro.addstrategy(DummyDifferenceDivider)
      cerebro.run()
      print("Strategy is over, final cash:",cerebro.broker.getvalue())
      cerebro.plot()
      
      class DummyDifferenceDivider(bt.Indicator):
          lines = ('diffdiv',)  # output line (array)
          params = (
              ('period', 1),  # distance to previous data point
              ('divfactor', 2.0),  # factor to use for the division
          )
          def __init__(self):
              diff = self.data(0) - self.data(-self.p.period)
              diffdiv = diff / self.p.divfactor
              self.lines.diffdiv = diffdiv
      
      
      1 Reply Last reply Reply Quote 0
      • M
        marsario last edited by

        I just realized that I only created an indicator, but no strategy and they are two totally different things lol. All clear

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