Scale Out - Implementation

Guys, good afternoon.
I'm implementing a PS using the scale out, which has the following idea. When the strategy sell is triggered, I want it to move out of the open position by 50% of the money I have in it. And let the negotiation happen for two more days, then I totally leave the negotiation, that is to close the position.

PositionRisk = 0.01;
pct = (MarginDeposit*PositionRisk*100 / (PointValue * ATR(20)));    // considera o montante que gera a flutuação na conta
//AtrI = ValueWhen( Buy, ATR(20));

DoScaleOut = Sell;
//Buy = IIf ( Sell, sigScaleOut, 0);
Buy = Buy + sigScaleOut * DoScaleOut;
SetPositionSize( pct, spsPercentOfEquity);
//SetPositionSize( 50, IIf( Buy == sigScaleOut, spsPercentOfPosition, spsNoChange)); 
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); // scale out 50% of position 

IIf(Buy == sigScaleOut, ApplyStop(stopTypeNBar, stopModeBars, 1, True),spsNoChange);