Who develops EAs using the CExpert/CExpertSignal OOP framework, aka Strategy Modules from the Standard Library?

 

Hello to all MQL5 gurus :-)

Can you please let me know if you personally develop/extend these set of classes from the Strategy Modules (MQL5\Include\Expert) to build your own trading bots? If not, have you come across others relying on this or know how widespread it is used by the MQL community?

Here's some context for my interest in these questions: I am transitioning to develop on MQL5 exclusively going forward, considering the many improvements in MT5 over the ageing MT4 platform. In this context, I am very keen to take as much advantage to use the capabilities available in the Standard Library -- I particularly like the OOP-based concept for building bots by composing objects representing experts, signals, filters, indicators, risk managers, and so on -- very elegant approach in my opinion, favouring code reuse and extensibility without sacrificing power... In fact, as I have a good deal of experience with C++/Java/Python, I was already using similar OOP approaches in my projects in MQL4.

I started studying the various classes in the Strategy Modules (CExpert, CExpertSignal, CExpertMoney, etc) and playing with some examples -- this confirmed my first impression about the elegance of this modular framework, yet the level of complexity seems quite daunting. The learning curve to master all the classes, their relationships and interdependencies appears to be steep, however I imagine it could pay off later going this OOP route to fast-track prototyping/testing new trading strategy ideas, before committing to a full R&D cycle to bring it to production.

The documentation of the Strategy Modules is not particularly great -- it's really just reference material, without a developer's guide nor any articles published with design patterns & best practices as is the case for many other topics about the  platform capabilities written by MetaQuotes and the MQL community at large. In any case, having a solid grasp of MT4/MT5 and experience coding in MQL, it's possible to get one's head around the library's concept and architecture by reading the code itself.

In addition, I remain apprehensive about diving head first to develop on top of this library because I do not find a lot of evidence of significant adoption of these Strategy Modules or even the Standard Library itself, by searching online and in these forums. I confess to be somewhat puzzled considering that MT5 has been released over 12 years by now and, according to the release notes, these libraries were first introduced shortly after (first reference found at least circa 2012). It almost looks like these classes are only used by the MQL5 Wizard function to assemble boilerplate EAs!! :-0

Another aspect raising my concerns further about investing myself too deeply are several posts from people report finding/fixing bugs in the Standard Library that appear to be ignored by MetaQuotes, as well as an "eerie" feeling of distrust by a number of experienced members of the community, even in posts as recent as 2020 -- links to a few example below:

So... THE QUESTION IS: is anyone actively developing on top of the Strategy Modules or are they really used internally by the MQL5 Wizard itself?;-)

Documentation on MQL5: Standard Library / Strategy Modules
Documentation on MQL5: Standard Library / Strategy Modules
  • www.mql5.com
Strategy Modules - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Given that no one answered, I will answer for the negative — I DO NOT use the Standard Library.

I write my code so that it is always compatible with both MQL4 and MQL5, making use of conditional compilation. This is something that the Standard Library does not do.

Had MetaQuotes the foresight to make their Standard Library compatible with both MQL5 and MQL4, they would probably have sped up the transition between platforms (which is their goal, but have been unsuccessful at it).

Also, my code is mostly procedural and when I use OOP, I code my own classes.

 
I would like to use it more but I ran into some problem with CExpertMoneyFixedRisk.
It seems you just need to set your Risk via the method Percentage() and then by using CheckOpenLong/Short you can get a Lotsize that you should keep if you want to have the set risk on your account on a deal with a certain Trailing Stop. But it only ever gives me Lotsize = 0.0. I wonder what's wrong or what I am doing wrong.
 
Fernando Carreiro #:

Given that no one answered, I will answer for the negative — I DO NOT use the Standard Library.

I write my code so that it is always compatible with both MQL4 and MQL5, making use of conditional compilation. This is something that the Standard Library does not do.

Had MetaQuotes the foresight to make their Standard Library compatible with both MQL5 and MQL4, they would probably have sped up the transition between platforms (which is their goal, but have been unsuccessful at it).

Also, my code is mostly procedural and when I use OOP, I code my own classes.

mql4 seems on data collection library, so if you use for loop to search something, the speed is very slow because of bad search performance without data colloction.

 
Liu Ying Pei #: mql4 seems on data collection library, so if you use for loop to search something, the speed is very slow because of bad search performance without data colloction.

And what does that have to do with Standard Library or OOP?

 

Thank you all for the comments so far. I agree with you, @Fernando Carreiro, MetaQuotes missed a huge opportunity to accelerate the transition from MT4 to MT5 -- some months after I started tinkering with MQL4 not long before the pandemic, I was absolutely shocked to discover that MQL5 had already been released on the market a decade earlier!!!

In the meantime, I've been studying the code and playing with the classes some more -- I'm starting to get a hang of it... I still find it overly complex/complicated, but seems like a good enough base to customise it for my needs of modularity, etc.

Here's a new question for MQL5 gurus out there -- how would you integrate a trend filter in CExpert and/or CExpertSignal?

The library includes CExpertBase::m_trend_type property but unfortunately it is not really used anywhere in the examples provided with the platform. I am divided between two design possibilities... Adding a  trend filtering object directly in my subclass of CExpert (see code snippet below), which could offer more control on making trading decisions at the level of the expert. Another way to solve it could involve fiddling with the filters of my main signal object and somehow calculate the trend and make a decision inside my subclass of CSignalExpert, e.g. inside CSignalWithTrendFilter::Direction(). Not quite sure yet what are the advantages and disadvantages of one method versus the other, and which one will provide me with more flexibility for requirements of my future projects, i.e. more code reuse without complications and less tweaking of my base classes.

class CExpertWithTrendFilter : public CExpert
{
protected:
   CExpertSignal    *m_trend;   // work in parallel with CExpert::m_signal to filter the signals it generates
// ...
   virtual bool      Processing(void);
   virtual bool      CheckOpen(void);
// ...
};

bool CExpertWithTrendFilter::Processing(void)
{
   CExpertBase::m_trend_type = (ENUM_TYPE_TREND) m_trend.Direction();   // determine current trend based from specialised object derived from CExpertSignal
   
   m_signal.TrendType(m_trend_type);             // pass trend type/strength as input to m_signal, also subclassed from CExpertSignal
   m_signal.SetDirection();                      // OPTION #1 >>> calculate signal direction, possibly taking trend established above into consideration (or not)

// ...

   if(CheckOpen())                               // OPTION #2 >>> alternatively, trend type/strength can be checked by expert before opening long or short
      return(true);

   retun(false);                                 // return without any operations
}

bool CExpertWithTrendFilter::CheckOpen(void)
{
   if(m_trend_type > TYPE_TREND_FLAT && CheckOpenLong())    // only allow opening long if trend filter direction agrees
      return(true);
   if(m_trend_type < TYPE_TREND_FLAT && CheckOpenShort())   // only allow opening short if trend filter direction agrees
      return(true);

   return(false);                                // return without any operations
}

Thanks in advance for you help and recommendations

 

Just a quick note about a 5-year old article that discusses adaptation of the Trading and Strategy Modules from the MQL5 Standard Library for use in MQL4. Looks like a promising start if someone is interested to use this OOP framework for developing EAs on MT4, but -- DISCLAIMER -- I have not really tested it at all nor planning to anytime soon...

Ready-made Expert Advisors from the MQL5 Wizard work in MetaTrader 4 - MQL5 Articles

Ready-made Expert Advisors from the MQL5 Wizard work in MetaTrader 4
Ready-made Expert Advisors from the MQL5 Wizard work in MetaTrader 4
  • www.mql5.com
The article offers a simple emulator of the MetaTrader 5 trading environment for MetaTrader 4. The emulator implements migration and adjustment of trade classes of the Standard Library. As a result, Expert Advisors generated in the MetaTrader 5 Wizard can be compiled and executed in MetaTrader 4 without changes.
 
Dmitri Diall #:

Just a quick note about a 5-year old article that discusses adaptation of the Trading and Strategy Modules from the MQL5 Standard Library for use in MQL4. Looks like a promising start if someone is interested to use this OOP framework for developing EAs on MT4, but -- DISCLAIMER -- I have not really tested it at all nor planning to anytime soon...

Ready-made Expert Advisors from the MQL5 Wizard work in MetaTrader 4 - MQL5 Articles

Hello,

I personally use de standard library classes by extending them and creating new CTrailingXXX CMoneyXXX, CSignalXXX etc. classes to extend my needs. I guess a developer would have to have 1 to 2 years of coding experience to understand and use these easily. 

I'd been keen to share insights (and code) about this as very few people are using it, and wonder why, besides

  • backwards compatibility with mt4 which I would understand very well!
  • difficulty to learn new library / frameworks
I also wonder why we don't find more articles and promotions from Metaquotes here about this standard library (are they even using it themselves ?)
 
Dmitri Diall #:

Thank you all for the comments so far. I agree with you, @Fernando Carreiro, MetaQuotes missed a huge opportunity to accelerate the transition from MT4 to MT5 -- some months after I started tinkering with MQL4 not long before the pandemic, I was absolutely shocked to discover that MQL5 had already been released on the market a decade earlier!!!

In the meantime, I've been studying the code and playing with the classes some more -- I'm starting to get a hang of it... I still find it overly complex/complicated, but seems like a good enough base to customise it for my needs of modularity, etc.

Here's a new question for MQL5 gurus out there -- how would you integrate a trend filter in CExpert and/or CExpertSignal?

The library includes CExpertBase::m_trend_type property but unfortunately it is not really used anywhere in the examples provided with the platform. I am divided between two design possibilities... Adding a  trend filtering object directly in my subclass of CExpert (see code snippet below), which could offer more control on making trading decisions at the level of the expert. Another way to solve it could involve fiddling with the filters of my main signal object and somehow calculate the trend and make a decision inside my subclass of CSignalExpert, e.g. inside CSignalWithTrendFilter::Direction(). Not quite sure yet what are the advantages and disadvantages of one method versus the other, and which one will provide me with more flexibility for requirements of my future projects, i.e. more code reuse without complications and less tweaking of my base classes.

Thanks in advance for you help and recommendations

I would create a CSignal wrapping an indicator (or not, depending on your needs) to get the trend