I am trying to create an algo that will sell all open positions. I figured that it would be as simple as the following, but this is not generating any orders. I know that I am not seeing the obvious. Please help me out if you can.
Thank you!
I am trying to create an algo that will sell all open positions. I figured that it would be as simple as the following, but this is not generating any orders. I know that I am not seeing the obvious. Please help me out if you can.
Thank you!
You're pretty close. Instead of
order_target_percent(stock, -1.0)
you will want
order_target_percent(stock, 0)
To sell everything the target percent should be zero not minus one. Putting a minus one for a target value will end up with short positions equal to the value of the portfolio.
Also, I assume this isn't your entire code. If so, the obvious reason that no orders are being generated is that there is not a way for positions to get into the portfolio in the first place. Attached is a similar simple algorithm which buys SPY at the beginning of the week and sells all positions at the end of the week.