variable profit and stop loss in CExpertSignal

 

Hello,

I would like to create a descendant class of CExpertSignal. I plan to use make it callable by the EA wizard, as demonstrated here: https://www.mql5.com/en/articles/367.

An instance of this class will be added as a filter in the CExpertSignal generated. In addition to giving a buy or sell signal, this instance should also set the take profit and the stop loss of the trade.

The bit of the code where the main CExpertSignal instance (signal) and the instance of the descendant class (filter0) are created and where the latter instance is added as a filter is shown here:

//--- Creating signal
   CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//---
   ExtExpert.InitSignal(signal);
   signal.ThresholdOpen(Signal_ThresholdOpen);
   signal.ThresholdClose(Signal_ThresholdClose);
   signal.PriceLevel(Signal_PriceLevel);
   signal.StopLevel(Signal_StopLevel);
   signal.TakeLevel(Signal_TakeLevel);
   signal.Expiration(Signal_Expiration);
//--- Creating filter MA_Cross
   MA_Cross *filter0=new MA_Cross;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter0);

 How can I modify the stop level (m_stop_level) and the take level (m_take_level) of signal from within filter0 ? 

Create Your Own Trading Robot in 6 Steps!
Create Your Own Trading Robot in 6 Steps!
  • www.mql5.com
If you don't know how trade classes are constructed, and are scared of the words "Object Oriented Programming", then this article is for you. In fact, you do not need to know the details to write your own module of trading signals. Just follow some simple rules. All the rest will be done by the MQL5 Wizard, and you will get a ready-to-use trading robot!
 

If anyone is intested, I found the solution. 

Just set filter0 as the main signal:

        signal.General(filter0);

The EA will then use the m_stop_level and m_take_level of filter0 when placing orders.

Reason: