Help with starting up
-
Hello,
I am new to backtrader as well as python and would really appreciate some help to get started. I have written a strategy that generates signals but I am not able to backtest the same. Can someone help me to convert the logic below to init and next functions?
Thanks in Advancedf['44sma'] = df['Close'].rolling(window=44).mean()
if (df.iloc[-1]['Low'] < df.iloc[-1]['44sma']):
if (df.iloc[-1]['High'] > df.iloc[-1]['44sma']):
if (df.iloc[-1]['Close'] > df.iloc[-2]['Close']):
if (df.iloc[-1]['Close'] > df.iloc[-1]['44sma']):
for i in range(30):
if(df.iloc[-i-1]['44sma'] > df.iloc[-i-2]['44sma']):
flag = 1
else:
flag = -1
break -
@shubham You need to create indicators and create them in the
__init__
of your strategy. You can then use them in next. I would encourage you to read the docs here They are quite useful and have many examples. Once you have taken a stab at writing the code in Backtrader, repost here again if you have any issues.