ChartApplyTemplate error 5002

 
Hi

Not sure if this question is in the correct topic area.
If not apologize for it


I have a small script (NOT EA) and would like to apply chart templates when a change occurs.
In the end I even tried FUL path yet I keep getting error 5002 (sometimes 5019)

string templateFolder = "C:\\Users\\XXX\\Desktop\\Prive\\MetaTrader 5\\Profiles\\Templates\\";  // Adjust the folder path where your templates are located

I used the folder above as well as \\MQL5\\Profiles\\Templates and the Files folder.
None of them works

      string symbolName = Symbol();  // Get the name of the current symbol
      string terminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH);
      string templateName = templateFolder + "Transfer_" + symbolName + ".tpl";  // Construct template file name
      string templateName1 = templateFolder + "Transfer_" + symbolName + ".tpl";  // Construct template file name

      
     if (FileIsExist(templateName1, 0))
      {
         //ChartApplyTemplate(0, templateName);  // Apply the template to the current chart
         //ChartApplyTemplate(0,TerminalInfoString(TERMINAL_DATA_PATH)+"\\Profiles\\Templates\\"+templateName1);
         ChartApplyTemplate(0,"\\Profiles\\Templates\\"+templateName1);
      }
      else
      {
         //Print("Template not found: ", TerminalInfoString(TERMINAL_DATA_PATH)+"\\Profiles\\Templates\\"+templateName1);
         int error = GetLastError();
         Print("Failed to apply template. Error code: ", error);
         Print(templateName1);
      }   


I assume it would be possible to load a new template when I switch Symbol?

Does anyone know what I am doing wrong or am I trying to do something impossible?


Kind regards

 
No one knows? 
 
      string terminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH);
         ChartApplyTemplate(0,"\\Profiles\\Templates\\"+templateName1);

You can't read (or write) outside the sandbox with normal code.
          File Write Problem (Error: 5002) - Expert Advisors and Automated Trading - MQL5 programming forum #1-2 (2020)

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)

Stop trying to kludge around the problem, fix the problem. Make a hard link for a file, or create a junction (mklink /J) at «DataFolder»\MQL4\Files\«other place» and use the regular file calls. (2022)
          File Path for saving .csv files in MT5 - MQL5 programming forum (2019)
          File Operations via WinAPI - MQL4 Articles (2008)