ChartApplyTemplate and ObjectCreate

Back to topics list To post a new topic, please log in or register
avatar
5
Nosek1705 2015.10.10 16:01
 

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?


avatar
735
honest_knave 2015.10.12 00:34 #
 

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.


avatar
5
Nosek1705 2015.10.16 15:20 #
 
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?


avatar
40
Hoodlum 2015.10.16 15:21 #
 

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. 

avatar
5
Nosek1705 2015.10.16 15:36 #
 
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.
avatar
40
Hoodlum 2015.10.16 15:41 #
 
How about the one that you are executing the ChartApplyTemplate command from?
avatar
40
Hoodlum 2015.10.16 15:43 #
 

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. 

avatar
5
Nosek1705 2015.10.16 16:21 #
 
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”);


avatar
5
Nosek1705 2015.10.16 16:22 #
 
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.
Back to topics list  

To add comments, please log in or register