Back to Community
Unknown Error Help

In an effort to build an EMA crossover, I am starting to learn the coding behind it using the videos here on quantopian. Can anyone tell me why this code isn't working? Thanks!

from quantopian.pipeline.data.builtin import USEquityPricing
from quantopian.pipeline.filters.morningstar import Q1500US

def initialize(context):
context.spy = sid(8554)

def handle_data(context, data):
# Calculate Technicals Here
hist = data.history(context.spy, 'price', 50, 1d)
log(hist.head())
sma_50 = hist.mean()
sma_20 = hist[20:].mean()
# Control Leverage Here
open_orders = get_open_orders()

# Trade Here  
if sma_20 > sma_50:  
    if context.spy not in open_orders:  
        order_target_percent(spy, 1.0)  
elif sma_20 < sma_50:  
    if context.spy not in open_orders:  
        order_target_percent(spy, -1.0)  

# Record Data Here  
record(leverage = context.account.leverage)  
record(buying power = context.account.buying_power)

Update: Figured out the build algorithm button helps to find the errors. Oops...