For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

# Question about the example in the article Developing a Recursive Indicator (with a seed)

• When I run the example code in the article “Developing a Recursive Indicator (with a seed)”
''''

class EMA(bt.indicators.PeriodN):
params = {'period': 30} # even if defined, we can redefine the default value
lines = ('ema',) # our output line

``````def __init__(self):
self.alpha = 2.0 / (1.0 + self.p.period)  # period -> exp smoothing factor

def nextstart(self):  # calculate here the seed value
self.lines.ema = self.data.get(size=self.p.period) / self.p.period

def next(self):
ema1 = self.lines.ema[-1]  # previous EMA value
self.lines.ema = ema1 * (1.0 - self.alpha) + self.data * self.alpha
``````

''''
I met the following error
''''
File "C:/Bob_home/exploration/backtrader/data-pandas.py", line 50, in nextstart
self.lines.ema = self.data.get(size=self.p.period) / self.p.period
TypeError: unsupported operand type(s) for /: 'array.array' and 'int'
''''

In the part of nextstart, from my understanding, ''''self.lines.ema '''' is a digit, and ''''self.data.get(size=self.p.period) / self.p.period'''' is a series whose length is period.
why there exists the error? many thx.

• '''' is not ```

There is an obvious typo

self.lines.ema = self.data.get(size=self.p.period) / self.p.period
TypeError: unsupported operand type(s) for /: 'array.array' and 'int'

``````self.lines.ema = sum(self.data.get(size=self.p.period)) / self.p.period
``````

});