How to open only 1 chart at a time

 
Hello guys I have the below code that is supposed to open a chart and apply template, the issue is multiple charts are being open 
void OPEN_CHART()
   {
      bool openchart = true;
      
      if(openchart)
         {
            long chartid   = ChartOpen(symbol,period);
            ChartApplyTemplate(chartid,templates);
            openchart = false;
         }
   }
 

Of course, it does. Your boolean is always true, your if always executes. You are not remembering anything.

Use a static (or global) variable to remember.

 
William Roeder #:

Of course, it does. Your boolean is always true, your if always executes. You are not remembering anything.

Use a static (or global) variable to remember.

Thanks

Reason: