当 运行 EA 在 Strategy Tester 中时,MT4 无法打开文件错误 4103

MT4 cannot open file error 4103 when running an EA in Strategy Tester

我使用读入配置文件的指标编写了一个 EA。这个配置文件放在文件夹MQL4\Files.

当我 运行 带有实时图表的 EA 时,它运行良好。但是当我尝试使用策略测试器测试此 EA 时,它 returns 一个 4103 error: can not open file.

知道为什么会这样吗?

以及如何解决这个问题?

发生的事情是 MQL4 生态系统的一个特征:

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.

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

如何解决这个问题?

简单地说,注意只使用文件路径的“relative”规范(并记住,正在使用三种可能的根目录情况中的哪一种其中作案手法 ).

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> }

对于读取文件的情况,对于非FILE_COMMON用例,您可能会强制在两个位置都拥有相同配置文件的副本,或者在<shared_common_directory>