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'
-
Hi, I'm learning to make a new indicator.
I've been following these two pages:
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
-
I just realized that I only created an indicator, but no strategy and they are two totally different things lol. All clear