Error Apply trailling Stop after Partially Closing positions

 
 double lots= GetBoomLots(inpRiskPercent);
     
 if(PositionsTotal(B1Comment)>0||PositionsTotal(B2Comment)>0)
        {
        if(TakeprofitnPartialClosure(inpEA_Magic,inpTypeLot,flotsize,inpTsl_percent,inpTsl_trigger,inpPClosePercent)){
                  //trailstoploss
                           TrailStopLoss(eaMagic,Tsl_trigger,Tsl_trigger);
                           
                        }
         if(TakeprofitnPartialClosure(inpEA_Magic,inpTypeLot,lots,inpTsl_percent,inpTsl_trigger,inpPClosePercent)){
                  //trailstoploss
                           TrailStopLoss(eaMagic,Tsl_trigger,Tsl_trigger);
                           
                }

        }

Hello everyone , need help with applying trailstops after a partial closure of positions

Partial Closure of positions works perfectly the problems begins when i try to trail the remaining positions the function simply wont do anything

//Function for Trailing StopLoss
bool TrailStopLoss(int EA_Magic,double Tsl_trigger,double Tsl_percent,bool TrailApplied=false)
  {
   for(int i=PositionsTotal()-1;i>=0;i--)
     {
      CPositionInfo pos;
      if(pos.SelectByIndex(i) && pos.Symbol()==_Symbol && pos.Magic()==EA_Magic)
        {
         isPosOpen=true;

         if(pos.PositionType()==POSITION_TYPE_BUY)
           {
            if(bid>pos.PriceOpen()+NormalizeDouble((pos.PriceOpen()*Tsl_trigger/100),_Digits))
              {
               double sl =bid -bid*Tsl_percent/100;
               if(sl>pos.StopLoss())
                 {
                  if(trade.PositionModify(pos.Ticket(),sl,pos.TakeProfit()))
                    {
                     TrailApplied=true;
                    }

                 }
              }
           }
         else
            if(pos.PositionType()==POSITION_TYPE_SELL)
              {
               if(ask<pos.PriceOpen()-NormalizeDouble((pos.PriceOpen()*Tsl_trigger/100),_Digits))
                 {
                  double sl =ask+ask*Tsl_percent/100;
                  if(sl<pos.StopLoss()|| pos.StopLoss()==0)
                    {
                     if(trade.PositionModify(pos.Ticket(),sl,pos.TakeProfit()))
                       {
                        Print("Trailstops Applied");
                        TrailApplied=true;
                       }
                    }
                 }

              }



        }
     }
   return false;
  }
 
ZhuwaoAbel:

Hello everyone , need help with applying trailstops after a partial closure of positions

Partial Closure of positions works perfectly the problems begins when i try to trail the remaining positions the function simply wont do anything

Any errors? your sl is NOT normalised.

Note that you have not shown how you call the function after adding the first sl.

               if(sl>pos.StopLoss())

for buy postions, shouldnt this be < and not >???

And vice versa for Sells.