Get the path to work on ChartApplyTemplate in MT4
Get the path to work on ChartApplyTemplate in MT4
Loading saved threads...
Jean · External communityPost link
External question — Stack Overflow Stack Exchange
Author: Jean
Original post: https://stackoverflow.com/questions/68072478
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
After reading the material I could find and trying various solutions, I still cannot get the
ChartApplyTemplate
to work. The template is not applying to the chart being opened and the error I receive is 5002 - the file cannot be found.
Here is my code:
int iChartID = ChartOpen(sChartNameL,5); ChartApplyTemplate(iChartID,"C:\\Users\\Jean\\AppData\\Roaming\\MetaQuotes\\Terminal\\DA3C92B1779898CC0CACD726A655BECB\\Files\\ADX.tpl");
Print(GetLastError());
I have also tried:
int iChartID = ChartOpen(sChartNameL,5);
string sTerminalDataPath = TerminalInfoString(TERMINAL_DATA_PATH);
ChartApplyTemplate(iChartID, sTerminalDataPath + "\\MQL4\\Files\\ADX.tpl");
I have tried to place the template in various directories. Files as stated above but I have also tried to insert a files subdirectory in the mql4\experts subdirectory and also tried to use the files subdirectory under the MQL4 subdirectory. I have also left the template in the default templates directory. I have tried these various locations as I believe Metatrader has a sandbox environment for where files may be accessed.
Please can you help me.
Quote
Report
PaulB · External communityPost link
External answer — Stack Overflow Stack Exchange
Author: PaulB
Original post: https://stackoverflow.com/a/68073319
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
You are using the wrong variable type for your chart ID, it should be of type
long
. The code should read as an example.
long iChartID = ChartOpen("EURUSD",5); ChartApplyTemplate(iChartID,"Popular.tpl");
For the location of the template file, from 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.
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: PaulB Source score (net votes, not local likes): 2 Original post: https://stackoverflow.com/a/68073319 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You are using the wrong variable type for your chart ID, it should be of type long . The code should read as an example. long iChartID = ChartOpen("EURUSD",5); ChartApplyTemplate(iChartID,"Popular.tpl"); For the location of the template file, from 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.
Checking account access…