Discussion of article "MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria"

 

New article MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria has been published:

We continue the series of articles on MQL5 programming. This time we will see how to get results of each optimization pass right during the Expert Advisor parameter optimization. The implementation will be done so as to ensure that if the conditions specified in the external parameters are met, the corresponding pass values will be written to a file. In addition to test values, we will also save the parameters that brought about such results.

MQL5 Cookbook: Saving Optimization Results of an Expert Advisor Based on Specified Criteria

To gain access to data in the course of optimization, you can use special MQL5 functions: OnTesterInit(), OnTester(), OnTesterPass() and OnTesterDeinit(). Let's have a quick look at each of them:

  • OnTesterInit() - this function is used to determine the optimization start.
  • OnTester() - this function is responsible for adding so-called frames after every optimization pass. The definition of frames will be given further below.
  • OnTesterPass() - this function gets frames after every optimization pass.
  • OnTesterDeinit() - this function generates the event of the end of the Expert Advisor parameter optimization.

Now we should define a frame. Frame is some sort of a data structure of a single optimization pass. During optimization, frames are saved to the *.mqd archive created in the MetaTrader 5/MQL5/Files/Tester folder. Data (frames) of this archive can be accessed both during the optimization "on the fly" and after its completion. For example, the article "Visualize a Strategy in the MetaTrader 5 Tester" illustrates how we can visualize the process of the optimization "on the fly" and then view the results following the optimization.

Author: Anatoli Kazharski

 

Quite curious and most importantly in demand, I would also like to know the percentage of profitable trades, including by their direction....

Is it possible to rework it for MT4?

 
-Aleks-:

Quite curious and most importantly in demand, I would also like to know the percentage of profitable trades including in the context of their direction ...

Is it possible to modify it for MT4?

You can add any indicators: https://www.mql5.com/en/docs/constants/environment_state/statistics, making small changes on your own.

For MT4 there is this variant: Optimisation (testing) technique and some criteria for selecting Expert Advisor working parameters

Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Статистика тестирования
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Статистика тестирования
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Статистика тестирования - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 

Yes, I have read the article on MT4, but this data is not enough for me, and there are no other ways to get more information similar to MT5?

 
-Aleks-:

Yes, I have read the MT4 article, but this data is not enough for me, and there are no other ways to get more information similar to MT5?

Unfortunately I can't tell you (maybe someone else can give you an answer). I finally switched to MT5 myself and orientate on the possibilities of this terminal only.
 
tyvm. Excellent article.
 
wow, its great
 

Due to the fact that I started working in MT5 I came back to your article.

And what I'm wondering is, is it possible to order the report by pass number, instead of the way it is now, by the order of frame arrival from the pass?

This is convenient for the purpose of comparing two reports (without filters especially) with different settings - from my experience of working with reports in MT4.

Actually, it can be done if you know how many passes there will be in total, then you can write the information into an array and at the end unload it into a file, but how to calculate the number of passes?

Another option, which is less beautiful, is post-processing of the file - i.e. to organise the data after their processing, but how to do it more efficiently and universally is also a question.

 
Aleksey Vyazmikin:

...

Actually, it can be done if you know how many passes there will be, then you can write the information into an array and at the end unload it into a file, but how to calculate the number of passes?

...

To add data to the array you don't need to know initially how many passes there will be.

 
Anatoli Kazharski:

To add data to an array, you don't need to know initially how many passes there will be.


I am not a programmer and it is difficult for me - I spent half a day to remove unnecessary filters for me from your example....

 
Aleksey Vyazmikin:

I am not a programmer and it is difficult for me - I spent half a day to throw out unnecessary filters for me from your example....

I don't plan to return to this topic anytime soon.

Try to formulate your problem more precisely and post it here. Perhaps someone will suggest a solution.