2

The following code cannot find a file and returns error 5002, wrong file name.

I include also a file explorer picture showing the file is in existence.

Can you please help me why the file is not found?

if (FileIsExist(TerminalInfoString(TERMINAL_DATA_PATH) + "\\templates\\reitron_trend_trading.tpl"))
     ChartApplyTemplate(0,TerminalInfoString(TERMINAL_DATA_PATH) + "\\templates\\reitron_trend_trading.tpl");
  else
  {
     int iErr = GetLastError(); 
     string sErrDesc = ErrorDescription(iErr);
     Print("Cannot open file - err " + IntegerToString(iErr) + " " + sErrDesc);   
     Print(TerminalInfoString(TERMINAL_DATA_PATH));
     Print(TerminalInfoString(TERMINAL_DATA_PATH) + "\\templates\\reitron_trend_trading.tpl");
   }

enter image description here

The output in my terminal says the following:

2018.03.07 15:59:30.628 Reitron_Scalping_Working_Model_2 EURUSD,M1: C:\Users\Jean\AppData\Roaming\MetaQuotes\Terminal\BB190E062770E27C3E79391AB0D1A117\templates\reitron_trend_trading.tpl when I output the path that I am searching in the program.

Thanks,

Jean
  • 137
  • 1
  • 13

1 Answers1

1

Panta Rhei,
MQL4 still evolves, so be ready for future potential change

The Why-part:

Until recent Build(s) all MQL4-instructed FileIO operations were always sandbox-ed to happen only inside a protected directory location, rooted relatively from this location:
<~TerminalDIRECTORY~>/MQL4/Files and never else.

If a code was run from StrategyTester tool, the FileIO goes in a similar manner yet to another location: <~TerminalDIRECTORY~>/tester/Files and never else.

Simply put, any attempts to perform any FileIO operation "outside" of the said sandbox-es will not be executed at all for isolating potential security reasons.


The How-part:

So, kindly put the intended file anywhere "inside" the said sandbox and voilá, it will become visible for MQL4-fileIO services. That simple.

<~TerminalDIRECTORY~>/MQL4/Files/aNewSubDirForApp/20180307/anythingElse/ is okay for the absolute path-part of the filename, the code will express the snadbox-relative path specification, as in:

int aFileHANDLE = FileOpen(  "aNewSubDirForApp/20180307/anythingElse/"
                            + aFileNAME,
                              FILE_READ
                              );`

So far ( 2017-EoY ) no exceptions from this.

Yet, MQL4 still evolves, so be ready for future potential changes.

user3666197
  • 1
  • 6
  • 50
  • 92
  • Thanks, is there then a way to apply a template with ChartApplyTemplate() where the template is in the default directory for templates? – Jean Mar 07 '18 at 14:32
  • 1
    Maybe yes, maybe no. Best arrange a top-down copy in MT4-launching batch-file, to re-copy ( mirror ) all actual templates from MQL4-non-accessible location downto the sandbox, **that works like HELL :o)** – user3666197 Mar 07 '18 at 15:40