My code:
def initialize(context):
context.security = sid(8554) #spy
context.risk = 4.0 #4%
def handle_data(context, data):
#hist = data.history(context.security, 'price', 7200,'1m')
ma21 = data.history(context.security, 'price', 21, '1m')
ma55 = data.history(context.security, 'price', 55, '1m')
# Divide fast_ma by slow_ma to get momentum factor and z-score.
momentum = ma21 / ma55
#momentum_factor = momentum.zscore()
# EXECUTE TRADES
if ma21 > ma55:
order_target_percent(context.security, context.risk)
elif ma55 > ma21:
order_target_percent(context.security, -context.risk)
The error:
ValueError:Series lengths must match to compare Line: 18 inhandle_data
if ma21 > ma55:
Can me someone please tell what the fuck is wrong with that super simple condition?
Thanks.