Discussion of article "Universal Expert Advisor: Trading in a Group and Managing a Portfolio of Strategies (Part 4)"

 

New article Universal Expert Advisor: Trading in a Group and Managing a Portfolio of Strategies (Part 4) has been published:

In the last part of the series of articles about the CStrategy trading engine, we will consider simultaneous operation of multiple trading algorithms, will learn to load strategies from XML files, and will present a simple panel for selecting Expert Advisors from a single executable module, and managing their trading modes.

Upon a click on any button on the panel, it defines the action to be performed and performs it. For example, if we select a strategy from the list of strategies, the index of the current strategy will be equal to the selected one, then you can perform further trading actions. For example, you can change the trading mode of the elected strategy by selecting the appropriate option from the drop-down list of the strategy modes:

Fig. 2. The list of modes of a selected strategy

Fig. 2. The list of modes of a selected strategy

Buying and selling on behalf of the selected strategy is performed the same way. A pointer to the strategy calls the Buy and Sell methods of the CStrategy base class. These methods buy and sell the volume passed in them. In this case, the magic number in the operations performed corresponds to the magic number of the strategy, so it is impossible to distinguish manual trading from the EA's actions.

Author: Vasiliy Sokolov

 
Many thanks to Vasiliy Sokolov for such a thorough work.
Please answer a couple of questions:
1. The author in the first articles wrote about platform independence... What should be done to adapt this code to MT4?
2. When trading 10 instruments, 2-3 systems on each, each system has 10 parameters, XML-portfolio will become a very large file, which will be difficult to edit by hand without errors. Maybe in this case it would be reasonable to store XML-portfolio in different files - one file for each instrument, which contains information about the systems traded on it and their parameters? Then it would be easier to enable/disable (by setting checkboxes in the file) both trading on the instrument and individual TS on this instrument.
 
Mike:
Many thanks to Vasiliy Sokolov for such a thorough work.
Please answer a couple of questions:
1. The author in the first articles wrote about platform independence... What should be done to adapt this code to MT4?
2. When trading 10 instruments, 2-3 systems on each, each system has 10 parameters, XML-portfolio will become a very large file, which will be difficult to edit by hand without errors. Maybe in this case it would be reasonable to store XML-portfolio in different files - one file for each instrument, which contains information about the systems traded on it and their parameters? Then it would be easier to enable/disable (by setting checkboxes in the file) both trading on the instrument and individual TS on this instrument.

Unfortunately, the first question is not so easy to answer. In reality, quite a lot of things need to be written to make the engine work in MT4. I will do it soon. When I port the engine to MT4, I will publish a corresponding article.

Regarding the second question - it is better to store everything in one file. XML is good because it allows you to organise tree-like sections and does not allow you to get confused even in a large volume of tags. Another thing is that manual editing of XML is not welcomed by the standard itself. It is an industrial format for algorithms to communicate with each other. Ideally, each xml file should have a gui muzzle in the form of a regular application that allows you to edit strategy parameters. But this, although quite simple (from an algorithmic point of view) will take quite a lot of time, so for now we edit xml directly.

 
Vasiliy Sokolov:

Each xml file should have a gui muzzle in the form of a regular application allowing to edit strategy parameters. But this, although quite simple (from an algorithmic point of view) would take quite a lot of time, so for now we edit the xml directly.

The ideal solution would be an "Edit" button on the User Panel, which would open a window for editing the corresponding section <Strategy>... </Strategy>:)
 
Mike:
The ideal solution would be an "Edit" button on the User Panel that would open a window to edit the corresponding <Strategy>... section . </Strategy>:)
Yeah, that would be cool. All that's left is to find someone to jump in and do it. It's not hard to do, I can even tell you what to do.
 
Vasiliy Sokolov:
Yeah, that'd be cool. I just need to find someone who's willing to step up and do it. It's not hard to do, I can even tell you what to do.
I'm still just learning ... :)
 

Good afternoon, Vasily!

Great engine! ...of course I have to finish some things (for example, work with pending orders).... but this is already tuning...

I have a question... For some reason the position is not closed when m_trade.PositionClose() method is called... error 10030, 10015 occurs when closing a position.

I understand that compared to MQL4 in terms of closing orders/positions everything has changed a lot... I want to understand what the problem is....

 

Vasiliy Sokolov, it should be noted that you have done a tremendous job of creating a universal engine, and demonstrated just a virtuoso mastery of OOP. So studying this material is useful even by itself to improve your MQL5 programming skills.

The engine contains a lot of necessary and useful points and will be in demand by many traders.

I am currently migrating my robots from S#.Shell engine to MT5, and I must say that the trading engine you have created implements many features that I lacked when I got acquainted with the standard Expert Advisor templates presented in Codebase. Moreover, many things are implemented at the same level, and even cooler, although the mentioned product is the work of a whole team of programmers.

In this regard, after familiarisation, I decided to stop working on my code and port it to your engine.

 
Сергей Лебедев:

Vasiliy Sokolov, it should be noted that you have done a tremendous job of creating a universal engine, and demonstrated just a virtuoso mastery of OOP. So studying this material is useful even by itself to improve your MQL5 programming skills.

The engine contains a lot of necessary and useful points and will be in demand by many traders.

I am currently migrating my robots from S#.Shell engine to MT5, and I must say that the trading engine you have created implements many features that I lacked when I got acquainted with the standard Expert Advisor templates presented in Codebase. Moreover, many things are implemented at the same level, and even cooler, although the mentioned product is the work of a whole team of programmers.

In this regard, after familiarisation, I decided to stop working on my code and port it to your engine.

Thank you for your appreciation of my proposed approach.

I would like to note that CStrategy trading engine itself is based on the standard library, starting from data organisation classes and ending with CTrade trading class. The standard library is good, robust and efficient, but not all of its classes are really OO. Many of them are just wrappers for standard functions. The goal of the OO approach is not to call a standard function in yet another more complex way, but to perform a useful task in the most efficient way possible, while hiding the complexity of the implementation. But this is already a philosophy...

 
Vasiliy Sokolov:

Thank you for your appreciation of my proposed approach.

I would like to note that the CStrategy trading engine itself is based on a standard library, starting from data organisation classes and ending with the CTrade trading class. The standard library is good, robust and efficient, but not all of its classes are really OO. Many of them are just wrappers for standard functions. The goal of the OO approach is not to call a standard function in yet another more complex way, but to perform a useful task in the most efficient way possible, while hiding the complexity of the implementation. But this is already a philosophy...

Tell me how to use the MoneyManagement module. It is not shown anywhere in the examples. Are MM settings supposed to be different for each strategy or are the settings common for the whole portfolio?

Why do these external variables in MoneyManagement.mqh? I don't understand where they are used.

input ENUM_MM_TYPE TypeMM;           // Тип управления MM

input double       FixLotOrPercent;  // Фикс. лот или % 

 

Hi.

Interesting material. I have read it and decided to try it in practice. I am trying to compile the attached Expert Advisor Agent.mq5 in MT5 Build 1295. All files are error-free, but at the end "Internal compiler error." :( Can you tell me where to dig?