Download MetaTrader 5

dynamically build parameter list for FileWrite

To add comments, please log in or register
Michael Kress
283
Michael Kress  

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
22037
Stanislav Korotky  
Are you asking for FileWriteArray function?
Michael Kress
283
Michael Kress  
Stanislav Korotky:
Are you asking for FileWriteArray function?
Not really, because I'm exporting to a CSV file.
Marco vd Heijden
Moderator
5648
Marco vd Heijden  
If it is only that small amount of elements why not just splice them to individuals omitting the array entries completely.
Michael Kress
283
Michael Kress  

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