Scale-in and scale-out for Buy Statement in afl code and how to Apply flip/Exrem

Hi
I am studying scale-in /scale out, the below is simple code but not any logic detail to explain my question.

buyFirst=  {your logic} ;
scaleOut_1=  {your logic} ;
scaleIn_1=   {your logic} ;
sellAll= {your logic} ;

buyFirst=Flip( {logic to flip} );
buyFirst=ExRem( {logic to exrem} );

scaleOut_1=Flip( {logic to flip} );
scaleOut_1=ExRem( {logic to exrem} );


scaleIn_1=Flip( {logic to flip} );
scaleIn_1=ExRem( {logic to exrem} );


sellAll=Flip( {logic to flip} );
sellAll=ExRem( {logic to exrem} );


contractBuy= 30;
contractSO=15;
contractSI=15; 


Buy = buyFirst_ex+ (sigScaleIn * scaleIn_1_ex)+(sigScaleOut*scaleOut_1_ex);
//Buy= IIf(buyFirst_ex,1, IIf(scaleOut_1_ex,sigScaleOut,IIf(scaleIn_1_ex ,sigScaleIn,0)));

Sell=sellAll_ex;

PosSize=(buyFirst_ex*contractBuy)+(scaleOut_1_ex*contractSO)+(scaleIn_1_ex*contractSI);
SetPositionSize(PosSize,spsShares);

My 2 questions are below.

  1. Please guide to how to step to Flip and Exrem function , the code above I apply from this link http://www.amibroker.com/members/library/formula.php?id=1380

I follow as the code sample, It is ok but I don't understand a concept to apply both of them.

2.What is different detail between both statement below? , even if Both are the same result in backtesting.
2.1 Buy = buyFirst_ex+ (sigScaleIn * scaleIn_1_ex)+(sigScaleOut*scaleOut_1_ex);
2.2 Buy= IIf(buyFirst_ex,1, IIf(scaleOut_1_ex,sigScaleOut,IIf(scaleIn_1_ex ,sigScaleIn,0)));

Thank you in advance.
Pongthorn Sangkaphet