Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

CFastFile - class for working with uchar array as a virtual file - library for MetaTrader 5

Views:
4448
Rating:
(38)
Published:
2012.03.02 09:09
Updated:
2017.05.02 10:01
\MQL5\Scripts\ \MQL5\Include\
FastFile.mqh (13.95 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

The CFastFile eliminates the need for an intermediate writing of data to the physical file on disk. It provides the significant acceleration when working with data.

It has functions, similar to standard FileWriteXXX/FileReadXXX functions. It means that you can easily migrate from the use of the physical files to the fast work with the "virtual" files in memory. The data storage and reading/writing is based on use of the uchar-array instead of the physical file.

List of functions:

    CFastFile(uchar &data[]);          // constructor with initialization of file data from array

    void Clear();                         // clear file
   
    //--- functions for working with file properties
    void Delim(uchar delim=';');        // set delimiter (data separator) for CSV mode
    int Size();                        // gets file size
    int Tell();                        // gets current position
    void Seek(int offset, int origin);  // seek
    bool IsEnding();                   // checking of end of file (EOF)
    bool IsLineEnding();                 // checking of end of line

    //--- functions for writing the data to file
    uint WriteArray(uchar &src[], uint src_start=0, int src_cnt=WHOLE_ARRAY); // write uchar array
    uint WriteDouble(double v);          // write double
    uint WriteFloat(float v);
    uint WriteLong(long v);
    uint WriteInt(int v);
    uint WriteShort(short v);
    uint WriteChar(char v);
    uint WriteInteger(int v, int sz=INT_VALUE); // write integer - for compatibility with standard FileWriteInteger
    uint WriteString(string v, int cnt);        // write string cnt=-1 means CSV mode with addition of \r\n
   
    //--- functions for reading from file
    uint ReadArray(uchar &dst[], uint dst_start=0, int cnt=WHOLE_ARRAY); //  read array
    double ReadDouble();                 // read double
    float ReadFloat(); 
    long ReadLong();
    int ReadInt();
    short ReadShort();
    char ReadChar();
    int ReadInteger(int sz=INT_VALUE); // read integer - for compatibility with standard FileReadInteger
    double ReadNumber(); //
    string ReadString(int cnt);         read string. cnt=-1 means CSV mode - reading to delimiter (data separator)
   
    //--- functions, used to save data
    uint Save(uchar &v[]);     // save file to uchar array
    uint Save(int h);         // save file to the real file on disk. h - file handle (the file must be opened)
    uint Save(string file);    // save file to the real file on disk. file - file name

    //--- functions, used for loading of data
    uint Load(uchar &v[]);   // load file from uchar array
    uint Load(int h);         // load data from real file on disk. h - file handle (the file must be opened)
    uint Load(string file);  // load data from real file on disk. file - file name

One can see, the functions are named similar to the standard file operations.

The migration from real files to the CFastFile is very easy. Instead of file open and getting file handle (for example, int h) you need to create the CFastFile class instance, for example:

CFastFile f; 

The next you need to change the conventional file functions according to the rule:

FileWriteDouble(h, 10)  ->  f.WriteDouble(10)

For convenience, the Save/Load functions is added - it allows you to save/load the "virtual" file data to the real file on disk.

The demo example of CFastFile class use in included.


Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/845

Trading signals module based on WPRSIsignal indicator Trading signals module based on WPRSIsignal indicator

Trading signals module for MQL5 Wizard. WPRSIsignal indicator's color arrow serves as a market entry signal.

Trading signals module based on Candles_Smoothed indicator Trading signals module based on Candles_Smoothed indicator

Trading signals module for MQL5 Wizard. The moment, when a candlestick formed by Candles_Smoothed changes its color, indicates the time for market entry.

Trading signals module based on ColorJFatl indicator Trading signals module based on ColorJFatl indicator

Trading signals module for MQL5 Wizard. The moment, when ColorJFatl indicator changes its color, indicates the time for market entry.

Trading signals module based on SilverTrend_Signal indicator Trading signals module based on SilverTrend_Signal indicator

Trading signals module for MQL5 Wizard. SilverTrend_Signal indicator's color dot serves as a market entry signal.