Using MTF. Printing values that confirm that this should work but still it doesnt?

 

I can confirm by comments that this code is calculating the desired values but it violates its own rules.

For example, for a BUY, even when Close[0] is less then limitBuy it still closes trades. Even when I am printing the values to confirm. 

Can anyone tell me why that is?

Thanks for your time

void barShiftClose(double RG2, string symb, int Magic, double Slippage, double tresholdToCloze)
{
     if(RG2 != 0)
     {
       for (int iii = OrdersTotal() - 1; iii >= 0; iii --) 
         {
         if (OrderSelect(iii, SELECT_BY_POS, MODE_TRADES))
            {
            if (OrderSymbol() == symb && OrderMagicNumber() == Magic) 
               {

               datetime then    =       TimeCurrent()-60;
               int              bar     =       iBarShift(NULL, PERIOD_M1, then, false);
               double limitBuy = ND(OrderOpenPrice()+((OrderTakeProfit()-OrderOpenPrice())*tresholdToCloze));
               double limitSell = ND(OrderOpenPrice()-((OrderOpenPrice()-OrderTakeProfit())*tresholdToCloze));
         
               switch(OrderType())
               {
               case OP_BUY:
                  RefreshRates();
                  if(Close[0] > limitBuy)
                  {OrderClose(OrderTicket(),OrderLots(), Bid,Slippage, Green);
                  }
                  Print("barClose" + Close[0]);
                  Print("0000000000 " + limitBuy);

               case OP_SELL:
                  RefreshRates();               
                  if(Close[0] < limitSell)
                  {OrderClose(OrderTicket(),OrderLots(), Ask,Slippage, Green);
                  } 
                  Print("barClose" + Close[0]);
                  Print("0000000000 " + limitSell);
                  
               }
           }
        }
     }
   } 
}