Download MetaTrader 5

ChartApplyTemplate and ObjectCreate

To add comments, please log in or register
Petr Nosek
41
Petr Nosek  

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?

honest_knave
Moderator
2358
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.

Petr Nosek
41
Petr Nosek  
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?

smimon
165
smimon  

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. 

Petr Nosek
41
Petr Nosek  
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.
smimon
165
smimon  
How about the one that you are executing the ChartApplyTemplate command from?
smimon
165
smimon  

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. 

Petr Nosek
41
Petr Nosek  
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”);

Petr Nosek
41
Petr Nosek  
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.
To add comments, please log in or register