Trying to code my partial closes to a percentage of the tp instead of a fixed point value

 
void Partialclosing(){
double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);

ask = NormalizeDouble(ask,_Digits);
bid = NormalizeDouble(bid,_Digits);
for(int i = PositionsTotal()-1; i >= 0; i--){
      ulong posticket = PositionGetTicket(i);
      if(PositionSelectByTicket(posticket)){
         double posOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
         double PosVolume = PositionGetDouble(POSITION_VOLUME);
         double postp = PositionGetDouble(POSITION_TP);
         double possl = PositionGetDouble(POSITION_SL);
         ENUM_POSITION_TYPE Postype = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
      //breakeven test
      
      double firstpartialclose = postp - ((postp / 100) * FirstPartialClosePoints);
      firstpartialclose = NormalizeDouble(firstpartialclose,_Digits);
      double secondpartialclose = postp - ((postp / 100) * SecondPartialClosePoints);
      secondpartialclose = NormalizeDouble(secondpartialclose,_Digits);
      
      
         if(Postype == POSITION_TYPE_BUY){
            if(bid > posOpenPrice + firstpartialclose * _Point){
               double sl = posOpenPrice + breakevenbuffer * _Point;
               sl = NormalizeDouble(sl,_Digits);
               if(sl > possl){
                  if(trade.PositionModify(posticket,sl,postp)){
                     Print("breakeven activated on first partial");
                  
                  }
               
               }
               }
         }else if(Postype == POSITION_TYPE_SELL){
         if(ask < posOpenPrice - firstpartialclose * _Point){
               double sl = posOpenPrice - breakevenbuffer * _Point;
               sl = NormalizeDouble(sl,_Digits);
               if(sl < possl){
                  if(trade.PositionModify(posticket,sl,postp)){
                     Print("breakeven activated on first partial");
                  
                  }
         
         
         }
      
      
      }
           if(Postype == POSITION_TYPE_BUY){
               if(bid > posOpenPrice + firstpartialclose * _Point){
                  if(PosVolume == Lots){
                     double lotstoclose = PosVolume * partialclosepercent;
                     lotstoclose = NormalizeDouble(lotstoclose,2);
                     
                     if(trade.PositionClosePartial(posticket,lotstoclose)){
                        Print("Pos",posticket,"closed partially");
                     
                     
                     }
                  }
               }
             } else  if(Postype == POSITION_TYPE_SELL){
               if(ask < posOpenPrice - firstpartialclose * _Point){
                  if(PosVolume == Lots){
                     double lotstoclose = PosVolume * partialclosepercent;
                     lotstoclose = NormalizeDouble(lotstoclose,2);
                     
                     if(trade.PositionClosePartial(posticket,lotstoclose)){
                        Print("Pos",posticket,"closed partially");
                     
                     
                     }
                  }
               }
             } 
               
               if(trailingSL = false){
                if(Postype == POSITION_TYPE_BUY){
               
               
               if(bid > posOpenPrice + secondpartialclose * _Point){
                  if(PosVolume < Lots){
                     double lotstoclose = PosVolume * partialclosepercent;
                     lotstoclose = NormalizeDouble(lotstoclose,2);
                     
                     if(trade.PositionClosePartial(posticket,lotstoclose)){
                        Print("Pos",posticket,"closed partially");
                    
                      trailingSL = true;
                     }
                     
                    
                  }
               }
             } else  if(Postype == POSITION_TYPE_SELL){
               if(ask < posOpenPrice - secondpartialclose * _Point){
                  if(PosVolume < Lots){
                     double lotstoclose = PosVolume * partialclosepercent;
                     lotstoclose = NormalizeDouble(lotstoclose,2);
                     
                     if(trade.PositionClosePartial(posticket,lotstoclose)){
                        Print("Pos",posticket,"closed partially");
                     
                      trailingSL = true;
                     
                     }
                  }
               }
             } 
             }
         }
      
      }


}


}

Pretty much the title, I'm having problems having my partial closing be a percentage of the whole tp instead of a fixed value and I'm not sure why. Basically, im coding a range breakout strat and I have a breakeven stop on the first partial and a trailing SL on the second partial which works just fine, but when I try to make the partial close a percentage of tp it kinda just messes up and I'm not exactly sure why. Any comments or criticisms would be greatly appreciated guys thanks!

 
First think about what the main functions are

I'd build the main functions once, just for buy, then have it depend from direction and percentage so you can call it again and again instead of using four different but same functions in a highly nested blob.