I wrote an EA using an indicator which reads in a configuration file. This configuration file is put in the folder MQL4\Files
.
When I run the EA with the live chart, it works well. But when I tried to test this EA using the strategy tester, it returns an 4103 error: can not open file.
Any idea why this happens?
And how to address this problem?
For security reasons, work with files is strictly controlled in the
MQL4
language. Files with which file operations are conducted usingMQL4
means, cannot be outside the file sandbox.
The file is opened in the folder of the client terminal in the subfolderMQL4\files
( orTester\Files
in case of testing ). IfFILE_COMMON
is specified among flags, the file is opened in a shared folder for all MetaTrader 4 client terminals.
Simply, take care of using just the "relative" specification of the file-path ( and keep in mind, which of the three possible root-directory cases is being used in which modus-operandi ).
aFH = FileOpen( "aFileInsideDefaultDirectoryRoot.txt", ... );
//
// USED:
// in Strategy Tester---+
// plain EA-mode-----|------------+
// FILE_COMMON-mode--|------------|----------------+
// | | |
// RESULTS: v v v
// in a file in { tester\files | MQL4\Files | <shared_common_directory> }
For the case of reading the file, you might enforce to have a copy of the same configuration file in both of the locations for the non-FILE_COMMON
use-cases, or keep a single instance in <shared_common_directory>