Add files via upload

This commit is contained in:
amirghadiri1987
2025-02-07 19:08:31 +03:30
committed by GitHub
parent c33ac55f2f
commit a9340e5d4e
85 changed files with 15214 additions and 0 deletions
+132
View File
@@ -0,0 +1,132 @@
//+------------------------------------------------------------------+
//| TrailingFixedPips.mqh |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\ExpertTrailing.mqh>
// wizard description start
//+----------------------------------------------------------------------+
//| Description of the class |
//| Title=Trailing Stop based on fixed Stop Level |
//| Type=Trailing |
//| Name=FixedPips |
//| Class=CTrailingFixedPips |
//| Page= |
//| Parameter=StopLevel,int,30,Stop Loss trailing level (in points) |
//| Parameter=ProfitLevel,int,50,Take Profit trailing level (in points) |
//+----------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CTrailingFixedPips. |
//| Purpose: Class of trailing stops with fixed stop level in pips. |
//| Derives from class CExpertTrailing. |
//+------------------------------------------------------------------+
class CTrailingFixedPips : public CExpertTrailing
{
protected:
//--- input parameters
int m_stop_level;
int m_profit_level;
public:
CTrailingFixedPips(void);
~CTrailingFixedPips(void);
//--- methods of initialization of protected data
void StopLevel(int stop_level) { m_stop_level=stop_level; }
void ProfitLevel(int profit_level) { m_profit_level=profit_level; }
virtual bool ValidationSettings(void);
//---
virtual bool CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp);
virtual bool CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
void CTrailingFixedPips::CTrailingFixedPips(void) : m_stop_level(30),
m_profit_level(50)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTrailingFixedPips::~CTrailingFixedPips(void)
{
}
//+------------------------------------------------------------------+
//| Validation settings protected data. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::ValidationSettings(void)
{
if(!CExpertTrailing::ValidationSettings())
return(false);
//--- initial data checks
if(m_profit_level!=0 && m_profit_level*(m_adjusted_point/m_symbol.Point())<m_symbol.StopsLevel())
{
printf(__FUNCTION__+": trailing Profit Level must be 0 or greater than %d",m_symbol.StopsLevel());
return(false);
}
if(m_stop_level!=0 && m_stop_level*(m_adjusted_point/m_symbol.Point())<m_symbol.StopsLevel())
{
printf(__FUNCTION__+": trailing Stop Level must be 0 or greater than %d",m_symbol.StopsLevel());
return(false);
}
//--- ok
return(true);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for long position. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
if(m_stop_level==0)
return(false);
//---
double delta;
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
double price =m_symbol.Bid();
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
delta=m_stop_level*m_adjusted_point;
if(price-base>delta)
{
sl=price-delta;
if(m_profit_level!=0)
tp=price+m_profit_level*m_adjusted_point;
}
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for short position. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
if(m_stop_level==0)
return(false);
//---
double delta;
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
double price =m_symbol.Ask();
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
delta=m_stop_level*m_adjusted_point;
if(base-price>delta)
{
sl=price+delta;
if(m_profit_level!=0)
tp=price-m_profit_level*m_adjusted_point;
}
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
+157
View File
@@ -0,0 +1,157 @@
//+------------------------------------------------------------------+
//| TrailingMA.mqh |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\ExpertTrailing.mqh>
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class |
//| Title=Trailing Stop based on MA |
//| Type=Trailing |
//| Name=MA |
//| Class=CTrailingMA |
//| Page= |
//| Parameter=Period,int,12,Period of MA |
//| Parameter=Shift,int,0,Shift of MA |
//| Parameter=Method,ENUM_MA_METHOD,MODE_SMA,Method of averaging |
//| Parameter=Applied,ENUM_APPLIED_PRICE,PRICE_CLOSE,Prices series |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CTrailingMA. |
//| Purpose: Class of trailing stops based on MA. |
//| Derives from class CExpertTrailing. |
//+------------------------------------------------------------------+
class CTrailingMA : public CExpertTrailing
{
protected:
CiMA *m_MA;
//--- input parameters
int m_ma_period;
int m_ma_shift;
ENUM_MA_METHOD m_ma_method;
ENUM_APPLIED_PRICE m_ma_applied;
public:
CTrailingMA(void);
~CTrailingMA(void);
//--- methods of initialization of protected data
void Period(int period) { m_ma_period=period; }
void Shift(int shift) { m_ma_shift=shift; }
void Method(ENUM_MA_METHOD method) { m_ma_method=method; }
void Applied(ENUM_APPLIED_PRICE applied) { m_ma_applied=applied; }
virtual bool InitIndicators(CIndicators *indicators);
virtual bool ValidationSettings(void);
//---
virtual bool CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp);
virtual bool CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
void CTrailingMA::CTrailingMA(void) : m_MA(NULL),
m_ma_period(12),
m_ma_shift(0),
m_ma_method(MODE_SMA),
m_ma_applied(PRICE_CLOSE)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
void CTrailingMA::~CTrailingMA(void)
{
}
//+------------------------------------------------------------------+
//| Validation settings protected data. |
//+------------------------------------------------------------------+
bool CTrailingMA::ValidationSettings(void)
{
if(!CExpertTrailing::ValidationSettings())
return(false);
//--- initial data checks
if(m_ma_period<=0)
{
printf(__FUNCTION__+": period MA must be greater than 0");
return(false);
}
//--- ok
return(true);
}
//+------------------------------------------------------------------+
//| Checking for input parameters and setting protected data. |
//+------------------------------------------------------------------+
bool CTrailingMA::InitIndicators(CIndicators *indicators)
{
//--- check
if(indicators==NULL)
return(false);
//--- create MA indicator
if(m_MA==NULL)
if((m_MA=new CiMA)==NULL)
{
printf(__FUNCTION__+": error creating object");
return(false);
}
//--- add MA indicator to collection
if(!indicators.Add(m_MA))
{
printf(__FUNCTION__+": error adding object");
delete m_MA;
return(false);
}
//--- initialize MA indicator
if(!m_MA.Create(m_symbol.Name(),m_period,m_ma_period,m_ma_shift,m_ma_method,m_ma_applied))
{
printf(__FUNCTION__+": error initializing object");
return(false);
}
m_MA.BufferResize(3+m_ma_shift);
//--- ok
return(true);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for long position. |
//+------------------------------------------------------------------+
bool CTrailingMA::CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
//---
double level =NormalizeDouble(m_symbol.Bid()-m_symbol.StopsLevel()*m_symbol.Point(),m_symbol.Digits());
double new_sl=NormalizeDouble(m_MA.Main(1),m_symbol.Digits());
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(new_sl>base && new_sl<level)
sl=new_sl;
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for short position. |
//+------------------------------------------------------------------+
bool CTrailingMA::CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
//---
double level =NormalizeDouble(m_symbol.Ask()+m_symbol.StopsLevel()*m_symbol.Point(),m_symbol.Digits());
double new_sl=NormalizeDouble(m_MA.Main(1)+m_symbol.Spread()*m_symbol.Point(),m_symbol.Digits());
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(new_sl<base && new_sl>level)
sl=new_sl;
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
+40
View File
@@ -0,0 +1,40 @@
//+------------------------------------------------------------------+
//| TrailingNone.mqh |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\ExpertTrailing.mqh>
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class |
//| Title=Trailing Stop not used |
//| Type=Trailing |
//| Name=None |
//| Class=CTrailingNone |
//| Page= |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CTrailingNone. |
//| Appointment: Class no traling stops. |
//| Derives from class CExpertTrailing. |
//+------------------------------------------------------------------+
class CTrailingNone : public CExpertTrailing
{
public:
CTrailingNone(void);
~CTrailingNone(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CTrailingNone::CTrailingNone(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTrailingNone::~CTrailingNone(void)
{
}
//+------------------------------------------------------------------+
+123
View File
@@ -0,0 +1,123 @@
//+------------------------------------------------------------------+
//| TrailingParabolicSAR.mqh |
//| Copyright 2000-2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#include <Expert\ExpertTrailing.mqh>
// wizard description start
//+------------------------------------------------------------------+
//| Description of the class |
//| Title=Trailing Stop based on Parabolic SAR |
//| Type=Trailing |
//| Name=ParabolicSAR |
//| Class=CTrailingPSAR |
//| Page= |
//| Parameter=Step,double,0.02,Speed increment |
//| Parameter=Maximum,double,0.2,Maximum rate |
//+------------------------------------------------------------------+
// wizard description end
//+------------------------------------------------------------------+
//| Class CTrailingPSAR. |
//| Appointment: Class traling stops with Parabolic SAR. |
//| Derives from class CExpertTrailing. |
//+------------------------------------------------------------------+
class CTrailingPSAR : public CExpertTrailing
{
protected:
CiSAR m_sar; // object-indicator
//--- adjusted parameters
double m_step; // the "speed increment" parameter of the indicator
double m_maximum; // the "maximum rate" parameter of the indicator
public:
CTrailingPSAR(void);
~CTrailingPSAR(void);
//--- methods of setting adjustable parameters
void Step(double step) { m_step=step; }
void Maximum(double maximum) { m_maximum=maximum; }
//--- method of creating the indicator and timeseries
virtual bool InitIndicators(CIndicators *indicators);
//---
virtual bool CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp);
virtual bool CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
void CTrailingPSAR::CTrailingPSAR(void) : m_step(0.02),
m_maximum(0.2)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
void CTrailingPSAR::~CTrailingPSAR(void)
{
}
//+------------------------------------------------------------------+
//| Create indicators. |
//+------------------------------------------------------------------+
bool CTrailingPSAR::InitIndicators(CIndicators *indicators)
{
//--- check pointer
if(indicators==NULL)
return(false);
//--- add object to collection
if(!indicators.Add(GetPointer(m_sar)))
{
printf(__FUNCTION__+": error adding object");
return(false);
}
//--- initialize object
if(!m_sar.Create(m_symbol.Name(),m_period,m_step,m_maximum))
{
printf(__FUNCTION__+": error initializing object");
return(false);
}
//--- ok
return(true);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for long position. |
//+------------------------------------------------------------------+
bool CTrailingPSAR::CheckTrailingStopLong(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
//---
double level =NormalizeDouble(m_symbol.Bid()-m_symbol.StopsLevel()*m_symbol.Point(),m_symbol.Digits());
double new_sl=NormalizeDouble(m_sar.Main(1),m_symbol.Digits());
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(new_sl>base && new_sl<level)
sl=new_sl;
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for short position. |
//+------------------------------------------------------------------+
bool CTrailingPSAR::CheckTrailingStopShort(CPositionInfo *position,double &sl,double &tp)
{
//--- check
if(position==NULL)
return(false);
//---
double level =NormalizeDouble(m_symbol.Ask()+m_symbol.StopsLevel()*m_symbol.Point(),m_symbol.Digits());
double new_sl=NormalizeDouble(m_sar.Main(1)+m_symbol.Spread()*m_symbol.Point(),m_symbol.Digits());
double pos_sl=position.StopLoss();
double base =(pos_sl==0.0) ? position.PriceOpen() : pos_sl;
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(new_sl<base && new_sl>level)
sl=new_sl;
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+