How to develop an Expert Advisor based on the ExpertSignal Class?

 
Hello there,

I want to build something based on the Expert Signal Class from the Standard Libary.
I know quite a lot about Web programming with PHP, JS and stuff but I am fairly new to those "higher" programming languages. MQL (C++ based) is one of those I guess.
So I have some questions and I hope that the more experienced developers of you can help me out.

Here is what I want to do:

I want to cover the main market models/situations (overbought/oversold, convergence/divergence, breakthrough etc.)
Every model has 1 to n filter(s) (indicators) that detect those situations, e.g. the model "overbought/oversold" has the indicators MFI, WPR and CCI.
Another model has the indicators RSI, Stoch, Momentum and CCI (again), just as an example. And so on...
So basically its a collection of 1 to n models with 1 to n indicators each.
Everything has to sit in one Expert Advisor.

How would you do that? Create one object of the Signal Class for every model and add the related filters to those objects...or create one single object for all models and append all filters to that one object?
My concern is this: The more filters one object has, the less signals will come through or the more false signals I will get. Is that true?

I hope you can help me out. Looking forward to answers.
Thanks!
 
 
angevoyageur:

Maybe this topic can help you : All about MQL5 Wizard : create robots without programming.

Thanks angevoyageur! I found some helpful information in the post you have linked.

In MQL5 Wizard: New Version under the heading "A New Mechanism for Making Trading Decisions", list item 4 it says:

"By comparing the forecasts received from the applied patterns, the strongest one is selected, and a forecast is given in the range from -100 to +100, where the sign determines the direction of the predicted movement (negative — the price will fall, positive — the price will rise). An absolute value corresponds to the strength of the found best pattern. This result is sent to the general vote."

Where is this done? I can't find it in code. Some clarification on that would be nice.

Unfortunately, most of the articles asume that one expert advisor covers one trading strategy. Thus they describe scenarios with use of 1-2 indicators.

But I want to combine many trading strategies (many market models/situations/patterns with around 10-20 indicators all together) in one expert advisor.
The Expert Advisor should "alert" the model/situation in which the market currently is. What is the best way to accomblish this?
I can see two ways:

Way 1 - Create one object for all strategies and append all indicators to that:
//--- Create signal
CExpertSignal *signal=new CExpertSignal;

//--- Create filters
CSignalRSI   *filter0=new CSignalRSI;
CSignalCCI   *filter1=new CSignalCCI;
CSignalStoch *filter2=new CSignalStoch;
  .
  .
  .
//--- Add filters
signal.AddFilter(filter0);
signal.AddFilter(filter1);
signal.AddFilter(filter2);
  .
  .
  .

Way 2 - Create one object for every single strategy and append the related indicators:
//+--------------------------------------+
//| "Overbought/Oversold"
//+--------------------------------------+
CExpertSignal *signal=new CExpertSignal;
signal.PatternsUsage(0) // Use only model 0 "reverse behind the level of overbuying/overselling"

//--- Create filters
CSignalRSI   *filter0=new CSignalRSI;
CSignalCCI   *filter1=new CSignalCCI;
CSignalStoch *filter2=new CSignalStoch;
  .
  .
  .
//--- Add filters
signal.AddFilter(filter0);
signal.AddFilter(filter1);
signal.AddFilter(filter2);
  .
  .
  .
//+----------------------------------------+
//| "Convergence/Divergence"
//+----------------------------------------+
CExpertSignal *signal=new CExpertSignal;
signal.PatternsUsage(1) // Use only model 1 "divergence of the oscillator and price"

//--- Create filters
CSignalRSI   *filter0=new CSignalRSI;
CSignalCCI   *filter1=new CSignalCCI;
CSignalStoch *filter2=new CSignalStoch;
  .
  .
  .
//--- Add filters
signal.AddFilter(filter0);
signal.AddFilter(filter1);
signal.AddFilter(filter2);
  .
  .
  .
//+--------------------------------------+
//| "Breakthrough"
//+--------------------------------------+
CExpertSignal *signal=new CExpertSignal;
signal.PatternsUsage(2) // Use only model 2 "Breakthrough"

//--- Create filters
CSignalRSI   *filter0=new CSignalRSI;
CSignalCCI   *filter1=new CSignalCCI;
CSignalStoch *filter2=new CSignalStoch;
  .
  .
  .
//--- Add filters
signal.AddFilter(filter0);
signal.AddFilter(filter1);
signal.AddFilter(filter2);
  .
  .
  .
//+--------------------------------------+
//| "Another" Strategy
//+--------------------------------------+
  .
  .
  .
What is the best way?

Looking forward to your thoughts and answers. Thanks!

MQL5 Wizard: New Version
MQL5 Wizard: New Version
  • 2011.04.29
  • MetaQuotes Software Corp.
  • www.mql5.com
The article contains descriptions of the new features available in the updated MQL5 Wizard. The modified architecture of signals allow creating trading robots based on the combination of various market patterns. The example contained in the article explains the procedure of interactive creation of an Expert Advisor.
 
yohmm:

Thanks angevoyageur! I found some helpful information in the post you have linked.

