As far as I see at a quick glance, you're never setting CancelOtherTrades back to 0, which you should when all trades are cancelled.


Also, another idea: If you want to make a portfolio version out of this script one day, you would want CancelOtherTrades to be an AssetVar.