Download MetaTrader 5

Writing Optimization Results into an external textfile

To add comments, please log in or register
Did you like the article? Share it with your friends!
sunshineh 2016.03.12 13:57 


I found this article in the codebase: 


It works fine for testing ONE run, but if I will do an optimization, than in the text-File shows only the last result (not for the different optimization values of an variable)  :-(

I've tried to put this part in the OnTester()-Function

      if(!IsTesting()) ExtInitialDeposit=CalculateInitialDeposit();

 So how can I realize that after EACH automatical run of my EA the result will be written in an text-file?

Carl Schreiber
Carl Schreiber 2016.03.12 18:00  

Be careful with this idea!

If the tester is optimizing it will test and write according to your wish e.g. in genetic mode between 8'000 and 19'000 results.

~20'000 * 25 lines will create 500'000 lines - you can't manage this. Even editors will probably refuse to open such a file - toooo big!

Write only one line per pass into a csv-file. Use OnTester() for this.

sunshineh 2016.03.13 15:05  

Thank you! 

I thought about this and in the first step I only write the values from the variables an the results in ONE file and for each result the summary, not each trade.

I also don't want to optimize more than about 100-200 results each time.


I insert a function to write into a text-file in the OnTester-Function but it never works whether on testing or on optimizing!? (But the same code works, if I put it into the init function.

Carl Schreiber
Carl Schreiber 2016.03.13 17:24  

To ad a line you have to do (without checking for errors - you'll find them in the journal tab anyway):

      string row = StringFormat("%.5f;...\n",var1,...);
      int fH = FileOpen(fName,FILE_READ|FILE_WRITE);
      FileWriteString(fH, row, StringLen(row) );

Otherwise you have to create at every pass a new file name - not to overwrite the existing ones.

To add comments, please log in or register