Why can't I get "ChartApplyTemplate" to work properly?

 

Hello!
I have a button on my EA that opens another chart and tries to apply a template on it.

Here's the code that deals with the action caused by the button. I even wait 5 seconds after the chart opens to apply the template:


 if (sparam == "abreJanelas"){
 long chartid = ChartOpen("BMOB3",PERIOD_M30);
   Sleep(5000);
 ChartApplyTemplate(chartid,"Ultimate.tpl");

 }

The thing is: the template is only activated randomly when I press the button. A new chart always opens but most times the template is not applied to the chart. Eventually it does, but not always! ChartApplyTemplate always returns true, though, even when the template is not applied to the chart.

How can I make ChartApplyTemplate react correctly and apply the template to the chart?

Thank you so much!

 
by using ChartRedraw() after ChartApplyTemplate() I was able to make the changes be effective.
Now I have another issue: my template has an EA. When I apply this template manually, the "allow algo trading" setting inside the EA is ticked. But when applying this template using ChartApplyTemplate(), it is always unticked (algo trading deactivated). Is there a way to make the algo trading option inside the EA ("common" tab) to be always active? Thank you so much