ChartApplyTemplate applying to _Symbol chartID, not desired ChartID

 

I want to apply a template on a chart other than the default chart for _Symbol.  I can successfully create a new chart and pass that chartID down to a function of mine which is supposed to apply a template in the Template directory, based on a constructed name, to the new chart.

‌In the debugger I can step down to the last If test in the function below, which is true and a template is loaded on the default chart, not the chartID passed to ChartApplyTemplate and my EA restarts -- does not load the template on the new chart I createds.

‌I've put a couple log (Print) statements just to confirm what I see.  Any ideas on what is happening in ChartApplyTemplate in my code and any workarounds?


bool reloadTemplate(string co, long chartid,ENUM_TIMEFRAMES per = PERIOD_CURRENT) {

   string sym = ChartSymbol(chartid);

   if (per == PERIOD_CURRENT) per = getBotPeriod();



   long c = ChartID();

   string terminal_path = "";

  

   log("reloadTemplate(): Attempting Template " + terminal_path + co + "_" + sym + "_" + curr_template_name + " reload");



   if (!ChartApplyTemplate(chartid, terminal_path + co + "_" +  sym + "_" + curr_template_name)) {

       log("reloadTemplate(): WARNING failed to apply template " + terminal_path + co +"_" + sym + "_" + curr_template_name);

       log("reloadTemplate(): Attempting Template " + terminal_path + sym + "_" + curr_template_name + " reload");



       if (!ChartApplyTemplate(chartid, terminal_path + sym + "_" + curr_template_name)) {

           log("reloadTemplate(): WARNING failed to apply template " + terminal_path + sym + "_" + curr_template_name);



           log("reloadTemplate(): Attempting Default Template " + terminal_path + curr_template_name + " reload");

           if (!ChartApplyTemplate(chartid, curr_template_name)) {

               log("reloadTemplate(): failed to apply template "+ terminal_path + curr_template_name+" : "+ErrorDescription(GetLastError()));

           }

       } else {

       }

   } else {

   }

   return (false);
Reason: