I found this part of code somewhere here on mql5.com. It looks great as I need to place Trailing Stop in most of my EAs.
Nevertheless I am not sure what is exactly the meaning of those 3 parameters : ZeroLevel, TrailingStop, TrailingStep
I already placed order (let's say BUY case) with a STOP LOSS and a TAKE PROFIT. Let's say TP is 100 and SL is 50.
Well indeed I would just need 1 parameter (that I would call TRAILING = 30) which would move my initial STOP LOSS to PriceOpen + the gap between CurrentPrice and TAKE PROFIT as soon as PriceOpen+TAKE PROFIT is crossed over...
In this perspective could you help me to understand the meaning of these 3 parameters ?
for(int i=PositionsTotal()-1;i>=0;i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic) { if(m_position.PositionType()==POSITION_TYPE_BUY) { //--- zero if(m_position.PriceOpen()<=m_position.PriceCurrent()-ExtZeroLevel && m_position.PriceOpen()>m_position.StopLoss()) { m_trade.PositionModify(m_position.Ticket(),m_position.PriceOpen(),m_position.TakeProfit()); } //--- tral if(m_position.StopLoss()<m_position.PriceCurrent()-ExtTrailingStop-ExtTrailingStep || m_position.StopLoss()==0.0) { m_trade.PositionModify(m_position.Ticket(), m_symbol.NormalizePrice(m_position.PriceCurrent()-ExtTrailingStop), m_position.TakeProfit()); } }
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi,
I found this part of code somewhere here on mql5.com. It looks great as I need to place Trailing Stop in most of my EAs.
Nevertheless I am not sure what is exactly the meaning of those 3 parameters : ZeroLevel, TrailingStop, TrailingStep
I already placed order (let's say BUY case) with a STOP LOSS and a TAKE PROFIT. Let's say TP is 100 and SL is 50.
Well indeed I would just need 1 parameter (that I would call TRAILING = 30) which would move my initial STOP LOSS to PriceOpen + the gap between CurrentPrice and TAKE PROFIT as soon as PriceOpen+TAKE PROFIT is crossed over...
In this perspective could you help me to understand the meaning of these 3 parameters ?
Many tx in advance,
BR,
PART OF CODE :
double ExtZeroLevel=0;
double ExtTrailingStop=0;
double ExtTrailingStep=0;
(...)
//--> TRAILING STOP
for(int i=PositionsTotal()-1;i>=0;i--)
if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
{
if(m_position.PositionType()==POSITION_TYPE_BUY)
{
//--- zero
if(m_position.PriceOpen()<=m_position.PriceCurrent()-ExtZeroLevel &&
m_position.PriceOpen()>m_position.StopLoss())
{
m_trade.PositionModify(m_position.Ticket(),m_position.PriceOpen(),m_position.TakeProfit());
}
//--- tral
if(m_position.StopLoss()<m_position.PriceCurrent()-ExtTrailingStop-ExtTrailingStep || m_position.StopLoss()==0.0)
{
m_trade.PositionModify(m_position.Ticket(),
m_symbol.NormalizePrice(m_position.PriceCurrent()-ExtTrailingStop),
m_position.TakeProfit());
}
}