Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why is it not selling?

The backtest "work". I use the breakpoints and apparently everything is good... but in real live trading it seems that it's not pulling the triggers.
Any ideas?

Profit_time is schecule to start at market_open ()

def profit_time(context,data):

for stock in context.portfolio.positions:  
    current_position = context.portfolio.positions[stock].amount  
    stock_price = context.portfolio.positions[stock].cost_basis  
    current_price = data.current(stock, 'price')  
    stop_loss = stock_price - (stock_price * 0.02)  
    #This should be inside the condition where is needed, right before trail trigger is compared.  
    #trail_trigger = stock_price + (stock_price * 0.01)  

    try:  

        if current_price < stop_loss and current_position > 0:  
            order(stock, -current_position)  
            context.recent_trades[stock]= data.current(stock,'last_traded')  

        elif not context.stop_price:  
           trail_trigger = stock_price + (stock_price * 0.01)  
           if current_price >= trail_trigger:  
               context.stop_price[stock] = max(context.stop_price[stock]  
                                                if stock in context.stop_price  
                                                else 0, current_price)  
               context.trail_stop[stock] = context.stop_price[stock] * context.stop_pct  

        elif context.stop_price:  
            if stock in context.stop_price:  
                if current_price > context.stop_price[stock]:  
                    context.stop_price[stock] = max(context.stop_price[stock],current_price)  
                    context.trail_stop[stock] = context.stop_price[stock] * context.stop_pct  
                elif current_price < context.trail_stop[stock] and current_position > 0:  
                    order(stock, -current_position)  
                    del context.stop_price[stock]  
                    del context.trail_stop[stock]  
                    context.recent_trades[stock]= data.current(stock,'last_traded')  

                else:  
                    pass  
            else:  
                trail_trigger = stock_price + (stock_price * 0.01)  
                if current_price >= trail_trigger:  
                    context.stop_price[stock] = max(context.stop_price[stock]  
                                                if stock in context.stop_price  
                                                else 0, current_price)  
                    context.trail_stop[stock] = context.stop_price[stock] * context.stop_pct  

        else:  
            print "Why did it go in HERE Line 157"  

    except Exception as (e):  
        print(str(e))