# Using multiple positionsize using spsPercentOfEquity and spsPercentOfEquity

Hi, I am experimenting with a simple formula using Scale in on subsequent buy signals. I plan to use a diff position size (dollar-based) for the first entry and all subsequent entry as a PercentOfEquity. Below is my full formula. can someone please help me with the last part of setpositionsize correctly to get the desired results. ie. first trade, invest \$ amount XXX and any subsequent buy based on the percent of Eq. Thanks in advance for any suggestions/help. cheers.

``````
BuyPrice = SellPrice = ShortPrice = CoverPrice = Close; // determines what price to use for backtesting. in this eg. CLOSE with TRADEDELAY of 0 means closing price of the day/week //

period = indicatorlength = RSILength = ATRLength = BBLength = ADXLength =  15;
BBMultiplierup = 1.618;
BBMultiplierdown = 2;
ATRMultiplier = 3;
short_period =  8;
Medium_period = 13;
Long_period =  21;
ExtraLong_period = 55;
periodtotal =  short_period +  Medium_period + Long_period ;

RS_1 = 5;
RS_2 = 8;
RS_3 = 13;
RS_4 = 21;
RS_5 = 34;
RS_6 = 55;

RSI_Index =  RSI(RSILength);

cmp = Close;
prvclose = Ref(Close, -1);
vol = Volume;
ema1 = EMA(cmp, short_period);
ema2 = EMA(cmp, long_period);

RS = RelStrength("NIFTY",fixup = 1);
RS = IIf( ! IsNull( cmp ), RS, Null );

bb = BBandTop(cmp,BBLength,BBMultiplierup);
bb1 = BBandBot(cmp,BBLength,BBMultiplierdown);

RSI_Stock = RSI(RSILength);

RiskPerShare = ATR(ATRLength) * ATRmultiplier; //has to come before pctSize

Stock_Breakout = 75;
Stock_Support = 55;
Stock_Resistance = 85;

a  = IIf(  RSI_Stock > Stock_Breakout, 1 ,0);
b = IIf(   RSI_Stock < Stock_Support , 1 ,0);

stockup = Flip(a,b);
stockdown = Flip(b,a);

PositionRisk = RSI_Stock/RSI_Index;
PctSize =  PositionRisk * BuyPrice / RiskPerShare;											// (100 - Index_Support)/(RSI_Index);
PositionSize =  10000; 																		// position size calculation - no of shares
SetOption("InitialEquity", 1000000);      													// Initial Equity Starting Value
SetOption( "UsePrevBarEquityForPosSizing", True); 											// set the use of last bars
SetOption("MinPosValue", 2000); 															// min value of shares to purchase
///SetPositionSize( 1, spsPercentOfEquity );												// set position size
SetOption( "AllowPositionShrinking", True ); 												// Shrink Position on Loss
RoundLotSize = 1 ;  																		// Lot Size
TickSize = 0.05;    																		// Tick Size
SetOption("RefreshWhenCompleted", True); 													// Refresh when completed
SetOption("CommissionMode", 1); 															// Commission in Percent Mode
SetOption("CommissionAmount", 0.15); 														// 0.15% of Trade Value
Totalpositions = 30; 																		// Max no of positions allowed (just change here)
SetOption("MaxOpenPositions", Totalpositions ); 											// formula for max open positions
PositionScore = 100-RSI_Stock  ;
//SetOption("Worstrankheld", 0);

AND C != H
AND C > 2*RiskPerShare

delay = 0;
stopAmount = RiskPerShare;
ApplyStop( stopTypeTrailing, stopModePoint, StopAmount, 0, True, 0, delay);					///@link http://www.amibroker.com/kb/2014/10/17/using-price-levels-with-applystop-function/

Sellsignal = 0 OR STOCKDOWN  ;

xsigs = ft <=50;

XsigsX =  xsigs;

exitLastBar = datetime() >= GetFnData("DelistingDate");

Sell =  Sellsignal OR exitLastBar; // helps improve performance

IIf(firsttrade ,SetPositionSize( PositionSize, spsPercentOfEquity ),SetPositionSize(PctSize, spsPercentOfEquity )) ;  // reducing percent size with every new signal//
``````

apologies the last line of the formula... should read as follows...

``````IIf(firsttrade ,SetPositionSize( PositionSize, spsValue ),SetPositionSize(PctSize, spsPercentOfEquity )) ;  // Increasing percent size with every new signal, initial investment should be hard \$ value//

``````

thanks