@ L. Williams
A couple of thoughts...
The code you had above (copied below) will simply place an order to close any existing positions. However, it will NOT close any orders that are open but not filled. To really close out, one should also cancel all open orders.
for s in context.portfolio.positions:
order_target(s,0) *# This is issued 120 minutes into the day to ensure we have no carry over*
I changed your original posted algorithm to use 'VolumeShareSlippage'
I've also added some debug code to your algorithm above. You can now see when orders are entered and when they are filled. That might help you see better what's going on. Note the 'order id' in the printout so you can see see how each order progresses. You can see from the 'limit price' and 'last price' outputs that the reason some orders do not fill is that the limit price is not reached.
With the 'VolumeShareSlippage' set to 1.0 the orders will consume 100% of the volume ordered on any given bar. So, if you have an order for 1000 shares and the volume was only 750 shares, then your order would fill 750 shares and still have outstanding 250 shares. You can see this happen in your trading from the logs. If what you want to do is fill 100% of your order REGARDLESS of actual volume then use
That will completely fill your order independent of actual bar volume as long as the bar volume is greater than zero. Your order won't trade in a zero volume bar.
Because in no case will an order fill if there is zero volume in a bar, you can't be 100% certain that positions will all close at the end of the day. (this is very true in live trading also). The following should cover you pretty well though.
for security, order_list in get_open_orders().items():
for open_order in order_list:
for security in context.portfolio.positions: