How can I apply template to a newly opened Chart

 

Hi all,

I use the code below to apply template to newly opened chart but it is not working as intended.

It doesn't work or it works after a minute or something. And also if I open another chart and close it then it applies template to the chart I want.

  ChartApplyTemplate(ChartOpen(_Symbol,_Period),"mytemplate.tpl");
Documentation on MQL5: Chart Operations / ChartApplyTemplate
Documentation on MQL5: Chart Operations / ChartApplyTemplate
  • www.mql5.com
Applies a specific template from a specified file to the chart. The command is added to chart messages queue and will be executed after processing of all previous commands. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. If the...
 
  1. It takes time to open the chart. Sleep five seconds between the open and the apply.
  2. Do you understand that if you name the template Default.tpl it will be automatically applied?
 
William Roeder:
  1. It takes time to open the chart. Sleep five seconds between the open and the apply.

An answer which again shows primitivity of MQL environment. Even javascript has ability to "wait until first function is done".

btw sleep didn't work.

"Do you understand that if you name the template Default.tpl it will be automatically applied?"

I even know tester.tpl