//+------------------------------------------------------------------+ //| ExpertTakeProfit.mqh | //| Copyright 2023 - Dev.Solve LTDA | //+------------------------------------------------------------------+ #include "EngineBase.mqh" //+------------------------------------------------------------------+ //| Class CExpertTakeProfit. | //| Purpose: Base class take profit signals. | //| Derives from class CEngineBase. | //+------------------------------------------------------------------+ class CExpertTakeProfit : public CEngineBase { public: CExpertTakeProfit(); ~CExpertTakeProfit(); //--- common functions of take profit class virtual bool CheckTakeProfitLong(CPositionInfo *position,double &sl,double &tp) { return(true); } virtual bool CheckTakeProfitShort(CPositionInfo *position,double &sl,double &tp) { return(true); } virtual bool CheckTakeProfitLong(double &price,double &sl,double &tp) { return(true); } virtual bool CheckTakeProfitShort(double &price,double &sl,double &tp) { return(true); } //--- override is new bar virtual bool IsNewBar(ENUM_TIMEFRAMES period=WRONG_VALUE); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CExpertTakeProfit::CExpertTakeProfit() { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CExpertTakeProfit::~CExpertTakeProfit() { } //+------------------------------------------------------------------+ //| Verify is New Bar | //+------------------------------------------------------------------+ bool CExpertTakeProfit::IsNewBar(ENUM_TIMEFRAMES period=WRONG_VALUE) { //--- if(period==WRONG_VALUE) period=m_period; //--- memorize the time of opening of the last bar in the static variable static datetime last_time=0; //--- current time datetime lastbar_time=(datetime)SeriesInfoInteger(m_symbol.Name(),period,SERIES_LASTBAR_DATE); //--- if it is the first call of the function if(last_time==0) { //--- set the time and exit last_time=lastbar_time; return(true); } //--- if the time differs if(last_time!=lastbar_time) { //--- memorize the time and return true last_time=lastbar_time; return(true); } //--- if we passed to this line, then the bar is not new; return false return(false); }