Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Could someone help with this very simple moving average strategy

There seems to be a problem with line 20 but I don't get it.
This line =>> order_target_percent(context.gold, 1.0):
The error =>> "SyntaxError: invalid syntax"

I'm very new to this.

The aim was so that it buys when SMA_50 > SMA_200
But sells once SMA_30 < SMA_50
Vice versa for when shorting.

Any ideas what I'm doing wrong?

2 responses

Maybe a problem with the indentation and the extra colon.

    if sma_50 > sma_200:  
        if context.gold not in open_orders:  
            order_target_percent(context.gold, 1.0)    # remove colon that was at the end  
            if sma_30 < sma_50:    # move to align with line above.  
                order_target_percent(context.gold, 0)  

Not sure how you wanted your IF statements so you may need to adjust. But, I think the colon and indentation are the main issues.

Good luck.

Thanks Dan!