How to Open a Chart with a mql4 script?

 
Does anyone know how to open a Metatrader4 chart with a mql4 script. Should I have to use ChartOpen()? For Example: I just want to open the Eur/Usd chart with a specific template.
Thanks a lot.
 
void OnStart() {
   ...
   long IDChart = ChartOpen( "EURUSD", PERIOD_H1 ); // opens new chart
   if ( !ChartApplyTemplate( IDChart , "templateName" ) ) { ChartClose( IDChart ); } // appl. template or kill chart
   else ChartClose( ChartID() ); // closes the chart of the script
   ...
}
PS: Do not try to save the Chart-ID as global variable, Glob-Vars are Double, ChartID are long and generally too big and so the values will differ :( (its a feature not a bug!)
 
gooly:

PS: Do not try to save the Chart-ID as global variable, Glob-Vars are Double, ChartID are long and generally too big and so the values will differ :( (its a feature not a bug!)

A workaround might be to split it and save it as 2 GV's

 

Hello Gooly,

thanks for your quick answer. But Im not sure what you mean by "Do not try to save...". Ive copy and pasted your code into a new script file (deleted ...), but it didnt work. There was a warning called `IDChart`-undeclared identifier. Thanks for your solution.

 
Sry. I forgot something but now it works. Thanks for you help.
 
Timerider:

Hello Gooly,

thanks for your quick answer. But Im not sure what you mean by "Do not try to save...". Ive copy and pasted your code into a new script file (deleted ...), but it didnt work. There was a warning called `IDChart`-undeclared identifier. Thanks for your solution.

1) I forgot to declare long IDChart (I was using a global definition, I have changed it now)

2) I was trying to use the Glob.Vars. for a kind of inter-chart-communication: use a parameter-set which is not jet used on a different chart.

Reason: