Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
No backtest results

I want to exit with 10% profit target or 10% stop-loss is the condition for pattern is valid in the code below:

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

def handle_data(context, data):  
    closev = {}  
    closev = history(6, "1d", "close_price")  
    if (closev.iloc[-2][context.stock] > closev.iloc[-1][context.stock] and closev.iloc[-3][context.stock] > closev.iloc[-4][context.stock] and closev.iloc[-1][context.stock] > closev.iloc[-3][context.stock] and closev.iloc[-5][context.stock] > closev.iloc[-6][context.stock] and closev.iloc[-4][context.stock] > closev.iloc[-5][context.stock] ):  
        order_target_percent(context.stock, 1)  
        entry = data[context.stock].close_price  
        order_target_percent(context.stock, -1.0, limit_price = entry * 1.1, stop_price = entry * 0.90)  

But I get no backtest results although there should be trades.

2 responses

This is my new modified code:

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

def handle_data(context, data):  
    closev = {}  
    closev = history(6, "1d", "close_price")  
    if (closev.iloc[-2][context.stock] > closev.iloc[-1][context.stock] and closev.iloc[-3][context.stock] > closev.iloc[-4][context.stock] and closev.iloc[-1][context.stock] > closev.iloc[-3][context.stock] and closev.iloc[-5][context.stock] > closev.iloc[-6][context.stock] and closev.iloc[-4][context.stock] > closev.iloc[-5][context.stock] ):  
        order(context.stock, 1)  
        entry = data[context.stock].close_price  
        order(context.stock, 1, style=LimitOrder(entry*1.1))  
        order(context.stock, 1, style=StopOrder(entry*0.90))  

Still I get no good results. Any ideas how I can change the above code to get a reliable backtest?

I have tried to improve on the algo but I still get an error

USER ALGORITHM:11, in handle_data
if data[context.stock].price > entry*1.03:

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

def handle_data(context, data):  
    closev = {}  
    closev = history(6, "1d", "close_price")  
    if (closev.iloc[-2][context.stock] > closev.iloc[-1][context.stock] and closev.iloc[-3][context.stock] > closev.iloc[-4][context.stock] and closev.iloc[-1][context.stock] > closev.iloc[-3][context.stock] and closev.iloc[-5][context.stock] > closev.iloc[-6][context.stock] and closev.iloc[-4][context.stock] > closev.iloc[-5][context.stock] ):  
        order(context.stock, 1)  
        entry = data[context.stock].close_price  
    if data[context.stock].price > entry*1.03:  
        order(context.stock, 0)  
    if data[context.stock].price < entry*0.97:  
        order(context.stock, 0)  

Can anyone help?