Download MetaTrader 5

CChart class

To add comments, please log in or register
Launch your trading signal and add account monitoring!
NTFS
650
NTFS 2013.03.30 11:24 

Hello!

I wrote a simple script

 

#include    <Charts\Chart.mqh> 

void OnStart()

  {

   CChart xChart;

   xChart.ApplyTemplate("blank");

  } 

 in order to apply a template to the current chart. But when I run it nothing happens. I can successfully apply the very same template throught context menu  "right click\templates\blank", but when I run the script there is no reaction whatsoever from the terminal. Obviously there is a mistake here and should be very stupid, but I cannot figure it out  

I googled for applytemplate CChart but found nothing. Could anyone point me to the solution?

Thank you! 

Alain Verleyen
Moderator
30743
Alain Verleyen 2013.03.30 11:50  
ns_k:

Hello!

...

Thank you! 

Hello,

Please use SRC button when you post code.

Alain Verleyen
Moderator
30743
Alain Verleyen 2013.03.30 11:54  
  • Check the returned value of the function ApplyTemplate, and you see there is a problem. See documentation.
  • You have to open your chart.
  • As you use a script, it runs and directly terminates so you don't see anything.

If you want to see you chart, add a loop to your script like this :

    CChart xChart;

    xChart.ApplyTemplate("blank");     // You have to modifiy this code to use your template
    xChart.Open("EURUSD", PERIOD_H2);
    while(!IsStopped()) {}
Then attach you script to a chart.
NTFS
650
NTFS 2013.03.30 12:10  
angevoyageur:
  • Check the returned value of the function ApplyTemplate, and you see there is a problem. See documentation.
  • You have to open your chart.
  • As you use a script, it runs and directly terminates so you don't see anything.

If you want to see you chart, add a loop to your script like this :

Then attach you script to a chart.

Hello!

Thank you for a fast reply!

I tried your suggestion. Now I can see a chart as long as a script runs.

What I am trying to achieve is:

I have a chart opened in terminal. Now I want to run my script in order to apply to the current chart the blank template. I guess I should somehow tell CChart to use a current chart instead of opening another one. 

How can I do that?

Thank you! 

NTFS
650
NTFS 2013.03.30 12:13  

Ooops, sorry. I've got your point about documentation now.

Thank you!! 

Alain Verleyen
Moderator
30743
Alain Verleyen 2013.03.30 12:17  
ns_k:

Ooops, sorry. I've got your point about documentation now.

Thank you!! 

Ok, I missed the point about current chart. Tell us if reading documentation help you.

Anyway, why using a script to apply a template, when you can apply your template directly from MT5 terminal ?

NTFS
650
NTFS 2013.03.30 15:32  
angevoyageur:

Ok, I missed the point about current chart. Tell us if reading documentation help you.

Anyway, why using a script to apply a template, when you can apply your template directly from MT5 terminal ?

Yes it did as it always does :)

I try to automate daily routine with MT5 features. Instead of working with external DDL calls as it was in MT4 (for example to apply a template to the current chart), I run only MT5 code which is much easier.

Thank you for your help! 

To add comments, please log in or register