PositionSizing based on Previous Bar Close

Hello Everyone,

I have done reasonable amounts of research about this and can't really find what I am searching for so trying my luck here.

I have a strategy a simple strategy that calls for buying QQQ at the open if a few conditions are met at the previous bars' close with all available dollar equity in the account.

	SetOption("MinShares",1);
	SetOption("MaxOpenLong",1);
	SetOption("MaxOpenPositions",1);
	SetOption("AllowPositionShrinking",True); 

	RoundLotSize=1;
	SetPositionSize(100,spsPercentOfEquity);
	SetTradeDelays(1,1,1,1);
	BuyPrice=Open;

My understanding is that this takes all $ equity available and divides it by the Open price and comes up with the number of shares to purchase.

From a practical point of view I would like to enter my orders after the close for execution at market at the open. (I understand the practical challenges here but just trying to backtest for now).

Something that would look like:
Shares = Available Equity at BarIndex-1 / Ref(Close,-1)

What would be the correct way to code this in AFL?

3 Years ago i had the same Problem / Question ...
Possible this helps ...

https://forum.amibroker.com/t/positionsize-in-cbt-based-on-the-previous-close-price/21238

1 Like

Yup, exactly what I was looking for. I can't believe I missed it!

Thank you!

For what it is worth, there is a single setting that you can just turn on.

See the Users' Guide:

http://www.amibroker.com/guide/w_settings.html

Use previous bar equity for position sizing

Affects how percent of current equity position sizing is performed.
Unchecked (default value) means: use current (intraday) equity to perform position sizing, checked means: use previous bar closing equity to perform position sizing.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.