• Join us

Error Code 5004 - page 2

To add comments, please log in or register
RaisingFire
54
RaisingFire  
mfilename = StringSubstr(OrderTicket(),StringLen(OrderTicket())-7,7) + ".DAT";

fhandle=FileOpen(mfilename, FILE_BIN|FILE_READ);

if(fhandle<=0)

{ Alert( "File:", mfilename, " not found, the last error is: ", GetLastError());

filewriting(mfilename); }

        if(fhandle>0)

FileClose(fhandle);
Simon Gniadkowski
17224
Simon Gniadkowski  
raisingfire:

This is the section that open the file and close the file :

I use the standard MQL4 file functions, not DLL calls.

Can you add the following and report back what the output is please . . .

mfilename = StringSubstr(OrderTicket(),StringLen(OrderTicket())-7,7) + ".DAT";

Print("Filename:  ", mfilename);    // <--- add this line

fhandle=FileOpen(mfilename, FILE_BIN|FILE_READ);

if(fhandle<=0)

{ Alert( "File:", mfilename, " not found, the last error is: ", GetLastError());

filewriting(mfilename); }

        if(fhandle>0)

FileClose(fhandle);


Have you confirmed that the file exists in the correct directory ? it no longer should be in experts\files . . . . it has to be in MQL4\Files you can find the correct MQL4 folder from MT4 by clicking File > Open data Folder

William Roeder
20341
William Roeder  
  1. mfilename = StringSubstr(OrderTicket(),StringLen(OrderTicket())-7,7) + ".DAT";

    Orderticket is an int, StringLen expects a string

    OrderTicket
    StringLen StringSubstr
    12345678
    8
    ("12345678", 1, 7) = "2345678"
    1234567
    7
    ("12345678", 0, 7) = "1234567"
    1234566("123456", -1, 7) INVALID

    so if the number of digits < 7 (like in the tester) the call fails. > 7 leading digits are removed?

    Try IntegerToString( OrderTicket(), 7, '0') + ".DAT" // 12345 -> 0012345.DAT

  2. There is no experts\files Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles
RaisingFire
54
RaisingFire  
RaptorUK:

Can you add the following and report back what the output is please . . .


Have you confirmed that the file exists in the correct directory ? it no longer should be in experts\files . . . . it has to be in MQL4\Files you can find the correct MQL4 folder from MT4 by clicking File > Open data Folder


RaptorUK:

Can you add the following and report back what the output is please . . .


Have you confirmed that the file exists in the correct directory ? it no longer should be in experts\files . . . . it has to be in MQL4\Files you can find the correct MQL4 folder from MT4 by clicking File > Open data Folder

Dear RaptorUK,

Here I attached the file from the log following the Print statement.

I am aware that the folder structure has been changed in build 610. But then, the terminal client program should adjust it automatically because I use the default folders.

Thank you for your help.

RaisingFire
54
RaisingFire  
WHRoeder:
  1. Orderticket is an int, StringLen expects a string

    OrderTicket
    StringLen StringSubstr
    12345678
    8
    ("12345678", 1, 7) = "2345678"
    1234567
    7
    ("12345678", 0, 7) = "1234567"
    1234566("123456", -1, 7) INVALID

    so if the number of digits < 7 (like in the tester) the call fails. > 7 leading digits are removed?

    Try IntegerToString( OrderTicket(), 7, '0') + ".DAT" // 12345 -> 0012345.DAT

  2. There is no experts\files Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles


Dear WHRoder,

I tried your suggestion and It still gives me the same error code: 5004. You pointed out a good info that orderticket returns int. But then, the old client terminal program (build 580 something) didn't return any compilation error nor runtime error. This error code 5004, as I mentioned before, doesn't seem to affect my EA performance at all. my EA still can open and close position at the correct condition.

I use the default directory, I don't specify a specific directory. I could see the files are there but still it fails to fileopen them. To add more confusion, It does not fail all the time. Most of the times, it succeed to fileopen. I have add another condition to test if it succeed to fileopen. The success rate is around 10 : 1 ratio where the 1 is the fileopen fails.

Thank you for your help anyway.

qjol
3196
qjol  

what version are you using

& maybe its a UAC issue

James Hodges
3397
James Hodges  
//you are looking for a word in a number.... twice... It's like asking how many ounces are in a foot. Wrong datatype.
//Change your ticket number to a string.

string ticketString=IntegerToString(OrderTicket());
//now your ticket number is a string.

mfilename = StringSubstr(ticketString,StringLen(ticketString)-7,7) + ".DAT";
//now you are asking for the substring and length of a string instead of an integer.

fhandle=FileOpen(mfilename, FILE_BIN|FILE_READ);

if(fhandle == -1)
//if you are getting an INVALID HANDLE that is -1 you could also just say <0 instead of <=0 this may be why it only fails some times.

{ Alert( "File:", mfilename, " not found, the last error is: ", GetLastError());

filewriting(mfilename); }

        if(fhandle>0)

FileClose(fhandle);

As WHRoeder said above.. if you are using the tester and it is not using a ticket number that contains at least 7 digits then you are asking it to look for as substring starting at the 6 minus 7(ticketString-7) or -1 position.. which will make it fall. Also you mentioned the 'default' folder.

The 'default' folder has changed from what it used to be. I will have to assume that when you say 'default' you are talking about the new 'default' folder at Mql4/files.. not at the old experts/files.

Make sure that you took the suggestion above and used the file>Open Data Folder and looked in the actual location that your platform is using. It may be over in users/appdata if you are using UAC as has been suggested also... which is fine as long as you are aware of it and adjust your paths accordingly if need be.

If it is trading properly apparently this part of the code is just for record keeping and logging and not an integral part of the strategy. Hope some of these suggestions help you get it running error free.. Welcome to the Forum!

PipPip...Jimdandy

RaisingFire
54
RaisingFire  
qjol:

what version are you using

& maybe its a UAC issue


the current client terminal I am using is build 610.
RaisingFire
54
RaisingFire  
Jimdandy:

As WHRoeder said above.. if you are using the tester and it is not using a ticket number that contains at least 7 digits then you are asking it to look for as substring starting at the 6 minus 7(ticketString-7) or -1 position.. which will make it fall. Also you mentioned the 'default' folder.

The 'default' folder has changed from what it used to be. I will have to assume that when you say 'default' you are talking about the new 'default' folder at Mql4/files.. not at the old experts/files.

Make sure that you took the suggestion above and used the file>Open Data Folder and looked in the actual location that your platform is using. It may be over in users/appdata if you are using UAC as has been suggested also... which is fine as long as you are aware of it and adjust your paths accordingly if need be.

If it is trading properly apparently this part of the code is just for record keeping and logging and not an integral part of the strategy. Hope some of these suggestions help you get it running error free.. Welcome to the Forum!

PipPip...Jimdandy


As I have replied to WHRoeder, I have followed his suggestion and it still gives me the same error code 5004.

For the default folder, I am aware that folders structure has changed in build 610. I have recompiled my EA and I never specified my own folders. So, I assumed that the EA would create and look for the DAT files in the client terminal default folders. And it is confirmed that most of the time, the FILEOPEN succeeds. Only 10% of the same statement fails. (I am using simple if statement to test whether it succeeds).

Cheers,

Simon Gniadkowski
17224
Simon Gniadkowski  
raisingfire:

Dear RaptorUK,

Here I attached the file from the log following the Print statement.

I am aware that the folder structure has been changed in build 610. But then, the terminal client program should adjust it automatically because I use the default folders.

Thank you for your help.

There was no file attached . . .

Have you confirmed that the file you are trying to read from actually exists ? please look in the correct folder and check . . . one other thing, why do you have a function called filewriting() to READ from a file ?

To add comments, please log in or register