Hey guys, I'm trying to write a 13EMA/20SMA cross algo but I'm running into an error whenever I compare the two, any advice?
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
...
def handle_data(context, data):
hist = data.history(context.spy, fields="price", bar_count=30, frequency="1d")
ema_result = talib.EMA(hist, timeperiod=13)
record(ema=ema_result[-1])
sma_result = talib.SMA(hist, timeperiod=20)
record(sma=sma_result[-1])
open_orders = get_open_orders()
if ema_result > sma_result:
if context.spy not in open_orders:
order_target_percent(context.spy, 1.0)
elif sma_result > ema_result:
if context.spy not in open_orders:
order_target_percent(context.spy, -1.0)