# Position size afl help needed

#### deVille

##### New Member
The system I am testing opens random number of positions every day (Long only), and closes at the end of the day (yesterday bought 4 stocks, today bought 10 stocks, etc.). I am trying to allocate the same % of equity to each position, but since the number of positions is different every day I am not sure how to do it.

I used:
SetPositionSize(10,spsPercentOfEquity)

- but it didn't solve the problem as it always allocates 10% of equity to each position, no matter how many positions it is going to open.
What I need is (for example):

- when the system buys 4 stocks it should assign 25% of equity to each stock
- when it buys 10 tocks it should assign 10% of equity to each stok
- when it opens 20 positions it should assign 5% of equity to each stock, etc.

Is there any way to code it?

Daniel

#### Romeo1998

##### Well-Known Member
The system I am testing opens random number of positions every day (Long only), and closes at the end of the day (yesterday bought 4 stocks, today bought 10 stocks, etc.). I am trying to allocate the same % of equity to each position, but since the number of positions is different every day I am not sure how to do it.

I used:
SetPositionSize(10,spsPercentOfEquity)

- but it didn't solve the problem as it always allocates 10% of equity to each position, no matter how many positions it is going to open.
What I need is (for example):

- when the system buys 4 stocks it should assign 25% of equity to each stock
- when it buys 10 tocks it should assign 10% of equity to each stok
- when it opens 20 positions it should assign 5% of equity to each stock, etc.

Is there any way to code it?

Daniel
Dear friend,
use this code Code:
``````// First find out how many random trades will take place on that day
// then divide the capital to be used for trading by the number of trades to be taken on that day

M = 1000000;

R = 5;

// Amount Allocated for each trade today
A = M/R;

// To Allocate equal amount for each trade
SetPositionSize (A,spsValue);

// To Allocate equal amount for each trade in percentage
P = (A*100)/M;
SetPositionSize (P,spsPercentOfEquity);``````

Last edited:

#### trash

##### Well-Known Member
Dear friend,
use this code Code:
``````// First find out how many random trades will take place on that day
// then divide the capital to be used for trading by the number of trades to be taken on that day

M = 1000000;

R = 5;

// Amount Allocated for each trade today
A = M/R;

// To Allocate equal amount for each trade
SetPositionSize (A,spsValue);

// To Allocate equal amount for each trade in percentage
P = (A*100)/M;
SetPositionSize (P,spsPercentOfEquity);``````

He has to use custom backtest interface of AmiBroker.

#### Romeo1998

##### Well-Known Member

He has to use custom backtest interface of AmiBroker.
Ok friend 