(Mq4) how to add information to a text file, line by line by using a script or EA?

 

Ok, but I have a problem. When I use the following script again on the different Symbol() on chart - the existing file delete all previous data.

How to add to this one file - informations from all available Symbols? I would like to get informations in one file from different Symbols - under line each Symbol.

Have you any IDEA ?

//+------------------------------------------------------------------+
//|                                           zapis_do_pliku_csv.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
  int handle;
  datetime orderOpen=OrderOpenTime();
  handle=FileOpen("plik_csv", FILE_CSV|FILE_WRITE, ';');
  if(handle>0)
    {
     FileWrite(handle, Symbol(), Close[0], Open[0], High[0], Low[0], TimeToStr(orderOpen));
     FileClose(handle);
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
puncher:

Ok, but I have a problem. When I use the following script again on the different Symbol() on chart - the existing file delete all previous data.

How to add to this one file - informations from all available Symbols? I would like to get informations in one file from different Symbols - under line each Symbol.

Have you any IDEA ?

You need to seek to the end of the file and start writing new data there . .
 
RaptorUK:
You need to seek to the end of the file and start writing new data there . .

any example, pls ?
 

Add FILE_READ in FileOpen ("plik_csv", FILE_CSV|FILE_WRITE|FILE_READ, ';');

There's no need for FileSeek(), because the script is just open the csv file.

 
onewithzachy:

Add FILE_READ in FileOpen ("plik_csv", FILE_CSV|FILE_WRITE|FILE_READ, ';');

There's no need for FileSeek(), because the script is just open the csv file.


this solution does not work...

 
puncher:

this solution does not work...

Dear puncher

Your ...

datetime orderOpen=OrderOpenTime();

need to be selected with OrderSelect() first.

And in the FileOpen must specify the file type, in your case .csv

FileOpen("plik_csv.csv", FILE_CSV|FILE_WRITE|FILE_READ, ';');

If I may ask, what is it that you want to write into a file anyway ? And did you use Win Vista/7 and installed in C:\Program Files ... ?

 
onewithzachy:

Dear puncher

Your ...

need to be selected with OrderSelect() first.

And in the FileOpen must specify the file type, in your case .csv

If I may ask, what is it that you want to write into a file anyway ? And did you use Win Vista/7 and installed in C:\Program Files ... ?


OrderSelect() ? What for.... ???

I would like to save only all data into one file - order management is unnecessary.


I have Vista 64 bit system and MT4 installed on C:\Program Files (x86)\MT4 - but there is also available on my system folder C:\Program Files - but here there is not installed my MT4.


One after the other: I open the EURUSD chart are putting the script and write the data to a file. Then I open another chart, for example: CADPLN, make the script and should save the data to the same file as before - no erase previous data.

This script works - but erases all previous data from the file - when I use this script again and it saves only last data from the current chart!


 
puncher:

OrderSelect() ? What for.... ???

I would like to save only all data into one file - order management is unnecessary.

I have Vista 64 bit system and MT4 installed on C:\Program Files (x86)\MT4 - but there is also available on my system folder C:\Program Files - but here there is not installed my MT4.

One after the other: I open the EURUSD chart are putting the script and write the data to a file. Then I open another chart, for example: CADPLN, make the script and should save the data to the same file as before - no erase previous data.

1. No one talk about order management, whatever - read this carefully - OrderOpenTime() need to be selected first with OrderSelect() !.

2. You may want to install outside C:\Program Files\... (for example C:\Trading Platform\MT4...) or just modify the security tab, because we read so many forumers here having trouble with Vista/7, than can only be fixed when MT4 installed outside C:\Program Files\...

3. Data of a chart using OrderOpenTime() ? I already have one working, if you show your code, I'll show mine.

 
RaptorUK:
You need to seek to the end of the file and start writing new data there . .


Thank you RaptorUK, I solve the problem - here's the solution I was looking for:


#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

int start()
  {

  int handle;
  handle=FileOpen ("plik_csv", FILE_CSV|FILE_WRITE|FILE_READ, ';');
  if(handle>0)
    {
     FileSeek(handle, 0, SEEK_END);
     FileWrite(handle, Symbol(), Close[0], Open[0], High[0], Low[0]);
     FileClose(handle);
    }

   return(0);
  }


SUBJECT IS CLOSED