Wizard Customized Filter --> Title=Simpler Profit filter Type=SignalAdvanced ....

 
Hello everyone, 

I am interested in creating some filters through the wizard. .. This time the intraday filter for profit or loss management..
Follows code, not working properly, could you guys help on the logic.. 

Many Thanks!
    
//+------------------------------------------------------------------+
//|                                                    SignalProfit.mqh |
//|                   Copyright 2009-2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\ExpertSignal.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\SymbolInfo.mqh>  
CPositionInfo  m_position;                      // trade position object
CSymbolInfo    m_symbol;                        // symbol info object
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class                                         |
//| Title=Simpler Profit filter                                      |
//| Type=SignalAdvanced                                              |
//| Name=SignalProfit                                                |
//| ShortName=SPF                                                    |
//| Class=CSignalSPF                                                 |
//| Page=signal_profit_filter                                        |
//| Parameter=DayProfit,double,200.0,Day Profit                      |
//| Parameter=DayLoss,double,-100.0,Day Loss                         |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CSignalSPF.                                                |
//| Appointment: Class trading signals Profit filter.                  |
//|              Derives from class CExpertSignal.                   |
//+------------------------------------------------------------------+
class CSignalSPF : public CExpertSignal
  {
protected:
   //--- input parameters
   double            m_dayprofit;
   double            m_dayloss;
   ulong             Expert_MagicNumber; 

public:
                     CSignalSPF(void);
                    ~CSignalSPF(void);
   //--- method of verification of settings
   virtual bool      ValidationSettings(void);                    
   //--- methods initialize protected data
   void              DayProfit(double value)  { m_dayprofit=value; }
   void              DayLoss(double value)    { m_dayloss=value;   }
   bool              IsTradingTime(void);
   //--- methods of checking conditions of entering the market
   virtual double    Direction(void);
  };
//+------------------------------------------------------------------+
//| Constructor                                                      |
//+------------------------------------------------------------------+
CSignalSPF::CSignalSPF(void) : m_dayprofit(200),
                               m_dayloss(-100)
  {
  }
//+------------------------------------------------------------------+
//| Destructor                                                       |
//+------------------------------------------------------------------+
CSignalSPF::~CSignalSPF(void)
  {
  }
//+------------------------------------------------------------------+
//| Validation settings protected data.                              |
//+------------------------------------------------------------------+
bool CSignalSPF::ValidationSettings(void)
  {
//--- validation settings of additional filters
   if(!CExpertSignal::ValidationSettings())
      return(false);
//--- initial data checks
   if(m_dayprofit==0 || m_dayloss==0)
     {
      printf(__FUNCTION__+": No Profit or Loss Should be consider, must not be empty to work");
      return(false);
     }
//--- ok
   return(true);
  }  
//+------------------------------------------------------------------+
//| Check conditions for time filter.                                |
//+------------------------------------------------------------------+
double CSignalSPF::Direction(void)
  {
   if(!IsTradingTime())
      return(EMPTY_VALUE); 
//--- condition OK
   return(0.0);
  }
  
bool CSignalSPF::IsTradingTime(void)
  { 
   bool result=false;
//---
   double profit_position=0.0;
   double profit_order=0.0;

   for(int i=PositionsTotal()-1;i>=0;i--)
      {if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         {if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==Expert_MagicNumber)
            {profit_position+=m_position.Commission()+m_position.Swap()+m_position.Profit();}}}
//---
   datetime end=TimeCurrent();                // current sever time
   datetime start=end-PeriodSeconds(PERIOD_H12);// set the beginning for 12 hours ago
   HistorySelect(start,end); //--- request in the cache of the program the needed interval of the trading history
   int deals=HistoryDealsTotal(); //--- obtain the number of deals in history

   for(int i=0;i<deals;i++)//--- obtain the ticket for the deal, which has the last index in the list
     {
       ulong deal_ticket   =HistoryDealGetTicket(deals-1);
       if(deal_ticket>0) // we obtained in the cache of the deal, and work with it
         {
         ulong order       =HistoryDealGetInteger(deal_ticket,DEAL_ORDER);//--- the ticket order, based on which the deal was made
         long order_magic  =HistoryDealGetInteger(deal_ticket,DEAL_MAGIC);
         profit_order      =HistoryDealGetDouble(deal_ticket,DEAL_PROFIT);
         }
         profit_order+=profit_order;
     }
//---   
        if(profit_position+profit_order>m_dayprofit) result=true;
        if(profit_position+profit_order<m_dayloss) result=true;
//---
   return(result);
  }  
//+------------------------------------------------------------------+

 
Ljordao2018:

*What* is not working properly?


Clarify your question, tell about the wrong behaviour, what is going wrong and how was it supposed to do, etc..

 
rrocchi:

*What* is not working properly?


Clarify your question, tell about the wrong behaviour, what is going wrong and how was it supposed to do, etc..

Sorry for that.. I'll try to Clarify my question,

 

The idea is to have a filter that could be possible to use on Wizard that verify the daily profit and stop to trade if we have any one of two values. Daily Profit or Daily Loss.

To compile I don't have any errors, but I think I'm missing something in the logic.

When I created some EA using the Wizard and put the filter together is not stopping entry a new trade.

I would like to have a Filter that allow or not a new entry position/order based on the profit/loss for the current day.

This is my first filter, thank you in advance. for help...

Reason: