Download MetaTrader 5
To add comments, please log in or register
All activity of the MQL5.community members is displayed on a single page!
jhon
21
jhon 2015.09.27 16:57 

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. 

whroeder1
13596
whroeder1 2015.09.27 18:11  
Open the file in write mode not read&write
jhon
21
jhon 2015.09.27 18:35  

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);
}
Keith Watford
Moderator
7887
Keith Watford 2015.09.27 22:08  

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);

 .....

jhon
21
jhon 2015.09.27 22:32  
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. 

whroeder1
13596
whroeder1 2015.09.29 15:44  
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
/
To add comments, please log in or register