Download MetaTrader 5

ChartApplyTemplate

To add comments, please log in or register
Dua Yong Rew
5554
Dua Yong Rew  

Hi All,

I have some issue trying to apply template to charts that I open using my script. The charts open but the template don't apply when I use ChartApplyTemplate

Here is the code.

 

For loop
{
...

      if(ShowChart && TradeSig)
      {
         ChartOpen(FX_Pairs[i], PERIOD_D1);
         ChartApplyTemplate(0, "\\kiss.tpl");
      }
}
Jose Francisco Casado Fernandez
4658
Jose Francisco Casado Fernandez  
Dua Yong Rew:

Hi All,

I have some issue trying to apply template to charts that I open using my script. The charts open but the template don't apply when I use ChartApplyTemplate

Here is the code.

 

For loop
{
...

      if(ShowChart && TradeSig)
      {
         ChartOpen(FX_Pairs[i], PERIOD_D1);
         ChartApplyTemplate(0, "\\kiss.tpl");
      }
}

Do you have a template with that name inside 'terminal_data_path\MQL5' or inside 'terminal_path\Profiles\templates' ?.

In the other hand, 0 denotes the current chart. If you have a template with that name, it would apply to the current chart, and not to the new opened chart. You would have to replace 0 by the new chart ID. Example:


long chart = 0;

For loop
{
...

      if(ShowChart && TradeSig)
      {
         chart = ChartOpen(FX_Pairs[i], PERIOD_D1);
         if(chart > 0)

         {

         ResetLastError();

         if(!ChartApplyTemplate(chart, "\\kiss.tpl"))
         PrintFormat("Failed to apply template to %I64d,  error code: %d", chart, GetLastError());
         else
         ChartRedraw(chart);
         }
      }
}


Regards

Dua Yong Rew
5554
Dua Yong Rew  
Jose Francisco Casado Fernandez:

Do you have a template with that name inside 'terminal_data_path\MQL5' or inside 'terminal_path\Profiles\templates' ?.

In the other hand, 0 denotes the current chart. If you have a template with that name, it would apply to the current chart, and not to the new opened chart. You would have to replace 0 by the new chart ID. Example:


long chart = 0;

For loop
{
...

      if(ShowChart && TradeSig)
      {
         chart = ChartOpen(FX_Pairs[i], PERIOD_D1);
         if(chart > 0)

         {

         ResetLastError();

         if(!ChartApplyTemplate(chart, "\\kiss.tpl"))
         PrintFormat("Failed to apply template to %I64d,  error code: %d", chart, GetLastError());
         else
         ChartRedraw(chart);
         }
      }
}


Regards

Thanks, Let me try that
To add comments, please log in or register