Topic: (Bug?) Slightly Different GetTrailingStopPrice() code between MT4/5
Hi Mr. Popov,
I´ve noticed that the GetTrailingStopPrice() function between MT4/5 is almost 100% identical, just one line (an extra check) is different. Shouldn´t this extra line from the MT4 function be added to the MT5 function as well?
MT4 function:
double GetTrailingStopPrice()
{
double bid = Bid();
double ask = Ask();
double stopLevelPoints = _Point * stopLevel;
double stopLossPoints = pip * Stop_Loss;
if (posType == OP_BUY)
{
double stopLossPrice = High[1] - stopLossPoints;
if (posStopLoss < stopLossPrice - pip && stopLossPrice < bid)
return stopLossPrice < bid
? stopLossPrice >= bid - stopLevelPoints
? bid - stopLevelPoints
: stopLossPrice
: bid;
}
if (posType == OP_SELL)
{
double stopLossPrice = Low[1] + stopLossPoints;
if (posStopLoss > stopLossPrice + pip)
return stopLossPrice > ask
? stopLossPrice <= ask + stopLevelPoints
? ask + stopLevelPoints
: stopLossPrice
: ask;
}
return posStopLoss;
}
MT5 function:
double GetTrailingStopPrice()
{
double bid = Bid();
double ask = Ask();
double stopLevelPoints = _Point * stopLevel;
double stopLossPoints = pip * Stop_Loss;
if (posType == OP_BUY)
{
double stopLossPrice = High(1) - stopLossPoints;
if (posStopLoss < stopLossPrice - pip)
return stopLossPrice < bid
? stopLossPrice >= bid - stopLevelPoints
? bid - stopLevelPoints
: stopLossPrice
: bid;
}
if (posType == OP_SELL)
{
double stopLossPrice = Low(1) + stopLossPoints;
if (posStopLoss > stopLossPrice + pip)
return stopLossPrice > ask
? stopLossPrice <= ask + stopLevelPoints
? ask + stopLevelPoints
: stopLossPrice
: ask;
}
return posStopLoss;
}
The difference is in this line (MT4) which is missing in MT5:
if (posStopLoss < stopLossPrice - pip && stopLossPrice < bid)
I think that extra check "&& stopLossPrice < bid" should be added to the MT5 function as well?
Thank you :-)