64 lines
No EOL
2.9 KiB
MQL5
64 lines
No EOL
2.9 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| ExpertStrategy.mqh |
|
|
//| Copyright 2024 - Dev.Solve LTDA |
|
|
//+------------------------------------------------------------------+
|
|
#include "EngineBase.mqh"
|
|
//+------------------------------------------------------------------+
|
|
//| Class CExpertStrategy. |
|
|
//| Purpose: Base class trading signals. |
|
|
//| Derives from class CEngineBase. |
|
|
//+------------------------------------------------------------------+
|
|
class CExpertStrategy : public CEngineBase
|
|
{
|
|
public:
|
|
CExpertStrategy();
|
|
~CExpertStrategy();
|
|
//--- methods for all strategy
|
|
virtual bool CheckOpenLong(double &price, double &sl, double &tp, datetime &expiration) { return(false); };
|
|
virtual bool CheckOpenShort(double &price, double &sl, double &tp, datetime &expiration) { return(false); };
|
|
virtual bool CheckTralilingOrder(COrderInfo *order, double &price, datetime &expiration) { return(false); };
|
|
virtual bool CheckClose(CPositionInfo *position) { return(false); };
|
|
//--- override is new bar
|
|
virtual bool IsNewBar(ENUM_TIMEFRAMES period=WRONG_VALUE);
|
|
};
|
|
//+------------------------------------------------------------------+
|
|
//| Constructor |
|
|
//+------------------------------------------------------------------+
|
|
CExpertStrategy::CExpertStrategy()
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Destructor |
|
|
//+------------------------------------------------------------------+
|
|
CExpertStrategy::~CExpertStrategy()
|
|
{
|
|
}
|
|
//+------------------------------------------------------------------+
|
|
//| Verify is New Bar |
|
|
//+------------------------------------------------------------------+
|
|
bool CExpertStrategy::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(false);
|
|
}
|
|
//--- 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);
|
|
} |