ChartApplyTemplate and ObjectCreate

 

Can anybody help me, please?

I tried to change chart template and then create a graphical object (horizontal line) in the chart by MQL4.

 

For example:

ChartApplyTemplate(0,”template_name.tpl”);

ObjectCreate(0,obj_name,obj_type,0,obj_time,obj_price);

 

The Template has changed successfully, but the Object hasn’t created.

If I cut out the first line ( ChartApplyTemplate(0,”TMP.tpl”); ), the Object will create successfully.

Any Idea?

 

I would surmise that:

ChartApplyTemplate is being added to the chart message queue, but before it has been processed the ObjectCreate is run.

A short time later, the template gets applied (which doesn't have your new object) and so it appears that your object was never created.

i.e. it was created, but then it got wiped by the application of your template.

 
honest_knave:

I would surmise that:

ChartApplyTemplate is being added to the chart message queue, but before it has been processed the ObjectCreate is run.

A short time later, the template gets applied (which doesn't have your new object) and so it appears that your object was never created.

i.e. it was created, but then it got wiped by the application of your template.


I think you’re right because I have the same opinion ;-)

But I still look for a solution. Inserting ChartRedraw or WindowRedraw between ChartApplyTemplate and ObjectCreate doesn’t help.

Is there a possibility to flush the chart message queue before object creating?

 

ChartApplyTemplate causes a reinitialisation of the indicators on the chart - so the code halts execution at that point.

You will perhaps need to store some flag in a global variable that gets checked upon initialisation if you want any behaviour to take place after the template is applied. 

 
Hoodlum:

ChartApplyTemplate causes a reinitialisation of the indicators on the chart - so the code halts execution at that point.

You will perhaps need to store some flag in a global variable that gets checked upon initialisation if you want any behaviour to take place after the template is applied. 

But there aren’t any indicators in the char.
 
How about the one that you are executing the ChartApplyTemplate command from?
 

The same thing applies if it is a script/EA or whatever - everything gets re-initialised when the template on the current chart is changed as far as I am aware.

In the past, I have had to work around this by using a global variable flag as I mentioned. 

 
Hoodlum:

The same thing applies if it is a script/EA or whatever - everything gets re-initialised when the template on the current chart is changed as far as I am aware.

In the past, I have had to work around this by using a global variable flag as I mentioned. 


ChartApplyTemplate doesn’t halt execution a code because the object has created (but then it will delete by applying a new template).

 

The behavior is like switching the two lines:

 

ObjectCreate(0,obj_name,obj_type,0,obj_time,obj_price);

ChartApplyTemplate(0,”template_name.tpl”);

 
Hoodlum:
How about the one that you are executing the ChartApplyTemplate command from?
I don’t execute the ChartApplyTemplate from an indicator but from a script.
 

Is'nt there any callback or listener function, where we easily get informed when function ChartApplyTemplate completed it's task.

Reason: