Where to locate files for Strategy tester to find them

 

MT5 has a very bizarre way of handling files... instead of defaulting to the directory where the executable is running it likes to mess things up and confuse the hell out of everyone but putting files in various places and give everyone the runabout... the reason for doing things this way escapes me, though I'm sure there must be one. 

I have a EA which I want to test on historical data. It requires data from a file in order to work.

When running the EA on real data it finds the file without any problems under MQL5/Files but when I try and run it in strategy tester if fails to find the file despite it being there.

I have tried creating a file just to find out where it appears but it doesn't appear anywhere so I guess creating files doesn't work either!

I have tried locating it under Tester and under Common and adding the FILE_COMMON flag but neither worked.

Actually on further analysis it appears to be even more strange. When I try to create a file as long as I do it within OnInit I can create a file in Common/Files but if I create a class, instantiate the class within OnInit which theoretically should be the same thread and open the file in this class it no longer works. I tried to open the file in OnInit and pass the file descriptor to the class, it executes the various reads but tacitly doesn't read in anything at all.

If anyone can explain the logic and how it is supposed to work and where I am going wrong I would be grateful.


 


 
Anthony Eric Gillon Dawson: When running the EA on real data it finds the file without any problems under MQL5/Files but when I try and run it in strategy tester if fails to find the file despite it being there.

FileOpen


Note
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.

...

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.

Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro:

FileOpen


Note
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.

...

The file is opened in the folder of the client terminal in the subfolder MQL5\files (or testing_agent_directory\MQL5\files in case of testing). If FILE_COMMON is specified among flags, the file is opened in a shared folder for all MetaTrader 5 client terminals.

Hi Fernando,

Thanks for your clarification. Normal running of EA is fine. My problem is with using files when running the EA with strategy tester.

When I run strategy tester where does my file have to be for the EA to find it and read it on initialization?

 
Anthony Eric Gillon Dawson: My problem is with using files when running the EA with strategy tester. When I run strategy tester where does my file have to be for the EA to find it and read it on initialization?
Already answered and I even highlighted it --- in one of the "Agent" sub-directories of the "Tester" directory (eg. "C:\...\Tester\Agent-127.0.0.1-3000\MQL5\Files\") or wherever you have installed your tester agents if you did that separately from the MetaTrader installation.
 

I have already tried that. When I place an file in there the first thing the agent does on starting up is delete all files.

Placing a file in any of these directories just gets deleted before it can be opened and read.


And none of these work

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\MQL5

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\MQL5\Files

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\Tester

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\Tester\Files

(using the COMMON flag)

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\Common

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\Common\Files


And using this does work either

#property tester_file "Files\\GBPUSD_PERIOD_H1_20Forecaster.nn"


 
Anthony Eric Gillon Dawson:

I have already tried that. When I place an file in there the first thing the agent does on starting up is delete all files.

Placing a file in any of these directories just gets deleted before it can be opened and read.

And none of these work

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\MQL5

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\MQL5\Files

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\Tester

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\1640F6577B1C4EC659BF41EA9F6C38ED\Tester\Files

(using the COMMON flag)

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\Common

C:\Users\antho\AppData\Roaming\MetaQuotes\Terminal\Common\Files

And using this does work either

#property tester_file "Files\\GBPUSD_PERIOD_H1_20Forecaster.nn"


When using the "Common" flag (because you want a persistent file to read) it will be the "...\AppData\Roaming\MetaQuotes\Terminal\Common\Files ", and I just tested it and it worked both on the OnInit and OnTick!
When NOT using the "Common" and for writing or appending, it will be in the "Agent" sub folders. I just tested that again and it worked on mine.
I am using the lastest official release, build 2875.

 

You are right, I stand corrected. 

I just found the failure was caused by something else.

Apologies and thank you for your assistance.


 
Anthony Eric Gillon Dawson:You are right, I stand corrected. I just found the failure was caused by something else. Apologies and thank you for your assistance.

No worries. You are welcome!
 
Fernando Carreiro #:

When using the "Common" flag (because you want a persistent file to read) it will be the "...\AppData\Roaming\MetaQuotes\Terminal\Common\Files ", and I just tested it and it worked both on the OnInit and OnTick!
When NOT using the "Common" and for writing or appending, it will be in the "Agent" sub folders. I just tested that again and it worked on mine.
I am using the lastest official release, build 2875.

Hi Fernando,

is there any way that we can change to path to the same place as non-stratey tester ?
like mine is. I want both strategy test and non-strategy tester read from this foler. I dont want in the common one. Because a friend of mine is using mac and there is no common folder. Also on mac there is no tester folder either. that is the reason why i want this

MetaQuotes\Terminal\ED480984639B96B48C6EBB5DA707E011\MQL5\Files

 
@tantran201094 #: is there any way that we can change to path to the same place as non-stratey tester ? like mine is. I want both strategy test and non-strategy tester read from this foler. I dont want in the common one. Because a friend of mine is using mac and there is no common folder. Also on mac there is no tester folder either. that is the reason why i want this MetaQuotes\Terminal\ED480984639B96B48C6EBB5DA707E011\MQL5\Files

On Windows you can use a NTFS Junction Point to make one point to the other.

However, on a mac, MetaTrader runs in a virtualised or emulated Windows environment, so there is definitely a "common" folder and there is also separate tester folder.

You just need to figure out where those folders are in the virtualised/emulated environment.

 
Is this already solved?
I had the same problem then I added the flag: FILE_SHARE_READ and it worked.

The problem was that all the cores wanted to open the file then the error came.