trailing stop not trailing

 
when looking in the journal the orders are not even trying to be modified. i assume there is a problem with the if statements
double Trailing_Stop = 100;



int init()
{
   double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
   if (ticksize == 0.0001 || ticksize == 0.001)
   pips = ticksize*10;
   else pips = ticksize;
}   

void OnTick()
  {
  
      for(int b=OrdersTotal();b=0;b--)
      {
      if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
            if(OrderType()==OP_BUY)
               if(OrderStopLoss()<Bid-pips*Trailing_Stop)
                  OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(pips*Trailing_Stop),OrderTakeProfit(),0,clrNONE);
      }
      
         for(int a=OrdersTotal();a=0;a--)
      {
      if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
         if(OrderSymbol()==Symbol())
            if(OrderType()==OP_SELL)
              if(OrderStopLoss()>Ask+pips*Trailing_Stop||OrderStopLoss()==0)
                  OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(pips*Trailing_Stop),OrderTakeProfit(),0,clrNONE);
      }
 
SladeMcBride:
when looking in the journal the orders are not even trying to be modified. i assume there is a problem with the if statements

(1) These two lines are different:

               if(OrderStopLoss()<Bid-pips*Trailing_Stop)
              if(OrderStopLoss()>Ask+pips*Trailing_Stop||OrderStopLoss()==0)

(2) This is not right - usually we check ticksize == 0.01 and == 0.0001, never 0.001 with 0.0001. And if it's 0.0001 or 0.01, then pips should be ticksize / 10, not * 10. (or course, your use of the name 'pips' here is confusing, but that's a different issue... LOL).

   if (ticksize == 0.0001 || ticksize == 0.001)
   pips = ticksize*10;
   else pips = ticksize;

(3) You want to iterate from OrdersTotal()-1 to 0, not OrdersTotal() to 0 - not necessary.

      for(int b=OrdersTotal();b=0;b--)


 
  for(int b=OrdersTotal();b=0;b--)
Your loops do nothing, because in the test you assign zero to b, and zero is false, so loop exits immediately.
  for(int b=OrdersTotal() - 1; b >= 0; b--)
Reason: