Close All Orders (Positions)

But when does it close the positions? Let´s say I have a tp set but I want to close my positions before my tp or sl is hit how do I then use this script to close all of my positions?
 
But when does it close the positions? Let´s say I have a tp set but I want to close my positions before my tp or sl is hit how do I then use this script to close all of my positions?
It closes the positions just when you run it. It's a script - it executes only once and that's it. It doesn't stay attached to the chart.
 
I tried to attach the script on the charts but it gets removed whenever I try. Also, the icon does not become the blue hat in the navigator tab.
 
I tried to attach the script on the charts but it gets removed whenever I try. Also, the icon does not become the blue hat in the navigator tab.
It's a script - it runs once and then gets unloaded. That's how it's supposed to work. Why would you want it to remain constantly active anyway? So that all trades are closed immediately once you open them?
 
I am running a series of EAs and I need the script to constantly remove all the trades once a profit target reached. Then the whole series starts again. I got another script from MQL5 community that does this but it's too slow it closes one by one. I was thinking since your script allows closing all trades at once after you adjusted Async to true maybe it can help me fulfil my strategy. Slippage is high closing 50 trades one by one. Can you help me to make it possible? Thanks.
 
I am running a series of EAs and I need the script to constantly remove all the trades once a profit target reached. Then the whole series starts again. I got another script from MQL5 community that does this but it's too slow it closes one by one. I was thinking since your script allows closing all trades at once after you adjusted Async to true maybe it can help me fulfil my strategy. Slippage is high closing 50 trades one by one. Can you help me to make it possible? Thanks.
Then you need an EA, not a script. Account Protector should do the thing:
https://www.earnforex.com/metatrader-expert-advisors/Account-Protector/