Download MetaTrader 5

Array to file

To add comments, please log in or register
Magaiver
20
Magaiver  

I have an array (example[]), that i want to print to file. What i am doing wrong? The data.csv file appears in folder, but it's empty.

‌‌This is the code:

‌In main section:

input string InpFileName="data.csv";
input string InpDirectoryName="SomeFolder";
string path=InpDirectoryName+"//"+InpFileName;


double example[] = {0,5,5,5,2,1,0,4,4,4,5,7,0,0};

‌In OnInit section:

handle=FileOpen(path,FILE_CSV|FILE_WRITE,',');

In  OnCalculate section:

FileWriteArray(handle,example,0,WHOLE_ARRAY);
honest_knave
Moderator
2325
honest_knave  
Magaiver:


handle=FileOpen(path,FILE_CSV|FILE_WRITE,',');
FileWriteArray(handle,example,0,WHOLE_ARRAY);


FileWriteArray only works for BIN files.

Magaiver
20
Magaiver  

Thank you for your answer. I have one more question:

How to read those bin files? Notepad gives me values like this: 

  ò?ffffffú?ÍÌÌÌÌÌô?       @      ð?              @      @      @      @      @        aTR' ‰ó?>íð×dó?B•š=Њó?9EGrùó?F%ušˆó?      4@        ‌

honest_knave
Moderator
2325
honest_knave  

Probably best just to stick with the CSV file.

// FileWriteArray(handle,example,0,WHOLE_ARRAY);
for(int i=0; i<ArraySize(example); i++) FileWrite(handle,example[i]);

To add comments, please log in or register