Download MetaTrader 5
To add comments, please log in or register
Write your articles using our editor. It is convenient!
Timerider
78
Timerider 2014.09.11 14:19 
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.
Carl Schreiber
5940
Carl Schreiber 2014.09.11 14:55  
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!)
Ian Venner
2583
Ian Venner 2014.09.11 15:17  
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

Timerider
78
Timerider 2014.09.11 15:33  

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.

Timerider
78
Timerider 2014.09.11 15:35  
Sry. I forgot something but now it works. Thanks for you help.
Carl Schreiber
5940
Carl Schreiber 2014.09.11 15:46  
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.

/
To add comments, please log in or register