Trailing Profit goes on both direction how can i fix it?

 

hi i made this trailing profit script the problem is that the take profit followes the price as it goes up and down, while i want to follow just as the price rise ( for a sell order, and opposite for a buy) i don't know how to fix it, i know the problem is that in ordermodify i use the take profit by adding the ask to it so it follows the price every direction it takes, but what can i put instead of that to let it follow the price only in one direction not both?

//Sell Trailing Profit//

 int     rcnt         =  OrdersTotal();
for (int r=rcnt-1; r>=0; r--) 
 {
   if (OrderSelect(r, SELECT_BY_POS, MODE_TRADES)) 
     if ((OrderMagicNumber()==MagicNumber || OrderMagicNumber()==MagicNumberHEDGE) && (OrderType()==OP_SELL || OrderType()==OP_SELLLIMIT))
      {
       if ((OrderOpenPrice()-TAKEPROFIT) < (Bid - TrailingProfitDistanceStepPoints) || OrderTakeProfit() == 0)
        {
        if (OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),(Bid - TrailingProfitDistancePoints),0,clrNONE)) {}
        }
      }
 }