DevSolve_DS_SDK_UnitTest/ExpertStoploss.mqh

64 lines
2.8 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:49:27 +02:00
//+------------------------------------------------------------------+
//| ExpertStopLoss.mqh |
//| Copyright 2023 - Dev.Solve LTDA |
//+------------------------------------------------------------------+
#include "EngineBase.mqh"
//+------------------------------------------------------------------+
//| Class CExpertStopLoss. |
//| Purpose: Base class stop loss signals. |
//| Derives from class CEngineBase. |
//+------------------------------------------------------------------+
class CExpertStopLoss : public CEngineBase
{
public:
CExpertStopLoss();
~CExpertStopLoss();
//--- common functions of stop loss class
virtual bool CheckStopLossLong(CPositionInfo *position,double &sl,double &tp) { return(true); }
virtual bool CheckStopLossLong(double &price,double &sl,double &tp) { return(true); }
virtual bool CheckStopLossShort(CPositionInfo *position,double &sl,double &tp) { return(true); }
virtual bool CheckStopLossShort(double &price,double &sl,double &tp) { return(true); }
//--- override is new bar
virtual bool IsNewBar(ENUM_TIMEFRAMES period=WRONG_VALUE);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CExpertStopLoss::CExpertStopLoss()
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CExpertStopLoss::~CExpertStopLoss()
{
}
//+------------------------------------------------------------------+
//| Verify is New Bar |
//+------------------------------------------------------------------+
bool CExpertStopLoss::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);
}