The code looks ok, so it should not stop, unless the closed trade was the only one. If you can't find the reason, you can contact Support with the script. They'll look into it. Maybe it is something that depends on other settings in the script.