Download MetaTrader 5

Simple Write to file Code

To add comments, please log in or register
Track Market top sellers!
therustytrader
457
therustytrader 2014.11.19 00:18 

Ok, I had this working earlier and made some changes and now it is not working so it is driving me crazy.

I am trying to collect some data in a csv file every time my EA takes a trade so inside the same if statement the command to take the trade

At the beginning of the Start() I have:

  int handle=FileOpen ("tradedatalog.csv", FILE_CSV|FILE_WRITE|FILE_READ, ';');

And in the if statement the order is taken in I have included:

     FileSeek(handle, 0, SEEK_END);
     FileWrite(handle, TimeCurrent()+ "," +Symbol()+ "," +Open[0]+ "," +High[0]+ "," +Low[0]+ "," +Close[0]);
     FileClose(handle);

The trades are taken but the file is no longer being written to.

Any help would be greatly appreciated.

John Townsend
83
John Townsend 2014.11.19 01:38  
therustytrader:

Ok, I had this working earlier and made some changes and now it is not working so it is driving me crazy.

I am trying to collect some data in a csv file every time my EA takes a trade so inside the same if statement the command to take the trade

At the beginning of the Start() I have:


And in the if statement the order is taken in I have included:

The trades are taken but the file is no longer being written to.

Any help would be greatly appreciated.

Add code to check for errors - that should tell you what is happening.

For instance, see the error-handling code in the example given here:

https://docs.mql4.com/files/fileopen

HTH

John 

Stuart Browne
5819
Stuart Browne 2014.11.19 01:46  

2 suggestions:

1) Change your delimiter.  Might not make a difference but using a semicolon is asking for trouble.

2) Make sure you're running MT as an administrator (Right click on the exe and "Run as..")

therustytrader
457
therustytrader 2014.11.19 02:52  

Thank you both for your help. 

Changed the semicolon.

Added checking for errors, and found that by adding the File Open command with the rest allowed it to work right.  have no clue why but was getting an error with the handle up top.

so just made it = the same thing down below and now works just fine.  Thank you both for your help.

To add comments, please log in or register