In MQL5 Wizard: New Version under the heading "A New Mechanism for Making Trading Decisions", list item 4 it says:

"By comparing the forecasts received from the applied patterns, the strongest one is selected, and a forecast is given in the range from -100 to +100, where the sign determines the direction of the predicted movement (negative — the price will fall, positive — the price will rise). An absolute value corresponds to the strength of the found best pattern. This result is sent to the general vote."

Where is this done? I can't find it in code. Some clarification on that would be nice.

It's done in the LongCondition/ShortCondition method of each module, this method are then called from the Direction method of ExpertSignal class.

Unfortunately, most of the articles asume that one expert advisor covers one trading strategy. Thus they describe scenarios with use of 1-2 indicators.

But I want to combine many trading strategies (many market models/situations/patterns with around 10-20 indicators all together) in one expert advisor.
The Expert Advisor should "alert" the model/situation in which the market currently is. What is the best way to accomblish this?
I can see two ways:

Way 1 - Create one object for all strategies and append all indicators to that:

Way 2 - Create one object for every single strategy and append the related indicators:
What is the best way?

Looking forward to your thoughts and answers. Thanks!

What you try to do is provided by the standard library, but it's not possible with the MQL5 Wizard it self.

In my opinion the best way is the second, it's more logical and flexible. Of course it's also probably more difficult, or at least that needs more work.

 
angevoyageur:
It's done in the LongCondition/ShortCondition method of each module, this method are then called from the Direction method of ExpertSignal class.

What you try to do is provided by the standard library, but it's not possible with the MQL5 Wizard it self.

In my opinion the best way is the second, it's more logical and flexible. Of course it's also probably more difficult, or at least that needs more work.

OK, great to hear that this can be done with the standard library. So I will follow way 2.

I can't see where the strongest model is selected in the LongCondition method. The following is from the RSI module:

//+------------------------------------------------------------------+
//| "Voting" that price will grow.                                   |
//+------------------------------------------------------------------+
int CSignalRSI::LongCondition(void)
  {
   int result=0;
   int idx   =StartIndex();
//---
   if(DiffRSI(idx)>0.0)
     {
      //--- the oscillator is directed upwards confirming the possibility of price growth
      if(IS_PATTERN_USAGE(0))
         result=m_pattern_0;      // "confirming" signal number 0
      //--- if the model 1 is used, search for a reverse of the oscillator upwards behind the level of overselling
      if(IS_PATTERN_USAGE(1) && DiffRSI(idx+1)<0.0 && RSI(idx+1)<30.0)
         result=m_pattern_1;      // signal number 1
      //--- if the model 2, 3, 4 or 5 is used, perform the extended analysis of the oscillator state
      if(IS_PATTERN_USAGE(2) || IS_PATTERN_USAGE(3) || IS_PATTERN_USAGE(4) || IS_PATTERN_USAGE(5))
        {
         ExtStateRSI(idx);
         //--- search for the "failed swing" signal
         if(IS_PATTERN_USAGE(2) && RSI(idx)>m_extr_osc[1])
            result=m_pattern_2;   // signal number 2
         //--- search for the "divergence" signal
         if(IS_PATTERN_USAGE(3) && CompareMaps(1,1)) // 0000 0001b
            result=m_pattern_3;   // signal number 3
         //--- search for the "double divergence" signal
         if(IS_PATTERN_USAGE(4) && CompareMaps(0x11,2)) // 0001 0001b
            return(m_pattern_4);  // signal number 4
         //--- search for the "head/shoulders" signal
         if(IS_PATTERN_USAGE(5) && CompareMaps(0x62662,5,true) && RSI(idx)>m_extr_osc[1]) // 01100010011001100010b
            result=m_pattern_5;   // signal number 5
        }
     }
//--- return the result
   return(result);
  }

Every if-clause checks whether a pattern is used. If so, the weight of this pattern is written to the result variable (It never checks if the variable has already value and if that value is greater than the current one!).

Lets assume "oversold" (model 1) was given a weight of 100 and and "divergence" (model 3) was given 60. Now lets say they are both true, which is possible isn't it?
Since the check for divergence comes after the check for oversold, weight of divergence (60) "overwrites" weight of oversold (100).

So in this case the method would return the weaker signal right!?

 
yohmm:

OK, great to hear that this can be done with the standard library. So I will follow way 2.

I can't see where the strongest model is selected in the LongCondition method. The following is from the RSI module:

Every if-clause checks whether a pattern is used. If so, the weight of this pattern is written to the result variable (It never checks if the variable has already value and if that value is greater than the current one!).

Lets assume "oversold" (model 1) was given a weight of 100 and and "divergence" (model 3) was given 60. Now lets say they are both true, which is possible isn't it?
Since the check for divergence comes after the check for oversold, weight of divergence (60) "overwrites" weight of oversold (100).

So in this case the method would return the weaker signal right!?

You are right. I had not checked the code of standard modules. It seems they don't follow this rules of the "strongest" pattern. So they have to be well understood to be used (the pattern value can be changed). Maybe we miss something, my suggestion would be to write to the ServiceDesk about that.

However for your own modules you can implement the patterns and LongCondition/ShortCondition as you wish.

Reason: