Multiple instances of a script

 

Is it possible for the user to run multiple instances of a script simultaneously?

if so, how i can prevent it?

 
isaacarsenal:

Is it possible for the user to run multiple instances of a script simultaneously?


On the same chart? No. On different charts? Yes.


isaacarsenal:

if so, how i can prevent it?


Have your script do the following sequence of events:

Step 1. Look for the existence of a specific globalvariable
if(GlobalVariableCheck("ScriptXYZCurrentlyInUse")==true) return; // Check the global flag to see if a script instance is already in use
Step 2. Create the global variable
else GlobalVariableSet("ScriptXYZCurrentlyInUse",1); // Set the global flag to denote that the script instance is in use
Then do your script routines...

Step 3: At any potential exit point in your script, including the very end, delete the global variable:
GlobalVariableDel("ScriptXYZCurrentlyInUse"); // Delete the flag to denote the script is no longer running somewhere in the terminal