Help with Scale-out

After read guide at https://www.amibroker.com/guide/h_pyramid.html

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).

Follow the manual precisely. Re-read
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) {

Buy = sigScaleOut;

}
SetPositionSize( 20, spsPercentOfEquity );

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

It doesn't work, please help.

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

Your code is incorrect.

Please read this
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
Buy = IIF( Sell2, sigScaleOut, Buy ); 

SetPositionSize( 20, spsPercentOfEquity );
SetPositionSize( 50, spsPercentOfPosition * ( Buy == sigScaleOut ) ); 
SetPositionSize( 25, spsPercentOfPosition * ( Buy == sigScaleOut ) ); 

It doesn't work.

@Thomasz, I was trying to understand how position sizing is executing the quantity. Is it that in each position sizing (ex. 50% target hit or 50% SL hit) the entire quantity is getting squared off and new position is building based on the percentage (i.e. 50% in this case). As we only use either Buy or Short with `sigScaleIn' and sigScaleOut .