I'm new to Quantopian and just took my first shot at writing an algorithm. I based it off the Ichimoku technical analysis indicator. When I back test it, no orders are executed and I'm not sure why.
def initialize(context):
context.assets = [sid(24)]
def handle_data(context, data):
hist = data.history(context.assets, "price", 260, '1m')
log.info(hist.head())
ph_52 = hist.max()
ph_26 = hist[-130:].max()
ph_9 = hist[-45:].max()
pl_52 = hist.min()
pl_26 = hist[-130:].min()
pl_9 = hist[-45:].min()
tenkan = ((9-ph_9)+(9-pl_9))/2
kijun = ((26-ph_26)+(26-pl_26))/2
span_a = (tenkan+kijun)/2
span_b = ((52-ph_52)+(52-pl_52))/2
tenkan_last = tenkan[-1]
kijun_last = kijun[-1]
span_a_last = span_a[-1]
span_b_last = span_b[-1]
i = 0
stock = context.assets[i]
open_orders = get_open_orders()
if (tenkan_last>kijun_last) & (span_a_last > span_b_last):
if stock not in open_orders:
order_target_percent(stock, 1.0)
elif (kijun_last>tenkan_last) | (span_b_last > span_a_last):
if stock not in open_orders:
order_target_percent(stock, 0)