Australian (ASX) Stock Market Forum

Position size AFL help needed

Joined
26 July 2017
Posts
2
Reactions
0
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?

Thank you in advance
Daniel
 
I don't use AFL so I'm clueless on exact code but you need to make the 10 a variable and have that variable calculated as 100 divided by the number of stocks in your scan/whatever defines that number if that data is available to your software , if it isn't that's the next solution you require

make 10 (a)

make number of stocks in scan (b)

a = 100/b
 
I am not an expert in afl too, and this is actually my biggest issue, what afl function retrieves the number of positions?
 
Top