Delete Ticks from csv file

 

Hi,

I found this EA:

https://www.mql5.com/en/code/10483

 It's great but I need help with one simple thing - I want that just one line will be writtento the file. it's mean that every time I will open the file I see only 1 line, the last tick.

Only the last tick!

In the next tick the current line will be deleted and the new tick will be written. 

It is possible?

 

Sorry for my english.

Thank. 

 
Open the file in write mode not read&write
 

I found this EA here:

 http://www.forexfactory.com/showthread.php?t=488265

What is the required change please?

And one more thing please - change this EA that the file will be csv file, I think the changes need to be in this line:

 

file_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_SHARE_READ|FILE_WRITE|FILE_TXT|FILE_ANSI);

Thanks! 

// EA code

#property strict

int file_handle;
string InpFileName = _Symbol + ".txt"; // File name
input string InpDirectoryName = "Data"; // Folder name

int OnInit()
{
        ResetLastError();
        file_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_SHARE_READ|FILE_WRITE|FILE_TXT|FILE_ANSI);
        if(file_handle == INVALID_HANDLE) {
                PrintFormat("Failed to open %s file, Error code = %d", InpFileName, GetLastError());
                ExpertRemove();
        }
        return INIT_SUCCEEDED;
}

void OnTick()
{
        // Datetime), Bid, Volume
        string s = TimeToStr(TimeGMT()) + " " + Bid + " " + Volume[0];
        FileWriteString(file_handle, s + "\r\n");
        FileFlush(file_handle);
}

void OnDeinit(const int reason)
{
        FileClose(file_handle);
}
 

Don't open the file in init and close it in deinit

Do the whole operation in OnTick 

You have an example for opening /creating a CSV file in the documentation

   filehandle=FileOpen("fractals.csv",FILE_WRITE|FILE_CSV);

 .....

 
GumRai:

Don't open the file in init and close it in deinit

Do the whole operation in OnTick 

You have an example for opening /creating a CSV file in the documentation

 .....

Thanks but now I can't access to the file while the EA is running...

I need a simple EA that will record any tick to csv file (just the last tick!) and I can get access to the file while the EA is running.

Please help me.

Thanks. 

 
input string InpDirectoryName = "Data"; // Folder name
file_handle = FileOpen(InpDirectoryName + "//" + InpFileName, FILE_SHARE_READ|FILE_WRITE|FILE_TXT|FILE_ANSI);
  1. "//" is wrong. "\\" (a single back slash.)
  2. Do you have a folder "c:\Users\XXX\AppData\Roaming\MetaQuotes\Terminal\BB190E062770E27C3E79391AB0D1A117\MQL4\files\Data" ? Data Structure in MetaTrader 4 Build 600 and Higher - MQL4 Articles 17.02.2014
Reason: