question about ChartApplyTemplate

To add comments, please log in or register
faustf
137
faustf  

hi guys 

i have  a  question i try to do a little script for attach a template.

My template is located in  C:\\Users\\pc\\AppData\\Roaming\\MetaQuotes\\Terminal\\B6FECCFE53E01D2BAC26AAD9B14029A8\\templates\\BollingerBands.tpl

i read in manual  , if a template is not found in the first two variants, the search is performed in the folder terminal_directory\Profiles\Templates\.

therfore  i can use this code

   if(FileIsExist("BollingerBands.tpl"))

 without  path , i run  but  the condition return me False

if i set all path , the same  error

what wrong???

Naguisa Unada
524
Naguisa Unada  
"FileIsExist" searches in "MQL4 \ Files".
Sharon Aharonov
222
Sharon Aharonov  

Until the last MT4 version 1170 you could use the sign "../" in the FileIsExist function and therefore you could actually enter into the template folder, even if the FileIsExists searches in MQL4 \ Files directory.

So if you still use an old version you can find the template file by the path "../../templates"

But if you use the 1170 version, it seems that it's not working.

I'll glad to know if you found any way to do it. 

faustf
137
faustf  

so for clarify my  mind , 

i use  build 1170  version 4 ,  the  installation create  one  folder  template  in  C:\FOREX\MetaTrader\templates   (where live metarader.exe) and other C:\Users\pc\AppData\Roaming\MetaQuotes\Terminal\B6FECCFE53E01D2BAC26AAD9B14029A8\templates

i  copy in both  folder  BollingerBands.tpl ,  and not  work , return me always  not exist blablabl..

but  if  i specify a  path filexist  should find  in other path ???

i try to use

if(FileIsExist("../templates/BollingerBands.tpl"))

but  have the same problem:(

thankz  again at all

faustf
137
faustf  

i  answer me in part

For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox.

If common_flag = FILE_COMMON, then the function looks for the file in a shared folder for all client terminals \Terminal\Common\Files, otherwise the function looks for a file in a local folder (MQL4\Files or MQL4\Tester\Files in the case of testing).

f .... hell  :|

bwcause  my problem born , if  i want  atach boligerband  over graph  ,   how  is possible to do that ?? :(
Trinh Dat
47098
Trinh Dat  

Hi

copy tpl file to Files folder, then you can use the code.

ChartApplyTemplate(ID_CHART,"\\Files\\BollingerBands.tpl");

use the code to save tpl to Files folder.

ChartSaveTemplate(ID_CHART,"\\Files\\BollingerBands.tpl");
https://www.mql5.com/en/docs/chart_operations/chartapplytemplate
Documentation on MQL5: Chart Operations / ChartApplyTemplate
Documentation on MQL5: Chart Operations / ChartApplyTemplate
  • www.mql5.com
Applies a specific template from a specified file to the chart. The command is added to chart messages queue and will be executed after processing of all previous commands. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. If the...
Sharon Aharonov
222
Sharon Aharonov  
faustf:

so for clarify my  mind , 

i use  build 1170  version 4 ,  the  installation create  one  folder  template  in  C:\FOREX\MetaTrader\templates   (where live metarader.exe) and other C:\Users\pc\AppData\Roaming\MetaQuotes\Terminal\B6FECCFE53E01D2BAC26AAD9B14029A8\templates

i  copy in both  folder  BollingerBands.tpl ,  and not  work , return me always  not exist blablabl..

but  if  i specify a  path filexist  should find  in other path ???

i try to use

if(FileIsExist("../templates/BollingerBands.tpl"))

but  have the same problem:(

thankz  again at all

As I said, it seems that you can't use the "../" in build 1170  :-/

Sharon Aharonov
222
Sharon Aharonov  
Trinh Dat:

Hi

copy tpl file to Files folder, then you can use the code.

use the code to save tpl to Files folder.

https://www.mql5.com/en/docs/chart_operations/chartapplytemplate

Hi Trinh,

The problem is that at the new build 1170, the function ChartSaveTemplate save the file at the templates directory and refuse to save it in other directories.

On the other hand, the function FileIsExist (on the new build 1170) can't find files if they are outside the Files directory.

I asked here  https://www.mql5.com/en/forum/298112 for a solution but got nothing yet..

FileIsExist return error 5002 (file not found)
FileIsExist return error 5002 (file not found)
  • 2019.01.06
  • www.mql5.com
I'm trying to copy a temporary .tpl file that I saved using the ChartSaveTemplate function into the Files directory. The...
Alain Verleyen
38753
Alain Verleyen  
Sharon Aharonov:

Hi Trinh,

The problem is that at the new build 1170, the function ChartSaveTemplate save the file at the templates directory and refuse to save it in other directories.

...

That's not exact, use the correct syntax and fix your code.

Sharon Aharonov
222
Sharon Aharonov  
Alain Verleyen:

That's not exact, use the correct syntax and fix your code.

Hi Alain,

So what is the correct syntax?

How can I save a template file in the Files directory by using the ChartSaveTemplate() function?

Or, How can I get a file from the templates directory, using the FileIsExist() function?

Because as I wrote, until the new build 1170 I did it with no problem, but now its failed.


BTW, I need all of these to detect if an EA attached to the Chart, so if you know about another elegant way to detect it I'll glad to hear about it.


Thanks,

Petr Nosek
3059
Petr Nosek  
Sharon Aharonov:

How can I save a template file in the Files directory by using the ChartSaveTemplate() function?

ChartSaveTemplate(chartID,"\\Files\\Template\\tmp.tpl");

Pay attention whether the folder "Template" (in my example) really exists. Of course you can write a template direct into Files.


Sharon Aharonov:

Or, How can I get a file from the templates directory, using the FileIsExist() function?

I'm afraid that it isn't possible in the build 1170 (without dll). If I'm wrong I'll appreciate some advice.

12
To add comments, please log in or register