3

I'm using Ubuntu 14 and trying to create a script to write files, but I'm getting the 5004 error, every time I try to open a file.

datetime currtime;
bool     newcandle;

string   terminal_data_path = TerminalInfoString( TERMINAL_DATA_PATH );
string   filename           = terminal_data_path + "\\MQL4\\Files\\" + "data.csv";

int      filehandle;

filehandle = FileOpen( filename, FILE_WRITE | FILE_CSV );

if (  filehandle < 0 ){    
      Print( "Failed to open the file by the absolute path " );
      Print( "Error code ", GetLastError() );
    }
else {
      Print( "file opened with sucess" );
    } 

How can I solve this problem on Ubuntu?

UPDATE

I tried to change my file to the following:

string terminal_data_path = TerminalInfoString( TERMINAL_DATA_PATH );
string filename           = terminal_data_path + "\\tester\\files\\data.csv";

and just for this

string filename = "\\tester\\files\\data.csv";

and for this

string filename = "\\files\\data.csv";

But I'm still getting error, but this time is 5002 not 5004.

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Filipe Ferminiano
  • 8,373
  • 25
  • 104
  • 174
  • 5004 is "ERR_FILE_CANNOT_OPEN" are you sure you've got the right path? Also, does the application have permissions to access that path? – Malt Jan 03 '15 at 02:06
  • If you've figured out the issue, please post that as an answer, and not edit it into the question. Thanks! – Andrew Barber Jan 04 '15 at 04:15

1 Answers1

2

MQL4 Permissions By Design Do Not Allow / Restrict FileIO

There are three directories (with subdirectories) where working files can be placed:

/HISTORY/<current broker> - especially for the FileOpenHistory() function;

/EXPERTS/FILES - common case;

/TESTER/FILES - especially for testing ( ref. during Strategy Tester operations ).

Working with files from other directories is prohibited.

Solution

Adapt your MQL4-code so as to meet this fact and respect pre-Build 762 and post-Build 762 differences ( a "new"-MQL4 file-localisations ).

Update

As posted, your MQL4-code ( whether you share it's updated state or not ) shall better handle exceptions. Have met several suprising artefacts with filenames. Some platform specific, causing no harm in wXP, but failing to operate (the same code) on VPS-hosted wServer2008 VM or a LinuxVM-encapsulated Wine/MT4 instance.

Carefully read MQL4-help documentation and create a few post-mortem tools to step further.

5002
 ERR_FILE_WRONG_FILENAME
 Wrong file name               -------> pre-test + "fuse" the corner cases

5003
 ERR_FILE_TOO_LONG_FILENAME
 Too long file name

5004                           <------ a good sign, we are on the safer side here
 ERR_FILE_CANNOT_OPEN
 Cannot open file

//-------------------------------------------------------------
//   MT4_GUI_postMortem
//-------------------------------------------------------------    
void MT4_GUI_postMortem( string aFileNAME = "caller forgot to pass aFileNAME"
                         ){
  // SYNTAX
  //         if ( aFileHANDLE == INVALID_HANDLE ) MT4_GUI_postMortem( filename );
  //
     int aLastErrorNUM = GetLastError();
     Comment( "POST-MORTEM >>> [", aFileNAME, "] Threw error ", aLastErrorNUM );
     Print(   "POST-MORTEM >>> [", aFileNAME, "] Threw error ", aLastErrorNUM );

     return;
    }   
user3666197
  • 1
  • 6
  • 50
  • 92
  • thanks for the help. I pdated my tries. Can you check it please? – Filipe Ferminiano Jan 03 '15 at 22:41
  • thanks for the help! But I'm lost with your update. I saw the meaning of the 5002 error in the docs. I just don't know to solve this yet. Do you have a better tip for me? – Filipe Ferminiano Jan 04 '15 at 01:02
  • @FilipeFerminiano -- cool to have you almost online -- try a simplest ever filename "test.csv" -- no slashes, nothing else. There start the issue isolation & recovery path. – user3666197 Jan 04 '15 at 01:08
  • Have you ever tried to link MQL4 code with a distributed computing? **If in need and your Project allows, you may setup an interplatform/interprocess messaging between an MQL4 code and literally any external process ( other MT4 thread, other localhost process or remote *anything*, be it GPU-cluster or mobile phone ).** – user3666197 Jan 04 '15 at 01:14