I am new to quantopian and i am trying to learn it using some simple algorithms. I have found this tutorial for simple moving average crossover but when i backtested it , its showing some error regarding the code in my algorithm
def initialize(context):
context.sid = sid(23314)
context.invested = False
def handle_data(context, data):
shortmg = data [context.sid].mavg(10)
longmg = data [context.sid].mavg(50)
if (shortmg > longmg) and not context.invested :
order (context.sid, 100)
context.invested = True
elif (longmg > shortmg) and context.portfolio.positions[sid(23314)].amount > 100
order (context.sid, -100)
context.invested = False
record (short_mavg = shortmg, long_mavg = longmg,stock_price =context.price)
error
Your algorithm couldn't be backtested because it has some code problems.
line causing the error
11 Error SyntaxError: unexpected indent
if (shortmg > longmg) and not context.invested :