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.
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.
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)
.