Calculating Chart numbers for emergency measures

 

So I've created a simple EA that shuts the superfluous orders as soon as they are in profit as long as the orders number exceeds the maximum int granted. 

My code for now is this: 

void DeployErrorCloser(){





if(CalculateCurrentNonUserOrders(Symbol()) > MaxOrderPerSymbol)

   {


 long Chart = ChartOpen(Symbol(),Period());
ChartApplyTemplate(Chart,"Emergency");
}
   

else
ChartClose(Chart);



}

Problem is that due to the fact that this function is bound to OnTick, a new chart will pop on every tick when the condition is met. Is there anyway to count the new charts opened similar to something like this:

if(TotalNewCharts < 1) DeployChart();
else                   return;

Thanks in advance! 

 
  1. Closing down orders has nothing to do with creating charts.
  2. You do realize you pay the spread on each order created?
 
William Roeder:
  1. Closing down orders has nothing to do with creating charts.
  2. You do realize you pay the spread on each order created?
Sure I do, I’m just willing to understand if there’s a way to count new opened charts