Download MetaTrader 5

ChartApplyTemplate()

To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
Ziheng Zhuang
1524
Ziheng Zhuang 2015.05.12 21:05 

Hello, I want to load a template  to a back-testing chart, but I got an error#5019:ERR_FILE_NOT_EXIST.

Code same as below:

//+------------------------------------------------------------------+
//|                                            test_loadtemplate.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---    
     if(MQLInfoInteger(MQL_TESTER)) 
     {
      if(!ChartApplyTemplate(0,"ADX.tpl"))  Print("Load ADX.tpl template error# ",GetLastError());
      // error#5019:ERR_FILE_NOT_EXIST
     } 
     
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
     int test = 0;
  }

 Any suggestion is preciated !

Ziheng Zhuang
1524
Ziheng Zhuang 2015.05.13 17:05  
Any suggestion?
Alain Verleyen
Moderator
30736
Alain Verleyen 2015.05.13 17:42  
Ziheng Zhuang:
Any suggestion?

Where is saved your template ?

The ChartApplyTemplate() function is intended for using a previously saved template, and it can be used in any mql5 program. The path to the file that stores the template is passed as the second parameter to ChartApplyTemplate(). The template file is searched according to the following rules:

  • if the backslash "\" separator (written as "\\") is placed at  the beginning of the path, the template is searched for relative to the path _terminal_data_directory\MQL5,
  • if there is no backslash, the template is searched for relative to the executable EX5 file, in which ChartApplyTemplate() is called;
  • if a template is not found in the first two variants, the search is performed in the folder terminal_directory\Profiles\Templates\.
Ziheng Zhuang
1524
Ziheng Zhuang 2015.05.14 10:34  
Alain Verleyen:

Where is saved your template ?

It is saved in  terminal_directory\Profiles\Templates\
Alain Verleyen
Moderator
30736
Alain Verleyen 2015.05.14 12:04  
Ziheng Zhuang:
It is saved in  terminal_directory\Profiles\Templates\

So that dosn't work with the Strategy Tester.

You can name a template as your EA (yourEAname.tpl) and it will be loaded automatically.

Ziheng Zhuang
1524
Ziheng Zhuang 2015.05.14 12:40  
Alain Verleyen:

So that dosn't work with the Strategy Tester.

You can name a template as your EA (yourEAname.tpl) and it will be loaded automatically.

  Thank you.  

   Tested,it is a convenient method. 

To add comments, please log in or register