Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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 3, 2015 at 2: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 4, 2015 at 4:15

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

ERR_FILE_WRONG_FILENAME Wrong file name -------> pre-test + "fuse" the corner cases 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; 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 4, 2015 at 1: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 4, 2015 at 1: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 4, 2015 at 1:14

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.