# Help with Scale-out

I want to use Scale-out with Sell1 (10%) and Sell2 (5%) of Equity below this condition

``````Buy = Cross(EMA(C,5),EMA(C,15));

Sell = Cross(EMA(C,15),EMA(C,5));

Sell1 = Cross(EMA(C,10),EMA(C,15));

Sell2 = Cross(EMA(C,10),EMA(C,20));

SetPositionSize( 20, spsPercentOfEquity );

SetPositionSize( 10, IIf( Sell1, spsPercentOfEquity, spsNoChange ) );

SetPositionSize( 5, IIf( Sell2, spsPercentOfEquity, spsNoChange ) );
``````

But it doesn't work

How can I use Scale-out with this condition for backtest ?

Your formula is incorrect. First of all you are not even using sigScaleOut (which is required for scale-out).

https://www.amibroker.com/guide/h_pyramid.html
The manual says that both sigScaleIn and sigScaleOut should be assigned to Buy/Short variables
Look at example 3 in the manual - it provides working example.

1 Like
``````Buy = Cross(EMA(C,5),EMA(C,15));

Sell = Cross(EMA(C,15),EMA(C,5));

Sell1 = Cross(EMA(C,10),EMA(C,15));

if (Sell1 = True) {

}
SetPositionSize( 20, spsPercentOfEquity );

SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );

``````

@cecil, you need to make more of an effort.

http://www.amibroker.com/guide/a_mistakes.html

You should write (note that the code below is just an example of syntactically correct assignment using IIF function instead of if statement - it is not meant as "complete")

``````Buy = Cross(EMA(C,5),EMA(C,15));
Sell = Cross(EMA(C,15),EMA(C,5));
Sell1 = Cross(EMA(C,10),EMA(C,15));

Buy = IIF( Sell1, sigScaleOut, Buy ); // when you deal with arrays IIF should be used
SetPositionSize( 20, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) );
``````

Hello,

How to use Sell2 with this code ?

``````Buy = Cross(EMA(C,5),EMA(C,15));
Sell = Cross(EMA(C,15),EMA(C,5));
Sell1 = Cross(EMA(C,10),EMA(C,15));
Sell2 = Cross(EMA(C,10),EMA(C,20));

Buy = IIF( Sell1, sigScaleOut, Buy ); // when you deal with arrays IIF should be used