Hi, im using risk-based position sizing based on this page: https://www.amibroker.com/kb/2014/10/12/position-sizing-based-on-risk/
riskPerShare = 3*ATR(5);
positionRisk = 3;
PctSize = positionRisk * BuyPrice / riskPerShare;
SetPositionSize(200 * (PctSize/100), spsPercentOfEquity ); //to use that leverage
Im using margin for trading portfolio of stocks.
SetBacktestMode(backtestRegular);
SetOption("InitialEquity",30000);
SetOption("accountmargin",50);
SetOption("AllowPositionShrinking", True);
SetOption("AllowSameBarExit", False);
SetOption("FuturesMode", False);
SetOption("UsePrevBarEquityForPosSizing",True)
SetOption("MaxOpenPositions", maxPositions);
SetTradeDelays( 1, 1, 1, 1);
SetOption("ActivateStopsImmediately",False);
Is this correct setup to backtest with margin and risk-based position sizing ? What i thought is shoud have done - on hypothetical trade:
I have 30k USD account - 60k USD available with margin.
Buy signal on stock - PctSize 11% - PositionSize should be 22% so with margin there should be 60000 * 0,22 = 13200 USD big position.
Ive digged into trade list from backtest and its seems that with that setup, my backtest is using correct equity for margin - 60k. But it opens trades with size based on original PctSize (11% from example above, instead of 22%) and opens more trades (if there are enough signals and until 60k equity is used).
What am I doing wrong ?
Have a nice day
Petr