I am working on a long only algorithm and I'm running into a problem where it shorts a company by an insignificant amount of shares (although it shouldn't be shorting at all). I'm not sure why it is shorting when it should be ordering rather than selling. Below is the coportion of my code that keeps shorting. Where it errors at is the order_target_percent(stock, wgt) when a stock IS NOT IN my portfolio. Any help would be appreciated.
for stock in long_secs:
if (stock not in open_orders) & (stock in context.price_avg):
if (stock not in context.portfolio.positions):
order_target_percent(stock, wgt)
else:
if (data.current(stock, 'price') < float(context.price_avg[stock])):
order_target_percent(stock, wgt)