Trailing Stop - Check Parenthesis Precedence

 

Hello, MQL5 Community

Please assist with the following code function: "check operator precedence for possible error; use parentheses to clarify precedence".

I have attached an image and snippet of code showing where I get the warning "⚠". Despite my best efforts, I have not been able to resolve this warning.

The area affected is within the "if(OrderType() == OP_SELL) provided in the code:

|| (OrderStopLoss() == 0.0))

Please let me know if I am missing anything and if so, I would appreciate your support and guidance with the correct format.

id TrailingStop(int ticket)
  {
   bool res;
   res = OrderSelect(ticket, SELECT_BY_TICKET);

   if(TrailingStop == True)
      return;
   int      tOrder = 0;
   string   pair = "";
   double sl = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss
   pair = Symbol();
   tOrder = OrdersTotal();
   for(int i = tOrder - 1; i >= 0; i--)
     {
      if(OrderType() == OP_BUY)
        {
         if(Ask> NormalizeDouble(OrderOpenPrice() + TrailingStart * vPoint,Digits)
            && sl < NormalizeDouble(Bid - (TrailingStop + TrailingStep) * vPoint,Digits))
           {
            sl = NormalizeDouble(Bid - TrailingStop * vPoint,Digits);
            ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Blue);
            if(!res)
              {
               Alert("TrailingStop OrderModify Error: ", GetLastError());
              }
           }
        }

      if(OrderType() == OP_SELL)
        {
         if((Bid < NormalizeDouble(OrderOpenPrice() - TrailingStart * vPoint,Digits))
            && (sl > (NormalizeDouble(Ask + (TrailingStop + TrailingStep)* vPoint,Digits)))
            || (OrderStopLoss() == 0.0))
           {
            sl = NormalizeDouble(Ask + TrailingStop * vPoint,Digits);
            ticket = OrderModify(OrderTicket(),OrderOpenPrice(),sl,OrderTakeProfit(),0,Red);
            if(!res)
              {
               Alert("TrailingStop OrderModify Error: ", GetLastError());
              }
           }
        }
     }
  }
 

In your case it warns you because of this:

if((Bid < NormalizeDouble(OrderOpenPrice() - TrailingStart * vPoint,Digits))
            && (sl > (NormalizeDouble(Ask + (TrailingStop + TrailingStep)* vPoint,Digits)))
            || (OrderStopLoss() == 0.0))

There && and || are mixed and the compiler doesn't know what you want: if (a && (b || c))  or if ((a && b) || c) 

Check it - it's different.

 
   if((Bid < NormalizeDouble(OrderOpenPrice() - TrailingStart * vPoint, Digits)
       && sl > NormalizeDouble(Ask + (TrailingStop + TrailingStep) * vPoint, Digits))
      || OrderStopLoss() == 0.0)
 

Re: Trailing Stop - Check Parenthesis Precedence

Thanks for spotting the warning mistakes made during the coding process. I am forevermore thankful for such an open-minded community.

Exhaustion may have played a role in these mistakes. I'm working on it though, and learning through this support community...

Thanks @Vinicius de Oliveira & @Carl Schreiber

 
OTMT Howard #Thanks for spotting the warning mistakes made during the coding process. I am forevermore thankful for such an open-minded community. Exhaustion may have played a role in these mistakes. I'm working on it though, and learning through this support community... Thanks @Vinicius de Oliveira & @Carl Schreiber


You're welcome. 👍

Reason: