I think it can be closing in a loss because of these reasons:
1. slippage,
2. orders are closing one by one, so it closes first one at one price and while closing finishes, another trade price moves, so it starts to close second one at different price already.
3. spread changes fast.