How to apply a custom template

 

Hi everyone,

I want to apply a custom template, so that my EA immediately starts to change/show the chart with that template. It is called "normal.tpl"

Before, I want to check if that file is existing. So I print my terminal data path

  // Print the terminal data path
   string terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
   Print(terminal_data_path);

which prints

 G:\Meine Ablage\Trading\MetaTrader 4 IC Markets

and ask if there is the file I want to apply. I read in the documentation

  • 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\MQL4,
  • if there is no backslash, the template is searched for relative to the executable EX4 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.
   // is there a file called "normal.tpl"?
   
     if(FileIsExist("\templates\normal.tpl")){
      Print("The file normal.tpl found");
      }
      else{
      Print("NOT FOUND");
      }

It always prints NOT FOUND.

Same with

if(FileIsExist("templates\normal.tpl")){

 or

if(FileIsExist("\\normal.tpl")){

or

if(FileIsExist("\normal.tpl")){

Yet, to try everything, I manually under windows copied the file "normal.tpl"

- in  G:\Meine Ablage\Trading\MetaTrader 4 IC Markets\normal.tpl

- in  G:\Meine Ablage\Trading\MetaTrader 4 IC Markets\templates\normal.tpl

- in  G:\Meine Ablage\Trading\MetaTrader 4 IC Markets\MQL4\normal.tpl

- in  G:\Meine Ablage\Trading\MetaTrader 4 IC Markets\MQL4\templates\normal.tpl


I am sure it is a very simple problem, yet I struggle to find the correct file path

 
Sam Flowdux: I am sure it is a very simple problem, yet I struggle to find the correct file path
     if(FileIsExist("\templates\normal.tpl")){

All file accesses are in the sandbox; you do not specify the path. «DataFolder»/Files or «DataFolder»/tester/files. You are trying to read «DataFolder»/Files/templates/normal.tpl.

You can't read (or write) outside the sandbox with normal code.

For security reasons, work with files is strictly controlled in the MQL5 language. Files with which file operations are conducted using MQL5 means, cannot be outside the file sandbox.
          FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5

File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)
and FolderDelete using TERMINAL_DATA_PATH - General - MQL5 programming forum (2017)