TrailingFixedPips

 

Hi all,

MT5- this function showing ONE error.

Thanks for help.

//+------------------------------------------------------------------+
//| TrailingFixedPips.mqh |
//| Copyright © 2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//| Revision 2010.07.12 |
//+------------------------------------------------------------------+
#include <Expert\ExpertTrailing.mqh>
//--- inputs
input int Inp_Trailing_FixedPips_StopLevel =300; // Trailing::FixedPips::StopLevel
input int Inp_Trailing_FixedPips_ProfitLevel=30; // Trailing::FixedPips::ProfitLevel
//+------------------------------------------------------------------+
//| Class CTrailingFixedPips. |
//| Appointment: Class traling stops with fixed in pips stop. |
//| Derives from class CTrailing. |
//+------------------------------------------------------------------+
class CTrailingFixedPips : public CExpertTrailing
{
public:
//--- methods initialize protected data
virtual bool Init(CSymbolInfo* symbol,ENUM_TIMEFRAMES period,double adjusted_point);
//---
virtual bool CheckTrailingStopLong(CPositionInfo *position,double& sl,double& tp);
virtual bool CheckTrailingStopShort(CPositionInfo *position,double& sl,double& tp);
};
//+------------------------------------------------------------------+
//| Checking for input parameters and setting protected data. |
//| INPUT: symbol -pointer to the CSymbolInfo, |
//| period -working period, |
//| adjusted_point -adjusted point value. |
//| OUTPUT: true-if successful, false otherwise. |
//| REMARK: no. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::Init(CSymbolInfo* symbol,ENUM_TIMEFRAMES period,double adjusted_point)
{
if(!CExpertTrailing::Init(symbol,period,adjusted_point)) return(false);
//--- initial data checks
if(Inp_Trailing_FixedPips_ProfitLevel*(adjusted_point/m_symbol.Point())<m_symbol.StopsLevel() &&
Inp_Trailing_FixedPips_ProfitLevel!=0)
{
printf("CTrailingFixedPips: Take Profit must be greater than %d",m_symbol.StopsLevel());
return(false);
}
if(Inp_Trailing_FixedPips_StopLevel*(adjusted_point/m_symbol.Point())<m_symbol.StopsLevel())
{
printf("CTrailingFixedPips: Trailing Stop must be greater than %d",m_symbol.StopsLevel());
return(false);
}
//--- ok
return(true);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for long position. |
//| INPUT: symbol -symbol. |
//| OUTPUT: true-if successful, false otherwise. |
//| REMARK: no. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::CheckTrailingStopLong(CPositionInfo *position,double& sl,double& tp)
{
double delta;
double price=m_symbol.Bid();
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(Inp_Trailing_FixedPips_StopLevel!=0)
{
delta=Inp_Trailing_FixedPips_StopLevel*m_adjusted_point;
if(position.StopLoss()==0.0)
{
if(price-position.PriceOpen()>delta) sl=price-delta;
}
else
{
if(price-position.StopLoss()>delta) sl=price-delta;
}
}
if(Inp_Trailing_FixedPips_ProfitLevel!=0)
{
delta=Inp_Trailing_FixedPips_ProfitLevel*m_adjusted_point;
if(sl!=EMPTY_VALUE) tp=price+delta;
}
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+
//| Checking trailing stop and/or profit for short position. |
//| INPUT: symbol -symbol. |
//| OUTPUT: true-if successful, false otherwise. |
//| REMARK: no. |
//+------------------------------------------------------------------+
bool CTrailingFixedPips::CheckTrailingStopShort(CPositionInfo *position,double& sl,double& tp)
{
double delta;
double price=m_symbol.Ask();
//---
sl=EMPTY_VALUE;
tp=EMPTY_VALUE;
if(Inp_Trailing_FixedPips_StopLevel!=0)
{
delta=Inp_Trailing_FixedPips_StopLevel*m_adjusted_point;
if(position.StopLoss()==0.0)
{
if(position.PriceOpen()-price>delta) sl=price+delta;
}
else
{
if(position.StopLoss()-price>delta) sl=price+delta;
}
}
if(Inp_Trailing_FixedPips_ProfitLevel!=0)
{
delta=Inp_Trailing_FixedPips_ProfitLevel*m_adjusted_point;
if(sl!=EMPTY_VALUE) tp=price-delta;
}
//---
return(sl!=EMPTY_VALUE);
}
//+------------------------------------------------------------------+

 
FXMan77:

[...] MT5- this function showing ONE error. [...]

This is the MQL4 forum (MQL5 is at MQL5.com)... Regardless, as this code is quite long, please attach it as a file. For small code snippets, use the SRC button.