Hello, community,
I'm trying to create an algo that, at every new tick, it will add some data in a .txt file. To achieve that, I'm using the FileSeek function following the instructions available in the "Writing to the end of a text file" Section in https://www.mql5.com/en/articles/2720#z3.
However, the algo is not adding the new information to the file. On the contrary, it is overwriting the existing data, so the file always contains one line of data. Thus, I do not get any noticeable errors in the execution.
Can anyone enlighten me on how to solve it?
This is the algo I wrote
txt file output:
Expert log
Thanks!
I ran your code (in MQL5) - worked fine:
2022.08.19 15:23 1660922610017 1.18252 1.18265
2022.08.19 15:24 1660922654877 1.18257 1.18271
2022.08.19 15:24 1660922660515 1.18266 1.18276
2022.08.19 15:24 1660922662316 1.18268 1.18280
2022.08.19 15:24 1660922663292 1.18261 1.18271
2022.08.19 15:29 1660922989902 1.18258 1.18270
2022.08.19 15:29 1660922994056 1.18250 1.18261
I had a look at some code I wrote a while back and I had done it differently, without the delimiter and using FileWriteString() which worked fine.
Maybe try that:
filehandle = FileOpen(iv_fileName, FILE_READ | FILE_WRITE | FILE_TXT); if(filehandle == INVALID_HANDLE) { return(false); } else { FileSeek(filehandle, 0, SEEK_END); //Append to file ov_bytesWritten = (int)FileWriteString(filehandle, line); FileClose(filehandle); //etc
I ran your code (in MQL5) - worked fine:
2022.08.19 15:23 1660922610017 1.18252 1.18265
2022.08.19 15:24 1660922654877 1.18257 1.18271
2022.08.19 15:24 1660922660515 1.18266 1.18276
2022.08.19 15:24 1660922662316 1.18268 1.18280
2022.08.19 15:24 1660922663292 1.18261 1.18271
2022.08.19 15:29 1660922989902 1.18258 1.18270
2022.08.19 15:29 1660922994056 1.18250 1.18261
I had a look at some code I wrote a while back and I had done it differently, without the delimiter and using FileWriteString() which worked fine.
Maybe try that:
Thanks for your reply! It's good to know that the algo is working.
For some reason, the data is being overwriten. And today I got another not intended result. For some time, the algo was not able to write the data in the file. None. I checked if the txt file was open or for an other reason, but could not find any.
I'm using MT5, v 5, build 3391.
I also tried your sugestion, but could not get any output.
Thanks for your help.
Thanks for your reply! It's good to know that the algo is working.
For some reason, the data is being overwriten. And today I got another not intended result. For some time, the algo was not able to write the data in the file. None. I checked if the txt file was open or for an other reason, but could not find any.
I'm using MT5, v 5, build 3391.
I also tried your sugestion, but could not get any output.
Thanks for your help.
Same build as me. Not sure why you have the problem.
I did wonder why you had 3 separate functions for open, write & close. Are you keeping the file unclosed for long periods?
I suggest combining the open and close operations into a single function write_file() so everything is done together
Also FileSeek and FileWrite have return values - print those out and it may reveal where the problem isI could solve the problem by adding FILE_COMMON in the FileOpen function.
//Print(fileName); fileHandle = FileOpen(fileName, FILE_READ|FILE_COMMON|FILE_WRITE|FILE_ANSI|FILE_TXT, '\t');
Thanks for the help!
Cheers!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, community,
I'm trying to create an algo that, at every new tick, it will add some data in a .txt file. To achieve that, I'm using the FileSeek function following the instructions available in the "Writing to the end of a text file" Section in https://www.mql5.com/en/articles/2720#z3.
However, the algo is not adding the new information to the file. On the contrary, it is overwriting the existing data, so the file always contains one line of data. Thus, I do not get any noticeable errors in the execution.
Can anyone enlighten me on how to solve it?
This is the algo I wrote
txt file output:
Expert log
Thanks!