Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Not sure why this wont run.

New to both python and Quant. I've been looking at this for hours/referencing google for syntax related to lists and initialization. Totally stumped.

def initialize(context):

import pandas as pd  
import numpy as np  
tpos = ['sold', 'sold', 'sold', 'sold', 'sold'];  
context.t = sid(6653);  

def handle_data(context, data):
MA3D = data.history(context.t, 'price', 3, '1d').mean()
MA3M = data.history(context.t, 'price', 3, '1m').mean()
boughts = tpos.count('bought');
solds = tpos.count('sold');

if boughts < 5: ###buy  
    if MA3M <= MA3D:  
        order_shares(6653, 100)  
        tpos[1] = 'bought'  
        context.bp = data.current(context.t, 'price')  

if solds < 5:  
    if data.current(context.t, 'price') > context.bp:  
        order_target_percent(context.t,-0.20)  
        tpos[1] = 'sold'

My goal is basically to develop a simple algo which trades a few sets of a specific stock at a time based on price. I'm aware this isn't a winning strategy. This algo is only intended as a means of studying success of simple buy sell stategies as a basis for developing future quant algos.