cant modify trades

 
For some reason it doesnt update my trades with the new TP.
Please help.
double BAvgTP (){
   double ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double newbtp;
   double loss = 0.00;
   double Lsize = 0.00;
   for(int i=PositionsTotal()-1;i>=0;i--){
      string name = PositionGetSymbol(i);
      if (_Symbol == name){
         ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
         if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY )
            loss = loss + PositionGetDouble(POSITION_PROFIT);
            if (Lsize < PositionGetDouble(POSITION_VOLUME))
            Lsize = PositionGetDouble(POSITION_VOLUME);
      }
   }
   double tickvalue =SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE) * Lsize;
   tickvalue = (loss / tickvalue) + dtp*_Point;
   newbtp = ask + tickvalue;
   
   for(int i=PositionsTotal()-1;i>=0;i--){
      string name = PositionGetSymbol(i);
      if (_Symbol == name){
         ulong PositionTicket = PositionGetInteger(POSITION_TICKET);
         if (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY )
            trade.PositionModify(PositionTicket,NULL,newbtp);         
      }
   }
   return (newbtp);
}
 

If your code doesn't do what it should:

  1. look what is written in the logs
  2. use the debugger to control the values of the variables:
        https://www.metatrader5.com/en/metaeditor/help/development/debug
        https://www.mql5.com/en/articles/654
        https://www.mql5.com/en/articles/272
        https://www.mql5.com/en/articles/150
        Can i get any Free Tutorial for Forex Trading?  https://www.mql5.com/en/forum/381853#comment_25845157

Reason: