From fa12639128d8d3228a29a0bdd72d86ab929ac912 Mon Sep 17 00:00:00 2001 From: EarnForex <48102957+EarnForex@users.noreply.github.com> Date: Fri, 16 Dec 2022 10:06:13 +0100 Subject: [PATCH] 1.01 Fixed a trailing stop bug with Sell trades. --- MQL4/Experts/Trailing Stop on Profit.mq4 | 6 +++--- MQL5/Experts/Trailing Stop on Profit.mq5 | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MQL4/Experts/Trailing Stop on Profit.mq4 b/MQL4/Experts/Trailing Stop on Profit.mq4 index 3924e8d..44ed5ba 100644 --- a/MQL4/Experts/Trailing Stop on Profit.mq4 +++ b/MQL4/Experts/Trailing Stop on Profit.mq4 @@ -105,7 +105,7 @@ void TrailingStop() if (OrderType() == OP_BUY) { - if (NormalizeDouble(Bid - OrderOpenPrice(), _Digits) > NormalizeDouble(P, _Digits)) + if (NormalizeDouble(Bid - OrderOpenPrice(), _Digits) >= NormalizeDouble(P, _Digits)) { if ((TSTP != 0) && (OrderStopLoss() < NormalizeDouble(Bid - TSTP, _Digits))) { @@ -115,9 +115,9 @@ void TrailingStop() } else if (OrderType() == OP_SELL) { - if ((TSTP != 0) && (NormalizeDouble(OrderOpenPrice() - Ask, _Digits) > TSTP)) + if (NormalizeDouble(OrderOpenPrice() - Ask, _Digits) >= NormalizeDouble(P, _Digits)) { - if ((OrderStopLoss() > NormalizeDouble(Ask + TSTP, _Digits)) || (OrderStopLoss() == 0)) + if ((TSTP != 0) && ((OrderStopLoss() > NormalizeDouble(Ask + TSTP, _Digits)) || (OrderStopLoss() == 0))) { ModifyOrder(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TSTP, _Digits), OrderTakeProfit()); } diff --git a/MQL5/Experts/Trailing Stop on Profit.mq5 b/MQL5/Experts/Trailing Stop on Profit.mq5 index 69e1ded..2ac8156 100644 --- a/MQL5/Experts/Trailing Stop on Profit.mq5 +++ b/MQL5/Experts/Trailing Stop on Profit.mq5 @@ -123,7 +123,7 @@ void TrailingStop() if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) { - if (NormalizeDouble(Bid - OpenPrice, _Digits) > NormalizeDouble(P, _Digits)) + if (NormalizeDouble(Bid - OpenPrice, _Digits) >= NormalizeDouble(P, _Digits)) { if ((TSTP != 0) && (StopLoss < NormalizeDouble(Bid - TSTP, _Digits))) { @@ -133,9 +133,9 @@ void TrailingStop() } else if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) { - if ((TSTP != 0) && (NormalizeDouble(OpenPrice - Ask, _Digits) > TSTP)) + if (NormalizeDouble(OpenPrice - Ask, _Digits) >= NormalizeDouble(P, _Digits)) { - if ((StopLoss > NormalizeDouble(Ask + TSTP, _Digits)) || (StopLoss == 0)) + if ((TSTP != 0) && ((StopLoss > NormalizeDouble(Ask + TSTP, _Digits)) || (StopLoss == 0))) { ModifyPosition(ticket, OpenPrice, NormalizeDouble(Ask + TSTP, _Digits), TakeProfit); }