Article-16991-MQL5-Post-Fac.../SymbolTradeExt.mqh

123 行
13 KiB
MQL5

2026-03-24 13:45:14 +07:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| SymbolTradeExt.mqh |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#include "Trailings.mqh"
#include "SymbolTrade.mqh"
enum ENUM_TRAILING_MODE // 5@5G8A;5=85 @568<>2 B@59;8=30
{
TRAILING_MODE_SIMPLE=2, // @>AB>9 B@0;
TRAILING_MODE_SAR, // "@0; ?> Parabolic SAR
TRAILING_MODE_AMA, // "@0; ?> 040@B82=>9 A:>;L7OI59 A@54=59
TRAILING_MODE_DEMA, // "@0; ?> 42>9=>9 M:A?>=5=F80;L=>9 A:>;L7OI59 A@54=59
TRAILING_MODE_FRAMA, // "@0; ?> D@0:B0;L=>9 040@B82=>9 A:>;L7OI59 A@54=59
TRAILING_MODE_MA, // "@0; ?> ?@>AB>9 A:>;L7OI59 A@54=59
TRAILING_MODE_TEMA, // "@0; ?> B@>9=>9 M:A?>=5=F80;L=>9 A:>;L7OI59 A@54=59
TRAILING_MODE_VIDYA, // "@0; ?> A:>;L7OI59 A@54=59 A 48=0<8G5A:8< ?5@8>4>< CA@54=5=8O
};
class CSymbolTradeExt : public CSymbolTrade
{
private:
CSimpleTrailing *m_trailing; // 1J5:B :;0AA0 B@59;8=3>2
ENUM_TIMEFRAMES m_timeframe; // "09<D@59< @0AGQB0 8=48:0B>@0 4;O B@0;0
public:
//--- #AB0=02;8205B B@0; 8 53> ?0@0<5B@K
bool SetTrailing(const ENUM_TRAILING_MODE trailing_mode, const int data_index, const long magic, const int start, const int step, const int offset, const MqlParam &param[]);
//--- 0?CA:05B B@0; C:070==>9 ?> B8:5BC ?>78F88
void Trailing(const ulong pos_ticket);
//--- >=AB@C:B>@/45AB@C:B>@
CSymbolTradeExt() : m_trailing(NULL), m_timeframe(::Period()) { this.SetSymbol(::Symbol()); }
CSymbolTradeExt(const string symbol, const ENUM_TIMEFRAMES timeframe);
~CSymbolTradeExt();
};
//+------------------------------------------------------------------+
//| >=AB@C:B>@ |
//+------------------------------------------------------------------+
CSymbolTradeExt::CSymbolTradeExt(const string symbol, const ENUM_TIMEFRAMES timeframe) : CSymbolTrade(symbol)
{
this.m_trailing=NULL;
this.m_timeframe=timeframe;
}
//+------------------------------------------------------------------+
//| 5AB@C:B>@ |
//+------------------------------------------------------------------+
CSymbolTradeExt::~CSymbolTradeExt()
{
//--- C40;O5< A>740==K9 >1J5:B B@0;0
if(this.m_trailing!=NULL)
delete this.m_trailing;
}
//+------------------------------------------------------------------+
//| #AB0=02;8205B ?0@0<5B@K B@0;0 |
//+------------------------------------------------------------------+
bool CSymbolTradeExt::SetTrailing(const ENUM_TRAILING_MODE trailing_mode, const int data_index, const long magic, const int start, const int step, const int offset, const MqlParam &param[])
{
//--- #AB0=02;8205< ?0@0<5B@K B@0;0 (4;O :064>3> B8?0 8=48:0B>@>2 8A?>;L7CNBAO B>;L:> A2>8, =C6=K5 8=48:0B>@C, ?>;O AB@C:BC@K)
int ma_period = (int)param[0].integer_value;
int ma_shift = (int)param[1].integer_value;
ENUM_APPLIED_PRICE ma_price = (ENUM_APPLIED_PRICE)param[2].integer_value;
ENUM_MA_METHOD ma_method = (ENUM_MA_METHOD)param[3].integer_value;
int fast_ema = (int)param[4].integer_value;
int slow_ema = (int)param[5].integer_value;
int period_cmo = (int)param[6].integer_value;
double sar_step = param[0].double_value;
double sar_max = param[1].double_value;
//--- 2 7028A8<>AB8 >B B8?0 B@59;8=30 A>740Q< >1J5:B B@0;0
//---5A;8 2 :0G5AB25 ?5@8>40 @0AGQB0 ?5@540=> 7=0G5=85, <5=LH5 4>?CAB8<>3>, B> 4;O :064>3> 8=48:0B>@0 CAB0=02;8205BAO 53> A>1AB25==>5 7=0G5=85 ?> C<>;G0=8N
switch(trailing_mode)
{
case TRAILING_MODE_SIMPLE :
this.m_trailing=new CSimpleTrailing(this.Symbol(), magic, start, step, offset);
break;
case TRAILING_MODE_AMA :
this.m_trailing=new CTrailingByAMA(this.Symbol(), this.m_timeframe, magic,
(ma_period<1 ? 9 : ma_period), (fast_ema<1 ? 2 : fast_ema), (slow_ema<1 ? 30 : slow_ema), ma_shift, ma_price, start, step, offset);
break;
case TRAILING_MODE_DEMA :
this.m_trailing=new CTrailingByDEMA(this.Symbol(), this.m_timeframe, magic, (ma_period==0 ? 14 : ma_period), ma_shift, ma_price, start, step, offset);
break;
case TRAILING_MODE_FRAMA :
this.m_trailing=new CTrailingByFRAMA(this.Symbol(), this.m_timeframe, magic, (ma_period==0 ? 14 : ma_period), ma_shift, ma_price, start, step, offset);
break;
case TRAILING_MODE_MA :
this.m_trailing=new CTrailingByMA(this.Symbol(), this.m_timeframe, magic, ma_period, (ma_period==0 ? 10 : ma_period), ma_method, ma_price, start, step, offset);
break;
case TRAILING_MODE_TEMA :
this.m_trailing=new CTrailingByTEMA(this.Symbol(), this.m_timeframe, magic, (ma_period==0 ? 14 : ma_period), ma_shift, ma_price, start, step, offset);
break;
case TRAILING_MODE_VIDYA :
this.m_trailing=new CTrailingByVIDYA(this.Symbol(), this.m_timeframe, magic, (period_cmo<1 ? 9 : period_cmo), (ma_period==0 ? 12 : ma_period), ma_shift, ma_price, start, step, offset);
break;
case TRAILING_MODE_SAR :
this.m_trailing=new CTrailingBySAR(this.Symbol(), this.m_timeframe, magic, (sar_step<0.0001 ? 0.02 : sar_step), (sar_max<0.02 ? 0.2 : sar_max), start, step, offset);
break;
default :
break;
}
//--- GB>-B> ?>H;> =5 B0: - 2>72@0I05< false
if(this.m_trailing==NULL)
return false;
//--- 2AQ CA?5H=> - 45;05< B@0; 0:B82=K< 8 2>72@0I05< true
this.m_trailing.SetActive(true);
return true;
}
//+------------------------------------------------------------------+
//| 0?CA:05B B@0; C:070==>9 ?> B8:5BC ?>78F88 |
//+------------------------------------------------------------------+
void CSymbolTradeExt::Trailing(const ulong pos_ticket)
{
if(this.m_trailing!=NULL)
this.m_trailing.Run(pos_ticket);
}
//+------------------------------------------------------------------+