Calling CExpert TradeEvent Functions - page 2

 
Antonio Jesus Martin Ruiz:

Felipe, hello again. Where WaitEvent(EVENT) function has to be called? In to OnTick function?

You just need to call it once, so it is better to call it at OnInit() after all the wizard checks.

 
Felipe Augusto Torres Maggico:

You just need to call it once, so it is better to call it at OnInit() after all the wizard checks.

Ok, thanks Felipe.

 
Felipe Augusto Torres Maggico:

You just need to call it once, so it is better to call it at OnInit() after all the wizard checks.

Felipe, i want to share my code with you.

//+------------------------------------------------------------------+
//|                                                     MyExpert.mqh |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Expert\Expert.mqh>
#include <Expert\Signal\MySignal\SignalDNN.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class CMyExpert : public CExpert
  {
public:
   CExpertSignal     *signal;
   CSignalDNN        *filter0;
public:
                     CMyExpert();
                    ~CMyExpert();
   virtual bool      TradeEventPositionOpened(void);
   virtual bool      TradeEventPositionClosed(void);
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CMyExpert::CMyExpert()
  {
//--- Creating signal
   signal = new CExpertSignal;
//--- Creating filter0
   filter0 = new CSignalDNN();
//--- Wait for events (First time, first trade)
   WaitEvent(TRADE_EVENT_POSITION_OPEN);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CMyExpert::~CMyExpert()
  {
   delete filter0;
   delete signal;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CMyExpert::TradeEventPositionOpened(void)
  {
   filter0.RdfUpdatePolicies();
   WaitEvent(TRADE_EVENT_POSITION_CLOSE);
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool CMyExpert::TradeEventPositionClosed(void)
  {
   filter0.RdfUpdateRewards();
   WaitEvent(TRADE_EVENT_POSITION_OPEN);
   return(true);
  }
//+------------------------------------------------------------------+

If you only call to the WaitEvent() function once in OnInit() or in class constructor they are only executed on the first trade. Debugged. 

On the other hand, in order to use the events in the signal class, it is necessary to start the signal within the derived class MyExpert. I can't think of another way, but it works.

Solved. Thanks so much, Felipe.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
Predefined Macro Substitutions - Named Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Antonio Jesus Martin Ruiz:

Felipe, i want to share my code with you.

If you only call to the WaitEvent() function once in OnInit() or in class constructor they are only executed on the first trade. Debugged. 

On the other hand, in order to use the events in the signal class, it is necessary to start the signal within the derived class MyExpert. I can't think of another way, but it works.

Solved. Thanks so much, Felipe.

Excellent. Thank you for clarifying my comment.