Trailing Stop Function Ineffective

 
void Trailing_Stop()
   {
   for(int i = OrdersTotal() - 1; i >= 0; i--)
      {
      if(m_position.SelectByIndex(i))
         {       
                   if(m_position.PositionType() == POSITION_TYPE_BUY)
                      {
                           if(TrailingStop > 0) 
                              {
                              if(Bid - m_position.PriceOpen() >= TrailingStop*10*_Point)
                                 {
                       if(m_position.StopLoss() < (Bid - _Point*10*TrailingStop - TSLStep*10*_Point)) 
                     {                                     
                                         m_trade.PositionModify(m_position.SelectByIndex(i),Bid - _Point*10*TrailingStop,m_position.TakeProfit());
                                         return;
                                    }
                                 }
                              }
                           }
                   if(m_position.PositionType() == POSITION_TYPE_SELL) 
                      {
                      if(TrailingStop > 0) 
                         {
                         if(m_position.PriceOpen() - Ask >= TrailingStop*10*_Point)
                            {
                            if(m_position.StopLoss() > (Ask + _Point*10*TrailingStop + TSLStep*10*_Point))
                               {
                               m_trade.PositionModify(m_position.SelectByIndex(i),Ask + _Point*10*TrailingStop,m_position.TakeProfit());
                               return;
                               }
                    }
               } 
            }
         }
      }
   return;
   }

Hi All, I am using the attached function along with the CPosition and CTrade objects to create a trailing stoploss on trades placed by my EA, however upon reflecting on the behaviour of the EA it doesn't seem to be having any effect, even though the function is called on every new tick, would somebody be able to give some guidance on what could be going wrong here?