MQL4 File Functions (MQL4 File Functions Replacement)


Hi folks,

A lot of people asked me and MetaQoutes for a better file handling functions that's why I'm writing this article/tool.
The problem of the normal file handling functions was the limited directories you can use for your output file:

Directories limitation:

One of annoying feature of MQL4 file functions is the directories limitation; you can't work with files that outside one of these three directories:

  • Terminal_Install_Dir/HISTORY/<current broker>
    Works with FileOpenHistory() function.
  • Terminal_Install_Dir/EXPERTS/FILES
    The common directory for file saving and opening.
  • Terminal_Install_Dir/TESTER/FILES
    The directory of testing files.

MetaTrader thinks it's safer to limit the directories you can access from the normal MQL4 program and give you the ability to write your MQL4 extension (dll) to do what do you want. That's why our tool today is useful because it enables you to work with files outside the limited directories of MQL4.

The package:

Please download the full package which includes:
The source code and the compiled version (dll) of the mtguru1.dll which is a MetaTrader extension that wrote in Visual c++.
gFiles.mqh is the include file which have the declarations of the functions inside the dll.
FilesDemo.mq4 is a demo indicator to show you how to use the dll.

Installation:

  1. Extract all of the contain of zip file to an empty folder.
  2. Copy the mtguru1.dll to "MetaTrader 4\experts\libraries" path.
  3. Copy FilesDemo.mq4 to "MetaTrader 4\experts\indicators" path and compile it.
  4. Copy gFiles.mqh to "MetaTrader 4\experts\include".
  5. Load FilesDemo.mq4from your Indicators - don't forget to enable "Allow DLL Import"

The functions we have:

This is a list of the functions the current version of the mtguru1.dll has:
int gFileOpen(string file_name,int mode);
bool gFileWrite(int handle,string data);
bool gFileClose(int handle);
string gFileRead(int handle,int length=0);
void gFileSeek(int handle,int offset, int mode);
bool gFileDelete(string file_name);
int gFileSize(int handle);
int gFileTell(int handle);
bool gFileFlush(int handle);
bool gFileCopy(string source,string distance,bool IfExists);
bool gFileMove(string source,string distance);

They are very like the normal MQL4 functions but you can write in any directory you want. Please play with them and tell me your comment!

Enjoy!
Coders' Guru