Repeated init() Calls

 

I use GlobalVariableSet() in init() call to count number of EAs running on Terminal.

int init()
{
  if(!GlobalVariableCheck("Count_EAs")) 
    {
      GlobalVariableSet("Count_EAs",1);
    }
  else 
    {
      GlobalVariableSet("Count_EAs",GlobalVariableGet("Count_EAs")+1);
    }

  return(0);
}

int deinit()
{
  if(GlobalVariableGet("Count_EAs")<2) 
    {
      GlobalVariableDel("Count_EAs");
    }
  else
    {
      GlobalVariableSet("Count_EAs",GlobalVariableGet("Count_EAs")-1);
    }

  return(0);
}

While Terminal is running with EAs loaded OK and EA count in Global Variables correct, later on the EA count will repeatedly double, indicating repeating init() calls. Example: Count_EAs at 3, sometime later becomes 6, sometime later becomes 9 and etc.

My question is: What Terminal events that can cause only repeated init() calls and does not call deinit() ?

 

Only one I know is a divide by zero in the tester, kills the EA.

 GlobalVariableSet("Count_EAs",GlobalVariableGet("Count_EAs")-1);

This may not be safe, On startup or shutdown of the terminal, these may be done concurrently, but it's two calls so one my clobber another.

Why do you even care it the EA is running on another pair?

 
WHRoeder:

Only one I know is a divide by zero in the tester, kills the EA.

This may not be safe, On startup or shutdown of the terminal, these may be done concurrently, but it's two calls so one my clobber another.

Why do you even care it the EA is running on another pair?


Thanks for your response. No problem in tester.

I use EA_Count as part of Money Management in allocating Free Margin for lot size calculation.

 
You might like to look at my code. I don't count EAs but instead look at all open orders and their max loss in my fm/lot size calculation.
Reason: