What MQL4 error 5004 means
The official MQL4 runtime table names error 5004 ERR_CANNOT_OPEN_FILE and defines it as “cannot open file.” FileOpen returned INVALID_HANDLE because MT4 could not open the requested file under its file sandbox and access flags.
The error number is evidence about one failed call, not a diagnosis of the whole EA. Read the API sentinel first, then call GetLastError immediately because that function returns the current _LastError value and resets it.
