Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Ichimoku Based Algorithm not executing orders

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)  
2 responses

This may help

# Ichimoku Clouds by Vladimir  
#---------------------------------------------------  
equity = symbol('SPY'); n_f = 9; n_m = 26; n_s = 52;  
#---------------------------------------------------  
def initialize(context):  
    schedule_function(Ichimoku, date_rules.every_day(), time_rules.market_open(minutes = 65))

def Ichimoku(context, data):  
    bars = n_s*2  
    H = data.history(equity, 'high', bars, '1d')  
    L = data.history(equity,'low', bars, '1d')

    tenkan_sen = (H.rolling(n_f,center = False).max() + L.rolling(n_f,center = False).min())/2  
    kijun_sen = (H.rolling(n_m,center = False).max() + L.rolling(n_m,center = False).min())/2  
    senkou_span_a = ((tenkan_sen + kijun_sen) / 2).shift(n_m)  
    senkou_span_b = ((H.rolling(n_s,center=False).max() + L.rolling(n_s,center=False).min())/2).shift(n_m)

    record(senkou_span_a = senkou_span_a[-1], senkou_span_b = senkou_span_b[-1])  

Thanks for the help. Whats the time frame for this?