The only issue here with your code is that everytime your stop order is cancelled you will reverse position. So if your Profit Target gets his for examply and you exit the trade you will reverse position.
This is why you need some sort of flag to be set for when you want to actually reverse.
I look forward to assisting you further.
Comment