Trailing stop for sell

 

Hi,

this code works perfectly for buy, but for sell how to do this with char "<", ">"


  // Buy Order
  for (int b=OrdersTotal()-1; b>=0; b--) {
    if (OrderSelect(b, SELECT_BY_POS, MODE_TRADES)) {  
      if (OrderMagicNumber() == MagicNumber) { // This EA ownes it
        // Check the Symbol !!!!   
        if (OrderSymbol() == Symbol() && OrderType() == OP_BUY) {
          //                          Convert pips to money.
          if (Bid-OrderOpenPrice()  > WhenToTrail*_Point) {
            if (OrderStopLoss() < Bid-TrailAmount*_Point || 
            OrderStopLoss() == 0) {  // Check whether the trail
                                                           // has already been moved,
              ticket = OrderModify(
                OrderTicket(),                             // ticket
                OrderOpenPrice(),                          // price
                
                // Shift stop loss up
                Bid-(TrailAmount*_Point),                    // stop loss
                OrderTakeProfit(),                         // take profit
                0,                                         // expiration
                CLR_NONE                                   // color
              );
                              if (ticket > 0){
                
              CreateTrailingStopStatusInfoComment("Activated!");
                          }
            } 
          }
        }
      }
    }
  }


Here:

   if (Bid-OrderOpenPrice()  > WhenToTrail*_Point) {
            if (OrderStopLoss() < Bid-TrailAmount*_Point || 
            OrderStopLoss() == 0) {  // Check whether the trail
 
  1. A sell order triggers with the Ask not the Bid.
  2. You have to think.
      if (OrderOpenPrice() - Ask > WhenToTrail*_Point) {
                if (OrderStopLoss() > Ask+TrailAmount*_Point || 
                OrderStopLoss() == 0) {  // Check whether the trail