The reason it was canceled because you closed the position that order was associated with. You would have to review your logic so you can better understand the order of events that are happening. One way is to review the order messages and then compare that against your logic which relates to the given orders. Another way is using prints, you can add prints into each part of your conditions to see when each part is becoming true so you can understand how the logic you made works.
If you are having difficulty being able to follow the order of events that your strategy is producing that will pose a large problem when you run the script live, only you will be able to debug the script if something unexpected happens with your code. If that is something which you will have continuing problems with It would likely be to your benefit to work with a third party developer. In that case you would let them know any problems you see and they could then debug and modify the script as needed for you.

Comment