Welcome to my Code Snippets

MyCodeSnippets.Space

tick.export

ReAdABLE Source (What is the ReAdABLE Human Format?)

http://mycodesnippets.space/mql4/tick.export.red

Code

https://i.imgur.com/UuWqkZf.png


//+--------------------------------------------------------+
//|      adapted for FILE_SHARE_READ from BP-Ticks-1.0.mq4 |
//+--------------------------------------------------------+
// see https://gist.github.com/lepinekong/9a53459b05ac5ed999883eb4a3cb6488
// File identificator
int file;
uint startTick;
uint tickTime;

datetime theTime;
string strTickDate;
string strTickSecond;

string separator = ",";

// Tick count for flushing each 1024 ticks

int flushCount = 0;
int flushCountLimit = 32; // you can experiment with 1024

int init() {

    startTick=GetTickCount();
    file = FileOpen(Symbol() + "-Ticks.csv",
        FILE_WRITE | FILE_READ | FILE_CSV | FILE_SHARE_READ, separator);   

    return(0);
}

int deinit() {
    FileClose(file);
    return(0);
}

int start() {
    //    - Date & time with seconds info
    //    - Bid
    //    - Ask
    //    - Volume indicator for the selected timeframe
    tickTime=GetTickCount()- startTick;
    theTime=TimeCurrent();
    strTickDate=TimeToStr(theTime,TIME_DATE);
    strTickSecond=TimeToStr(theTime,TIME_SECONDS);
    FileWrite(file, 
            strTickDate, strTickSecond,
            "" + tickTime,
            Bid, 
            Ask, 
            iVolume(Symbol(), NULL, 0));
    flushCount++;

    // Flush file buffer each 1024 ticks to enhance performance
    //    when writing huge files
    if (flushCount == flushCountLimit) {
        FileFlush(file);
        flushCount = 0;
    }

    return(0);
}