Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
What is the problem with this code

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 :  
2 responses

The line is too much indented as the error say. Remove the space before your if-statement if so it's aligned with the line above (longmg = ...).

Thanks for the reply