Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2012.03.02 09:09
Libraries

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

| English Русский 中文 Español Deutsch 日本語 Português

Views:
1893
Rating:
votes: 28
\MQL5\Include\
fastfile.mqh (7.36 KB)view
\MQL5\Scripts\

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 Software Corp.
Original code: https://www.mql5.com/ru/code/845

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

Average Directional Movement Index (ADX) Average Directional Movement Index (ADX)

The Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.

Holt's double exponential smoothing trend Holt's double exponential smoothing trend

Holt's double exponential smoothing - the trend component (mt4 version).

Holt's double exponential smoothing (mt4 version) Holt's double exponential smoothing (mt4 version)

Holt's double exponential smoothing with linear forecasting.