Newbie Coder--Trying to code in a trailing stop loss--somewhat lost

 
Hey, so this is what I have so far:


void OnTick(void)
  {
  openedpositions=OrdersTotal();
   if ((openedpositions > 0)) 
      { 
   int totalorders = OrdersTotal();
      for(int i=0;i<totalorders;i++) // scan all orders and positions. ..
      {
      OrderSelect(i, SELECT_BY_POS);
   if ( OrderSymbol()==Symbol() && OrderMagicNumber() == uniqueGridMagic) // only look if mygrid and symbol. ..
      { 
         int type = OrderType();
  if(OrderType()==OP_BUY)
            {
               if (Bid-OrderOpenPrice()>TrailingStop*Point && OrderStopLoss()<Bid-TrailingStop*Point)
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,0,0,Green);
               }   
            }
            
            if(OrderType()==OP_SELL) 
            {
               if(OrderOpenPrice()-Ask>TrailingStop*Point && OrderStopLoss()>Ask+TrailingStop*Point)
              {
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,0,0, Red);
              }           
           }
           }
           }
           }
}
Basically, I'm trying to have it scan all open orders every tick and modify them, if they have not been modified already, like this:
1. start with static stoploss of 25 pips
2. at 5 pips profit move stoploss to entry price
3. at 8 pips profit move stoploss 4 pips behind 8 pips profit (current price)

So I think I have it able to scan all orders, correct me if Im doing it wrong, but I am totally lost on how to incorporate the stop loss like so. Any ideas guys? Much appreciated
 

hello friend,

Do you get any warning? such as "return value of 'OrderModify' should be checked"

Reason: