Discussion of article "Developing multi-module Expert Advisors"

 

New article Developing multi-module Expert Advisors has been published:

MQL programming language allows implementing the concept of modular development of trading strategies. The article shows an example of developing a multi-module Expert Advisor consisting of separately compiled file modules.

As a result of the transformation, we obtain a modular EA allowing the integration of up to seven external modules.

  • Module 1 — money management module. It provides a lot size.
  • Module 2 — tracking positions and placing SL. It provides a distance to SL in points from the Open price.
  • Module 3 — tracking positions and placing TP. It provides a distance to TP in points from the Open price.
  • Module 4 — tracking positions and placing a trailing stop. It provides a distance to SL in points from the current price.
  • Module 5 — trading signals generation. It provides a signal value.
  • Module 6 — module for sorting out trading signals. It provides the filter value.
  • Module 7 — tracking positions and placing a breakeven level. It provides a distance to SL from the Open price.


Fig. 2. OnInit() function and initializing external modules

Author: Sergey Pavlov

 
What an unusual thesis "Auxiliary (external) module is an indicator", and did the author test the performance and especially the resource consumption of such a design?
 

The multimodularity of a trading system is determined primarily by the nature of the process (for financial markets, price movement is a non-stationary process).

And modelling of such a complex process (as EA development is always a process modelling) is impossible with the help of a single, even very complex input algorithm. To get closer to the process in terms of accuracy, we need a set of algorithms (modules), each of which is an independent model.

 
Aleksandr Masterskikh:

The multimodularity of the trading system is determined primarily by the nature of the process (for financial markets, price movement is a non-stationary process).

And modelling of such a complex process (as EA development is always a process modelling) is impossible with the help of a single, even very complex input algorithm. To get closer to the process in terms of accuracy, we need a set of algorithms (modules), each of which is an independent model.

Yes, yes, I think this approach is used by the majority of people - they implement them through functions and classes, in extreme case they just plug in a piece of code from another file. I am just wondering what is the advantage of data processing in indicators compared to the approaches described above.

[Deleted]  
modularity for modularity's sake?
put trall and lossless in 2 different separate modules? Really?
the author has probably never been involved in optimisation, especially in Mt4.
Most of the authors write using such methods, the simplest functions are put in a separate module called dozens of times per tick.
Such solutions increase optimisation time from tens to thousands of times.
 
Aleksey Vyazmikin:
What an unusual thesis "Auxiliary (external) module is an indicator", and the author has tested the performance and especially resource consumption of such a design?

The article was born after I faced a problem with the performance of one indicator. It consumed resources and testing time. And since it was used to generate trading signals, instead of it I made an external module (a signal indicator), which did not draw anything. As a result, the Expert Advisor with the external module "flew", although all the calculations remained in full.

I agree with you that any technology has its overheads. Here you need to compromise and choose what is more important. Sometimes it is more important to hide the algorithm rather than performance. Although performance decreases with modular programming, it is not critical. In the figure, I "hung" all the external modules on one graph:


Then, I checked the load of the Expert Advisor itself: in the mode of operation without and with external modules. The result was satisfactory:


Then I ran it in the strategy tester.

Without external modules:

2018.03.26 06:32:23.684 Core 1  EURUSD,M1: 2378530 ticks, 24349 bars generated. Environment synchronized in 0:00:00.140. Test passed in 0:00:07.769 (including ticks preprocessing 0:00:00.171).


And with external modules:

2018.03.26 06:33:49.859 Core 1  EURUSD,M1: 2378530 ticks, 24349 bars generated. Environment synchronized in 0:00:00.047. Test passed in 0:00:06.349.

As you can see, with external modules the testing ended faster.

The purpose of the article is to show how you can hide your algorithms using them in other people's codes.

 
Nikolay Khrushchev:
modularity for modularity's sake?
take out trall and no-loss in 2 different separate modules? really?
...

The article shows the technology of modular programming: any necessary function or group of functions can be hidden in an external module(s).

 
Sergey Pavlov:

The article was born after I faced a problem with the performance of one indicator. It was eating up resources and testing time. And since it was used to generate trading signals, instead of it I made an external module (signal indicator), which did not draw anything. As a result, the Expert Advisor with the external module "flew", although all calculations remained in full.

I agree with you that any technology has its overheads. Here you need to compromise and choose what is more important. Sometimes it is more important to hide the algorithm rather than performance. Although performance decreases with modular programming, it is not critical. In the figure, I have "hung" all the external modules on one graph:


Then, I checked the load of the Expert Advisor itself: in the mode of operation without and with external modules. The result is satisfactory:


Then I ran it in the strategy tester.

Without external modules:


And with external modules:

As you can see, the testing ended faster with external modules.

The purpose of the article is to show how you can hide your algorithms using them in other people's codes.

Thank you for your detailed answer. As a possibility of hiding a part of code, perhaps it is an option. However, who needs such a module, i.e. you can't sell it through the market, in freelancing people will demand the source code, there is only one option left - for public use on the Internet, and here it is forbidden to post compiled files.

The ability to speed up calculations due to the indicator used - a familiar topic, it is really convenient sometimes and allows you to get rid of cycles in the Expert Advisor. I am just now starting to work on such an indicator.

 
Aleksey Vyazmikin:

Yes, yes, this approach, I think, is used by the majority of people - they implement it through functions and classes, in extreme case they just plug in a piece of code from another file. I'm just wondering what is the advantage of data processing in indicators compared to the approaches described above.

It is important to distinguish between:

- modularity of a programme (when one simple model is divided into modules)

- and modularity of a complex model (where each module is an independent model).


Any traditional indicator is a simple model, and a complex model is needed,

because a simple model is not enough to get a sufficiently accurate

representation of the process.

 
Aleksandr Masterskikh:

It is important to distinguish between the two:

- modularity of the programme (when one simple model is broken down into modules)

- and modularity of a complex model (where each module is an independent model).


Any traditional indicator is a simple model, but we need a complex model,

because a simple model is not sufficient to obtain sufficient accuracy

of the process.

Let's say that I don't know what modularity of a complex model is, then from your comment my knowledge has not increased.

Give an example of a complex model embedded in the indicator.

 

As a non-professional, I found it informative. It's a good article for beginners.

But about modularity, I think the example is not complete. It seems to me that if in the same example, each function of the main module is written in a separate file, and then with the help of conditional compilation and inludes combined into one file - then this is modular writing. In this case, each separate piece can be rewritten without affecting the main code.

As an example, instead of the code:

 if(on_lot)
     { // If there is an additional module
      double buffer_m1[];
      ArraySetAsSeries(buffer_m1,true);
      if(CopyBuffer(handle_m1,0,0,1,buffer_m1)<0) return;
      lot=buffer_m1[0];
     }

code:

 if(on_lot)
     { 
        LotCulcFuntion(lot);//This function is implemented in a separate file.
     }

P.S. The names of modular indicators in the main file do not coincide with the file names. In the main module you need to add "_ind". For example, it should be: "Module_training_module_Filter_ind". and not " Module_training_module_Filter".