It sells only 1 position not all

Can someone help me. I would like to sell the full position after a 10 % profit.
Unfortunally it sells only 1 Position not all. What do I program here to solve this.
Thanks for any advice.

SetBacktestMode( backtestRegularRawMulti );
SetOption( "MaxOpenPositions" , 100 );
PerTrade = 1;
SetOption( "InitialEquity", 100000 );
SetPositionSize( PerTrade, spsPercentOfEquity );
ProfitTarget = 10; // profit
MINDAYHOLD = 230; // MinimumstayinTrade


// profit target stop
ApplyStop( stopTypeProfit, stopModePercent, Optimize( "Profit Target", ProfitTarget, 1, 20, 1 ), 1, False, 0, 252 );

MonthBegin = Month() != Ref( Month(), -1 );
FirstPurchase = Cum( MonthBegin ) == 1;

// Buy every month 1 % from Equity and average the price so long till profit target from average price will reach

Buy = MonthBegin ;
Sell = 0;

What you want to achieve is calling scaling out and you need to read relevant docs: http://www.amibroker.com/guide/h_pyramid.html

1 Like

I am still trying to scale in and exit the whole position. I have read the relevant docs, but didn´t catch the ball

FixedDollarAmount = 500; 
MonthBegin = Month() != Ref( Month(), -1 ); 

FirstPurchase = Cum( MonthBegin ) == 1; 

BuyFilter =  MonthBegin and c > MA(c,100); //monthly scale in and condition
SellFilter = c < MA(c,100) or Profit Target;


Buy = IIf(BuyFilter, sigScaleIn, 0 ); // each month increase position 

Sell = SellFilter; // we sell if condition
PositionSize = FixedDollarAmount;