错误代码5004 - 页 4

 
samoye: 请问5004错误有什么解决办法吗?我在尝试向文件写入时也得到了同样的错误信息。
提问和回答。在循环之前打开一次 文件。循环 关闭文件。
 

看来错误5004是与未关闭文件 有关的!


int readFileImg (string file_name) {

   int filehandle = FileOpen(file_name, FILE_READ|FILE_BIN);

   if (filehandle!=INVALID_HANDLE) {

      FileClose(filehandle);  // this line is important, without this line you will get 5004

      Alert("done");

   } else Alert("Operation FileOpen failed, error ",GetLastError(), TerminalInfoString(TERMINAL_DATA_PATH));

   return filehandle;

}

 

请使用</>按钮来插入你的代码。


 

我在使用Strategy Tester 测试EA的时候也出现了同样的5004错误。这一定是mt4的一个错误,因为它可以在同一会话中打开其他文件,但突然不能打开文件。

我用它来回测一个机器学习算法。

现在我需要另一个平台来回测这个算法,因为mt4不工作了。

有没有其他回测平台的想法?

最好是基于python的。

 
试试MT5。
 
kypa:
试试MT5。

我正在尝试调试我的程序,我有同样的问题。

根据FileOpen文档中的例子,我创建了这个函数,从一个文件中读取一个符号列表。

我在编辑器的 "文件目录 "中包含了这个文件,我就这样调用这个函数。


GetSymbolsFromFile("carteiras","ibrx_100_2018_12_10.txt");
//+------------------------------------------------------------------+
//| Get the symbols                                                  |
//+------------------------------------------------------------------+
void TProgram::GetSymbolsFromFile(const string filePath, const string fileName)
{
   //--- additional variables 
   int    str_size; 
   string str;
   int    array_size;
   string terminal_data_path;
   
   //--- open the file 
   ResetLastError(); 
   //--- Release the symbol array
   ::ArrayFree(m_file_symbols);
   
   terminal_data_path=TerminalInfoString(TERMINAL_DATA_PATH);
   PrintFormat("File path: %s\\Files\\",terminal_data_path);
   
   bool  test1 = FileIsExist(fileName,0 );
   bool  test2 = FileIsExist(fileName,FILE_COMMON);
   
   int file_handle=FileOpen(fileName,FILE_READ|FILE_TXT|FILE_ANSI); 
   if(file_handle!=INVALID_HANDLE) 
   { 
      PrintFormat("%s file is available for reading",filePath); 
      //PrintFormat("File path: %s\\Files\\",terminal_data_path);
      //--- read data from the file 
      while(!FileIsEnding(file_handle)) 
        { 
         //--- find out how many symbols are used for writing the time 
         str_size=FileReadInteger(file_handle,INT_VALUE); 
         //--- read the string 
         str=FileReadString(file_handle,str_size); 
         
         array_size=::ArraySize(m_file_symbols);
         ::ArrayResize(m_file_symbols,array_size+1);
         m_file_symbols[array_size]=str;
         
         //--- print the string 
         PrintFormat(str); 
        } 
      //--- close the file 
      FileClose(file_handle); 
      PrintFormat("Data is read, %s file is closed",fileName); 
   }
   else
   {
      PrintFormat("Failed to open %s file, Error code = %d",fileName,GetLastError()); 
   }
}

我尝试了许多不同的参数和filePaths

1 - 试图使用热敏文件路径,但这些都不起作用。

 int file_handle=FileOpen(fileName,FILE_READ|FILE_TXT|FILE_ANSI); 

我得到了这些错误。5002 e 5004

err_wrong_filename

5002

无效的文件名

err_cannot_open_file

5004

文件打开错误

附加的文件:
原因: