For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
TypeError: __init__() takes 1 positional argument but 2 were given
-
hi, i'm trying to backtest this strategy:
class WaveTrendStrategy(bt.Strategy):
def __init__(self) : n1 = 21 n2 = 14 obLevel1 = 60 obLevel1 = 60 obLevel2 = 53 osLevel1 = -60 osLevel2 = -53 hlc3 = (self.data.high+self.data.low+self.data.close)/3 ap = hlc3 esa = bt.ind.EMA(ap, n1) d = bt.ind.EMA(abs(ap - esa), n1) ci = (ap - esa) / (0.015 * d) tci = bt.ind.EMA(ci, n2) wt1 = tci wt2 = bt.ind.SMA(wt1,4) longCondition = bt.ind.CrossOver(wt2,osLevel2) shortCondition = bt.ind.CrossUnder(wt2,obLevel2) def next(self): if longCondition: self.buy() elif shortCondition: self.sell()
but i get TypeError: init() takes 1 positional argument but 2 were given.
Someone can show me where i'm wrong? Thanks a lot.
-
@chricco94 That error is coming from your use of
EMA
. You need to name theperiod
parameter so useesa = bt.ind.EMA(ap, period=n1)
instead of
esa = bt.ind.EMA(ap, n1)
BT makes heavy use of meta classes which can be confusing at times.
There are a couple of other issues in your code:
- There is no
CrossUnder
indicator in BT - You aren't storing the
longCondition
andshortCondition
indicators inself
so you cannot access them innext()
- There is no
-
@davidavr thank you, it worked!