A few bars later, I created a sell order to sell out whole stakes in next(). However, previous bracket order (stop loss) has also been triggered and both orders have been executed and position goes to negative. Do you have any idea how to avoid that?

Yes, that is what happened. Is there any mechanism available in BackTrader to support long-only strategy?
If not, I need to manage all active sell order in the implementation of my strategy and cancel all (some) of them before issuing new sell order, right?