Skip to content

Commit

Permalink
1.01
Browse files Browse the repository at this point in the history
Fixed a trailing stop bug with Sell trades.
  • Loading branch information
EarnForex authored Dec 16, 2022
1 parent 9da2087 commit fa12639
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions MQL4/Experts/Trailing Stop on Profit.mq4
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand All @@ -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());
}
Expand Down
6 changes: 3 additions & 3 deletions MQL5/Experts/Trailing Stop on Profit.mq5
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
{
Expand All @@ -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);
}
Expand Down

0 comments on commit fa12639

Please sign in to comment.