Download MetaTrader 5

dynamically build parameter list for FileWrite

To add comments, please log in or register
Share links from other resources. Now they have a description.
Michael Kress
280
Michael Kress 2016.10.21 19:29 

Hi, how can I dynamically build a parameter list for FileWrite? The number of columns is always the same, as I have a few loops through all timeframes, but I really want the loops. I suppose, the code will become ugly if I start the following:

FileWrite(file_handle, par1, par2, par3, arrayvalue[0], arrayvalue[1], arrayvalue[2]);

My ideal code would fill the parameter list right out of the loop for arrayvalue. Would that be possible?

Stanislav Korotky
17925
Stanislav Korotky 2016.10.21 21:22  
Are you asking for FileWriteArray function?
Michael Kress
280
Michael Kress 2016.10.21 23:29  
Stanislav Korotky:
Are you asking for FileWriteArray function?
Not really, because I'm exporting to a CSV file.
Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.10.22 10:39  
If it is only that small amount of elements why not just splice them to individuals omitting the array entries completely.
Michael Kress
280
Michael Kress 2016.10.22 19:45  

It's actually a huge amount of data, i.e. many columns. I bumped also with the 63 parameter limit of FilwWrite, so I had to rethink the export entirely.

The solution which works now for me:

void WriteData(string txt){
    uint uresult=0;
    if (txt!="\n") {
      txt=txt + ";";
    }
    uresult=FileWriteString(file_handle, txt,StringLen(txt));
    if (uresult<=0) {
      Print("Error writing to CSV file");

    }

return;
}


file_handle=FileOpen(DirectoryName+"//"+FileName,FILE_READ|FILE_WRITE|FILE_BIN);

// Write header:

WriteData("Symbol");
WriteData("OrderType");
WriteData("Lot");
WriteData("Open");
WriteData("Low");
.... // lots of more columns here
WriteData("\n");

.....

// then write data ...




output:

Symbol;OrderType;Lot;Open;Low;...
DE30;BUY;1.00;10629.81;10520.77;...


==> solved

To add comments, please log in or register