Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Stop loss not working

Hello all,

I am having issues to execute the stop with the new format that is suggested by quantopian. I am not sure what I am doing wrong here because it won't sell the stock ever. Thanks in advance.

1 response

order_percent(stock,0) will order shares of that stock worth 0% of your current portfolio, i.e. none at all. Check the documentation and search for order_percent.

In order to sell shares, you should find the number of shares of the security you are currently holding (context.portfolio.positions[security].amount), and then place an order for an appropriate negative number of shares. (Since selling is like buying a negative number.)

E.g. to sell all, you'd want to place order(security, -context.portfolio.positions[security].amount).