Problem with FileWrite etc..

Flirrrt
33
Flirrrt  

Trying to export tickdata during trades ONLY, for further analysis in excel:

I have written an ea, so when an position is taken, i want every tick or 1 minutebar-low to be exported inte an document.

I have never used the file-commands before, but I gave it a try:

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))

{

int handle=FileOpen("Breakout-export.csv",FILE_WRITE|FILE_CSV,"\t");

if(handle>0){

// write header

FileWrite(handle,OrderSymbol(),OrderTicket(),Bid);

FileClose(handle);

}}

The problem is that with this i don't get a file at all. I shuold be placed in the experts-folder, right?

Am I on the right track, or is my code really fucked up?

Thanks in advance,

Johan

sg1
18
sg1  

There are errors in your code.

Here's my code that adds to a file on every tick:

// Function WriteToFile ***********************

void WriteToFile(double val1, string str2)

{

int handle;

handle=FileOpen("Log.csv", FILE_CSV|FILE_WRITE|FILE_READ, '\t');

FileSeek(handle, 0, SEEK_END);

FileWrite(handle, TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS), DoubleToStr(val1, 4), str2);

FileClose(handle);

return(0);

}

//*********************************************

The file is saved to 'experts/files' folder

sg1

Flirrrt
33
Flirrrt  

Thank you for your answer sg1, unfortunately I don't get it to work properly.

I combined your code with mine, and used it in an ea. The testing now takes a lot longer, so it's some data it's processing.. but i still get no file with the tickdata.

This is what the code looks like:

void WriteToFile()

{

int handle;

handle=FileOpen("Breakout.csv",FILE_CSV|FILE_WRITE|FILE_READ,'\t');

FileSeek(handle, 0, SEEK_END);

FileWrite(handle,DoubleToStr(Bid, 4));

FileClose(handle);

}

And then I just call in the start().

Do you know what causes the problem?

/Johan

zupcon
313
zupcon  
Flirrrt:

Do you know what causes the problem?

/Johan

Code looks OK,

does it create a file, but the file is empty ?, if so sure that you dont already have the file open in excel, or any other editor, as that can cause problems.

regards

zu

Flirrrt
33
Flirrrt  

Zupcon, it doesn't create a file at all.. and no, I don't have that file opened in excel (even if i've done that thing tons of times before :-))

I got the code working with some changes, but my next problem is that it wont re-run the code on every new tick being made..

See the other thread about that problem: https://www.mql5.com/en/forum/177044