Trailing Stop moves in up down direction, need help check what is the error.

 
for(cnt=0;cnt<total;cnt++)
     {
     
     //set trailing stop
     if (OrderType() == OP_BUY)
      {
         if ((Bid - OrderOpenPrice()) > TrailingStop*Point)
         {
            if (OrderStopLoss() < (Bid - TrailingStop*Point) )
            {
               OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TrailingStop*Point, 0, 0);
            }
         }
    
      }
      else if (OrderType() == OP_SELL)
      {
         if ((OrderOpenPrice() - Ask) > TrailingStop * Point)
         {
            if ((OrderStopLoss() > (Ask + TrailingStop * Point)) )
            {
               OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TrailingStop*Point, 0, 0);
            }
         }
      
      }

HI all guru here,

If not mistaken, trailing stop will move your stoploss in one direction, either up or down closer to market value

Using the code above, I found that the stoploss will move up and down.

Example, for BUY, when the market value is more than the trailing stop, the stoploss will be adjusted to higher value. When the market value fall, the stoploss by right will remain there.

But I notice the stoploss will move up and down accordingly to the market price

 
for(cnt=0;cnt<total;cnt++)
     {
     
     //set trailing stop
     if (OrderType() == OP_BUY
No OrderSelect. Always count down.
    for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS)                    // Only my orders w/
    &&  OrderMagicNumber()  == magic.number                 // my magic number
    &&  OrderSymbol()       == symbolChart                  // and my pair.
    ){