Discussion of article "MQL5 Wizard: How to Teach an EA to Open Pending Orders at Any Price" - page 2

 

Hi @Vladimir Karputov -- that was a very instructive article, thanks for that!

I personally find this OOP framework in MQL5 quite interesting for building bots by composing objects representing experts, signals, filters, indicators, risk managers, and so on -- very elegant approach in my opinion, as it favours code reuse and extensibility without apparently sacrificing much power... however due to its complexity the learning curve seems fairly steep.

In any case, as I'm transitioning to MQL5 exclusively and have good experience in OOP concepts/languages, I am really keen to adapt it for my own use in prototyping new trading ideas and developing trading systems studying. I have been studying and playing with the library code and was wondering about your recommended best practice approach for the following:

QUESTION: How would you integrate a trend filter for signals received in the expert?

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.

 
I switched to my trading engine a long time ago An attempt at developing an EA constructor - it's more flexible.
An attempt at developing an EA constructor
An attempt at developing an EA constructor
  • www.mql5.com
In this article, I offer my set of trading functions in the form of a ready-made EA. This method allows getting multiple trading strategies by simply adding indicators and changing inputs.
 
Vladimir Karputov #:
I switched to my trading engine a long time ago An attempt at developing an EA constructor - it's more flexible.

OK, I see -- I'm reading the article and will have a look at the attached code... in any case, I'd still appreciate your comment/opinion on the question above if you don't mind. Thanks a lot!

 
Dima Diall # :

OK, I see -- I'm reading the article and will have a look at the attached code... in any case, I'd still appreciate your comment/opinion on the question above if you don't mind. Thanks a lot!

CExpertSignal is the past. No comments.

 
Vladimir Karputov #:

CExpertSignal is the past. No comments.

:-)

Reason: