You need a decrementing loop for your orderclose function.

Also be sure to make a loop for each conditions, don't add too much conditions in your loop, otherwise it will try to close tickets that have already been closed.