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

Here is my sell logic, i want to sell at a 3 percent gain or at a 3 percent loss, or thirty day high im wondering if it is actually doing what im telling it to... (code also in backtest)

    open_orders = get_open_orders()  
    if data.can_trade(stock) & (stock not in open_orders):  
        #Since parent if-statement will be inside for loop (as stated above)  
        if context.account.leverage > 2.7:  
            if stock in context.portfolio.positions:  
                order_target_percent(stock,0)  
            continue  
        buy = currentcash > .05 * context.portfolio.portfolio_value  
        if (stock not in context.portfolio.positions):  
            if (buy and last_close < min_close):  
                currentcash -= context.portfolio.portfolio_value * .05  
                order_target_percent(stock, 0.05)  
                orders += 1  
        elif (last_close >= max_close or (buyprice!=0 and (buyprice-curprice)/buyprice<=-.05) or buyprice!=0 and (buyprice-curprice)/buyprice>=.5):  
            order_target_percent(stock, 0)  
            orders += 1  

    if orders > 200 : break