Positionsizing based on available cash

Hi,

Is there any way to do position sizing based on available case, and not based on portfolio equity? To be more clear:
During backtesting, with the following code

SetOption("accountmargin",5);
SetPositionSize((riskpct/shortinitialslamt)*ShortPrice,spsPercentOfEquity);

amibroker backtester calculated the number of shares (ie position size ) taking into consideration the available cash + open positions. But my broker gives margin (leverage) based on the available cash only. He doesnot take into account equity of the open positions.

Say for ex: at the start of the day, the available cash is 5000. I bought 10 shares @ Rs 100. The available cash for the next trade is Rs 4000.(5000-10*100= 4000) . But the portfolio equity will be 5000 approx. (available cash : 4000 + equity of open positons: 1000).

For next trade, broker gives 20 times leverage on Rs 4000 (ie available cash) and hence i need to calculate the no of shares considering Rs 4000. But, excuse me if I am wrong, Amibroker backtester calculates shares based on portfolio equity (ie Rs 5000 approx).

Is there any way to consider only the available cash at any point of time in position sizing say fo ex:
"spspercentofcash"!!
I know it is possible through custom back tester, but any simpler way through backtester window?

Help is highly appreciated

A sample detailed trade log report of backtest for better understanding of my querry:

Date	Information	
8/17/2018 9:15:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:20:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:25:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:30:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:35:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:40:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:45:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:50:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 9:55:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 10:00:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 10:05:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 10:10:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 10:15:00 AM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 5000.00, Cash: 5000.00, Margin: 0.00, Net Cash Balance: 5000.00, 
8/17/2018 10:20:00 AM
	Entry signals(score):CIPLA=Short(-1), TECHM=Short(-1), 
	Exit signals:
	Enter Short, CIPLA, Price: 652.35, Shares: 25, Commission: 4.89263, Rank: -1, Equity 4990.21, Margin Loan: 15498, Fx rate: 1
	Enter Short, TECHM, Price: 667.2, Shares: 17, Commission: 3.40272, Rank: -1, Equity 4983.41, Margin Loan: 10778.5, Fx rate: 1
	2 Open Positions: , CIPLA (-25), , TECHM (-17), Market Value: 27577.44, Equity: 4917.99, Cash: 3617.03, Margin: -26276.47, Net Cash Balance: -22659.45, 
8/17/2018 10:25:00 AM
	Entry signals(score):HCLTECH=Short(-1), 
	Exit signals:TECHM=Cover, 
	Exit Short, TECHM, Price: 673, (Avg. exit pr. 673), Shares: 17, Commission: 3.4323, (Total comm.: 6.83502), Profit: -105.435 (-0.93 %), Entry rank:-1, Equity: 4917.44, Fx rate: 1
	Enter Short, HCLTECH, Price: 1002.25, Shares: 32, Commission: 9.6216, Rank: -1, Equity 4911.8, Margin Loan: 30477.5, Fx rate: 1
	2 Open Positions: , CIPLA (-25), , HCLTECH (-32), Market Value: 48433.96, Equity: 4933.26, Cash: 2474.80, Margin: -45975.50, Net Cash Balance: -43500.70, 
8/17/2018 10:30:00 AM
	Entry signals(score):SIEMENS=Short(-1), 
	Exit signals:
	Enter Short, SIEMENS, Price: 1016.5, Shares: 18, Commission: 5.4891, Rank: -1, Equity 4921.03, Margin Loan: 17387.4, Fx rate: 1
	3 Open Positions: , CIPLA (-25), , HCLTECH (-32), , SIEMENS (-18), Market Value: 66683.01, Equity: 4879.82, Cash: 1559.68, Margin: -63362.87, Net Cash Balance: -61803.19, 
8/17/2018 10:35:00 AM
	Entry signals(score):RELINFRA=Short(-1), RELCAPITAL=Short(-1), 
	Exit signals:
	RELINFRA not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 407.3, reqEntryPosSize: 708.348% of equity (value = 34579.2), reqLotSize: 1)
	3 Open Positions: , CIPLA (-25), , HCLTECH (-32), , SIEMENS (-18), Market Value: 66627.49, Equity: 4824.30, Cash: 1559.68, Margin: -63362.87, Net Cash Balance: -61803.19, 
8/17/2018 10:40:00 AM
	Entry signals(score):BANKINDIA=Short(-1), 
	Exit signals:RELCAPITAL=Cover, RELINFRA=Cover, 
	Enter Short, BANKINDIA, Price: 91.85, Shares: 242, Commission: 6.66831, Rank: -1, Equity 4828.97, Margin Loan: 21122.6, Fx rate: 1
	4 Open Positions: , CIPLA (-25), , HCLTECH (-32), , SIEMENS (-18), , BANKINDIA (-242), Market Value: 88952.00, Equity: 4914.44, Cash: 447.96, Margin: -84485.52, Net Cash Balance: -84037.56, 
8/17/2018 10:45:00 AM
	Entry signals(score):
	Exit signals:HCLTECH=Cover, 
	Exit Short, HCLTECH, Price: 1005.3, (Avg. exit pr. 1005.3), Shares: 32, Commission: 9.65088, (Total comm.: 19.2725), Profit: -116.872 (-0.36 %), Entry rank:-1, Equity: 4914.44, Fx rate: 1
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), Market Value: 56856.26, Equity: 4783.45, Cash: 1935.17, Margin: -54007.98, Net Cash Balance: -52072.81, 
8/17/2018 10:50:00 AM
	Entry signals(score):INDUSINDBK=Short(-1), 
	Exit signals:
	INDUSINDBK not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 1992.45, reqEntryPosSize: 937.624% of equity (value = 44964.3), reqLotSize: 1)
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), Market Value: 56754.48, Equity: 4681.67, Cash: 1935.17, Margin: -54007.98, Net Cash Balance: -52072.81, 
8/17/2018 10:55:00 AM
	Entry signals(score):ADANIENT=Short(-1), 
	Exit signals:
	Enter Short, ADANIENT, Price: 204.45, Shares: 93, Commission: 5.70415, Rank: -1, Equity 4670.27, Margin Loan: 18068.6, Fx rate: 1
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), , ADANIENT (-93), Market Value: 75854.15, Equity: 4761.79, Cash: 984.19, Margin: -72076.55, Net Cash Balance: -71092.36, 
8/17/2018 11:00:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), , ADANIENT (-93), Market Value: 75750.22, Equity: 4657.86, Cash: 984.19, Margin: -72076.55, Net Cash Balance: -71092.36, 
8/17/2018 11:05:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), , ADANIENT (-93), Market Value: 75790.44, Equity: 4698.07, Cash: 984.19, Margin: -72076.55, Net Cash Balance: -71092.36, 
8/17/2018 11:10:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), , ADANIENT (-93), Market Value: 75747.27, Equity: 4654.91, Cash: 984.19, Margin: -72076.55, Net Cash Balance: -71092.36, 
8/17/2018 11:15:00 AM
	Entry signals(score):TITAN=Short(-1), 
	Exit signals:
	TITAN not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 937.4, reqEntryPosSize: 1000% of equity (value = 46533.1), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , BANKINDIA (-242), , ADANIENT (-93), Market Value: 75810.34, Equity: 4717.98, Cash: 984.19, Margin: -72076.55, Net Cash Balance: -71092.36, 
8/17/2018 11:20:00 AM
	Entry signals(score):TATAMOTORS=Short(-1), 
	Exit signals:BANKINDIA=Cover, 
	Exit Short, BANKINDIA, Price: 92.25, (Avg. exit pr. 92.25), Shares: 242, Commission: 6.69735, (Total comm.: 13.3657), Profit: -110.166 (-0.50 %), Entry rank:-1, Equity: 4717.98, Fx rate: 1
	Enter Short, TATAMOTORS, Price: 254.95, Shares: 102, Commission: 7.80147, Rank: -1, Equity 4605.55, Margin Loan: 24712.1, Fx rate: 1
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79620.37, Equity: 4639.51, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:25:00 AM
	Entry signals(score):GRASIM=Short(-1), TATASTEEL=Short(-1), 
	Exit signals:TITAN=Cover, 
	GRASIM not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 1029.15, reqEntryPosSize: 514.55% of equity (value = 23834), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79642.88, Equity: 4662.01, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:30:00 AM
	Entry signals(score):
	Exit signals:GRASIM=Cover, TATASTEEL=Cover, 
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79568.75, Equity: 4587.89, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:35:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79651.28, Equity: 4670.42, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:40:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79647.33, Equity: 4666.47, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:45:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79667.58, Equity: 4686.72, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:50:00 AM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79636.22, Equity: 4655.36, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 11:55:00 AM
	Entry signals(score):IDEA=Short(-1), 
	Exit signals:
	IDEA not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 51.05, reqEntryPosSize: 408.4% of equity (value = 18974.5), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79614.32, Equity: 4633.46, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:00:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79603.71, Equity: 4622.85, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:05:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79654.03, Equity: 4673.17, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:10:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79601.06, Equity: 4620.20, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:15:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79680.24, Equity: 4699.38, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:20:00 PM
	Entry signals(score):KOTAKBANK=Short(-1), 
	Exit signals:
	KOTAKBANK not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 1270.45, reqEntryPosSize: 627.383% of equity (value = 29419.1), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79666.08, Equity: 4685.22, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:25:00 PM
	Entry signals(score):M&M=Short(-1), 
	Exit signals:
	M&M not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 965, reqEntryPosSize: 728.302% of equity (value = 34121.8), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79759.41, Equity: 4778.55, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:30:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79800.67, Equity: 4819.81, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:35:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79731.05, Equity: 4750.19, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:40:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TATAMOTORS (-102), Market Value: 79764.61, Equity: 4783.75, Cash: 685.11, Margin: -75665.97, Net Cash Balance: -74980.86, 
8/17/2018 12:45:00 PM
	Entry signals(score):
	Exit signals:TATAMOTORS=Cover, 
	Exit Short, TATAMOTORS, Price: 255.85, (Avg. exit pr. 255.85), Shares: 102, Commission: 7.82901, (Total comm.: 15.6305), Profit: -107.43 (-0.41 %), Entry rank:-1, Equity: 4774, Fx rate: 1
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53874.00, Equity: 4798.41, Cash: 1878.31, Margin: -50953.90, Net Cash Balance: -49075.59, 
8/17/2018 12:50:00 PM
	Entry signals(score):TECHM=Short(-1), 
	Exit signals:
	Enter Short, TECHM, Price: 680.45, Shares: 47, Commission: 9.59434, Rank: -1, Equity 4779.22, Margin Loan: 30391.2, Fx rate: 1
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85741.57, Equity: 4675.24, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 12:55:00 PM
	Entry signals(score):BHEL=Short(-1), 
	Exit signals:
	BHEL not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 73.2, reqEntryPosSize: 488% of equity (value = 22837.8), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85777.83, Equity: 4711.50, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:00:00 PM
	Entry signals(score):NMDC=Short(-1), 
	Exit signals:
	NMDC not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 105.05, reqEntryPosSize: 381.818% of equity (value = 17971.4), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85774.48, Equity: 4708.15, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:05:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85775.63, Equity: 4709.30, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:10:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85794.89, Equity: 4728.55, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:15:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85792.74, Equity: 4726.40, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:20:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85917.02, Equity: 4850.69, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:25:00 PM
	Entry signals(score):
	Exit signals:NMDC=Cover, 
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85858.06, Equity: 4791.72, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:30:00 PM
	Entry signals(score):JSWSTEEL=Short(-1), YESBANK=Short(-1), 
	Exit signals:
	JSWSTEEL not entered because of insufficient funds or wrong position size/value (reqEntryPrice: 334, reqEntryPosSize: 834.875% of equity (value = 39942.2), reqLotSize: 1)
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85927.53, Equity: 4861.19, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:35:00 PM
	Entry signals(score):
	Exit signals:JSWSTEEL=Cover, 
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85894.47, Equity: 4828.13, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:40:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85860.61, Equity: 4794.27, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:45:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85875.26, Equity: 4808.93, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:50:00 PM
	Entry signals(score):
	Exit signals:BHEL=Cover, 
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85885.96, Equity: 4819.63, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 1:55:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85823.85, Equity: 4757.51, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:00:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85801.09, Equity: 4734.75, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:05:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85811.84, Equity: 4745.51, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:10:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85807.29, Equity: 4740.96, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:15:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85828.45, Equity: 4762.11, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:20:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85811.44, Equity: 4745.11, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:25:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85744.32, Equity: 4677.99, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:30:00 PM
	Entry signals(score):
	Exit signals:YESBANK=Cover, 
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85678.20, Equity: 4611.87, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:35:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85661.90, Equity: 4595.56, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:40:00 PM
	Entry signals(score):
	Exit signals:
	4 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), , TECHM (-47), Market Value: 85667.10, Equity: 4600.76, Cash: 278.77, Margin: -81345.11, Net Cash Balance: -81066.34, 
8/17/2018 2:45:00 PM
	Entry signals(score):
	Exit signals:TECHM=Cover, 
	Exit Short, TECHM, Price: 682.4, (Avg. exit pr. 682.4), Shares: 47, Commission: 9.62184, (Total comm.: 19.2162), Profit: -110.866 (-0.35 %), Entry rank:-1, Equity: 4597.31, Fx rate: 1
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53742.76, Equity: 4556.30, Cash: 1767.45, Margin: -50953.90, Net Cash Balance: -49186.46, 
8/17/2018 2:50:00 PM
	Entry signals(score):
	Exit signals:
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53799.72, Equity: 4613.27, Cash: 1767.45, Margin: -50953.90, Net Cash Balance: -49186.46, 
8/17/2018 2:55:00 PM
	Entry signals(score):
	Exit signals:
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53824.48, Equity: 4638.02, Cash: 1767.45, Margin: -50953.90, Net Cash Balance: -49186.46, 
8/17/2018 3:00:00 PM
	Entry signals(score):
	Exit signals:
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53754.46, Equity: 4568.00, Cash: 1767.45, Margin: -50953.90, Net Cash Balance: -49186.46, 
8/17/2018 3:05:00 PM
	Entry signals(score):
	Exit signals:
	3 Open Positions: , CIPLA (-25), , SIEMENS (-18), , ADANIENT (-93), Market Value: 53729.90, Equity: 4543.45, Cash: 1767.45, Margin: -50953.90, Net Cash Balance: -49186.46, 
8/17/2018 3:10:00 PM
	Entry signals(score):
	Exit signals:ADANIENT=Cover, CIPLA=Cover, IDEA=Cover, INDUSINDBK=Cover, KOTAKBANK=Cover, M&M=Cover, SIEMENS=Cover, 
	Exit Short, CIPLA, Price: 648.05, (Avg. exit pr. 648.05), Shares: 25, Commission: 4.86037, (Total comm.: 9.753), Profit: 97.747 (0.60 %), Entry rank:-1, Equity: 4563.3, Fx rate: 1
	Exit Short, SIEMENS, Price: 1018.95, (Avg. exit pr. 1018.95), Shares: 18, Commission: 5.50233, (Total comm.: 10.9914), Profit: -55.0914 (-0.30 %), Entry rank:-1, Equity: 4563.3, Fx rate: 1
	Exit Short, ADANIENT, Price: 203.9, (Avg. exit pr. 203.9), Shares: 93, Commission: 5.68881, (Total comm.: 11.393), Profit: 39.757 (0.21 %), Entry rank:-1, Equity: 4563.3, Fx rate: 1
	0 Open Positions: , Market Value: 0.00, Equity: 4531.64, Cash: 4531.64, Margin: -0.00, Net Cash Balance: 4531.64, 
8/17/2018 3:15:00 PM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 4531.64, Cash: 4531.64, Margin: -0.00, Net Cash Balance: 4531.64, 
8/17/2018 3:20:00 PM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 4531.64, Cash: 4531.64, Margin: -0.00, Net Cash Balance: 4531.64, 
8/17/2018 3:25:00 PM
	Entry signals(score):
	Exit signals:
	0 Open Positions: , Market Value: 0.00, Equity: 4531.64, Cash: 4531.64, Margin: -0.00, Net Cash Balance: 4531.64, 

@Tvr126, your explanation of how your broker calculates "leverage" doesn't really make sense to me. In your example, you start with 5000. You buy 10 shares at 100, leaving you with 4000. That's indicating that you have no leverage at all. What if you'd purchased 50 shares at 100? You'd be unable to enter any more positions, right?

If your broker really does offer 20x leverage, then you should be setting your Account Margin to 5. Now when AmiBroker enters a new position, it will take 5% of the entry value from your cash, and the remaining 95% will be margin.

1 Like

Thanks @mradtke for your quick response and for correcting me. Yes, I f i buy 10 shares @ 100, the cash left with me, considering 20x leverage , for nest trade will be 4550. Broker would deduct Rs 50 (1000/20) from the available funds in my account.

Now I want amibroker to do position sizing based on Rs 4550 (ie the available cash) for the next trade, and not on the portfolio level equity, during backtesting. Is this feature not available in the standard backtester ?. I am afraid, i am missing something.

Just to confirm that we're on the same page, Rs 5000 - Rs 50 = Rs 4950 (not 4550), correct?

AmiBroker does not have a built-in mechanism to specify position sizing based on a percentage of available cash, but that would very seldom make sense anyway. Consider an unleveraged account (account margin = 100) with initial equity (cash) = 5000 and position sizing set to 20% of cash. The first trade would have a position size of 5000 x 20% = 1000. The second trade would have a position size of 4000 x 20% = 800, the third would be 3200 x 20% = 640, etc. Probably not really what you want.

Have you tried running your back test with % of Equity position sizing and the Account Margin set to 5? If so, how is the size of each position different than what you think it should be?

1 Like

Thanks @mradtke for correcting me again. It is Rs 4950.

Response to Para 2: That would be the case when the account is unleveraged. I have 20x leveraged account and hence it does make sense for me, as for every trade, only 5 % will be deducted from my account, rest 95 % is margin funded. The broker gives leverage on initial funds in account at the start of the day . And he keeps on deducting 5% for every trade and gives leverage on the remaining. This is the usual practice in India with most brokers. They never give leverage on portfolio level equity. Hence I am wondering how to include this scenario in the Amibroker backtest

Response to para 3: Yes, my code includes the following as i have mentioned it my first post:

SetPositionSize((riskpct/shortinitialslamt)*ShortPrice,spsPercentOfEquity);```

where:
riskpct is 2% of equity ie i am ready to risk 2% of equity on any trade (but i want to risk 2% of available cash on any trade)

shortinitialslamt is initial stop loss amount with out stop trailing

I have tried with the above code and compared with broker trade list. On any day, the  1st trade quantity matches with the quantity generated in the backtest, but for the subsequent trades, the quantity allowed by the broker is lesser than that of Amibroker backtester.

If AmiBroker does not have a built-in mechanism to specify position sizing based on a percentage of available cash, can you please guide me as to how to do it ?(ie position sizing based on available cash)

Is your broker allowing you to use 20x margin on the total position value, or on the capital at risk? When using risk-based position sizing, it's very easy to get total position values that are much larger than you expected, especially if your initial stop loss amount is small.

I think it would be helpful if you described in detail the calculation that your broker would use to determine your max position size for the second trade. So far, it seems to me that you're blurring the line between position value and value at risk, but maybe I'm just missing something.

If you do actually need to base your position size on available cash (although I'm not convinced that is the case yet), then you would need to write a Custom Back Test to do it. I would only recommend going that route if you have a solid programming background and reasonably good familiarity with how AmiBroker works.

Just a FYI. Keep in mind regardless of Asset Class, that initial margin requirements are set by the exchange and they have the right to adjust it during times of high volatility. Therefore, it is not a set and forget kind of thing. Also, maintenance margin can be a separate item as well.

As far as firms are concerned, they can set and adjust magin they want to their customers, but they too can adjust it at any time, or separate it out for non-overnight versus overnight held positions.

All-in-all margin is a moving target in the real world, but not so much in testing.
-S

The question pertains to intra day trading and in my code, all positions are squared off at 3:10 pm. No open positions over night, because my broker provides 20x leverage subject to following two conditions:

  1. Positions should be squared off (closed) before 3: 15 pm the same day. Overnight positions are not allowed.
  2. Stoploss amount should not be more than 1% of the entry price. Say I buy a share at Rs 100. Initial stoploss price should not be below 99.

If the above two conditions are satisfied, the maximum position size i can take is 20 times the available cash in my account just before a trade is entered.

The following may give an understanding of how broker determines the maximum allowable quantity of shares than can be bought(long) or sold(shorted) and quantity I enter based on risk based position sizing:

Before market starts, the funds I have in my account is Rs 5000.
9:15 am: Market started
10:10 am: Code gave a buy signal for ABC share with an entry price of Rs 100 with a a stop loss price of RS 99. The maximum no of shares that broker allows to buy considering 20x leverage is (500020/100)= 1000 shares. Say i would not like to lose more than 2% of available cash (ie 0.025000= Rs 100) on this trade if stop is hit. Therefore the no, of shares i would buy will be (2%5000/stoploss amount=0.025000/(100-99))=100 shares. Hence the position size for this trade is Rs 100 * 100 shares = Rs 10000. After the trade is executed, the cash balance in my account will be (5000-(10000/20))=Rs 4500 as broker will deduct only 5% of the position size from my account.

11.45: Position for ABC share is still open ie ABC shares are not sold off yet as target is not hit yet. Code gave another buy signal for XYZ share with an entry price of Rs 200 and stop loss price of Rs 198. The maximum no of shares that broker allows to buy considering 20x leverage is (450020/200)= 450 shares. Say I would not like to lose more than 2% of available cash (ie 0.024500= Rs 90) on this trade if stop is hit. Therefore the no, of shares I would buy will be (2%4500/stoploss amount=0.024500/(200-198))=45 shares. Hence the position size for this trade is Rs 200 * 45 shares = Rs 9000. After the trade is executed, the cash balance in my account will be (4500-(9000/20))=Rs 4050 as broker will deduct only 5% of the position size from my account.

Brokerage is also deducted, which i did not consider for sake of simplicity.Only two trades are considered for simplicity. Usually my code gives 6 to 8 trades in a day.

I wish the Amibroker backtester to do position sizing exactly the same way.

Any help please

The question pertains to intra day trading and in my code, all positions are squared off at 3:10 pm. No open positions over night, because my broker provides 20x leverage subject to following two conditions:

  1. Positions should be squared off (closed) before 3: 15 pm the same day. Overnight positions are not allowed.
  2. Stoploss amount should not be more than 1% of the entry price. Say I buy a share at Rs 100. Initial stoploss price should not be below 99.

If the above two conditions are satisfied, the maximum position size i can take is 20 times the available cash in my account just before a trade is entered.

The following may give an understanding of how broker determines the maximum allowable quantity of shares than can be bought(long) or sold(shorted) and quantity I enter based on risk based position sizing:

Before market starts, the funds I have in my account is Rs 5000.
9:15 am: Market started
10:10 am: Code gave a buy signal for ABC share with an entry price of Rs 100 with a a stop loss price of RS 99. The maximum no of shares that broker allows to buy considering 20x leverage is (5000 20/100)= 1000 shares. Say i would not like to lose more than 2% of available cash (ie 0.02 5000= Rs 100) on this trade if stop is hit. Therefore the no, of shares i would buy will be (2% 5000/stoploss amount=0.02 5000/(100-99))=100 shares. Hence the position size for this trade is Rs 100 * 100 shares = Rs 10000. After the trade is executed, the cash balance in my account will be (5000-(10000/20))=Rs 4500 as broker will deduct only 5% of the position size from my account.

11.45: Position for ABC share is still open ie ABC shares are not sold off yet as target is not hit yet. Code gave another buy signal for XYZ share with an entry price of Rs 200 and stop loss price of Rs 198. The maximum no of shares that broker allows to buy considering 20x leverage is (4500 20/200)= 450 shares. Say I would not like to lose more than 2% of available cash (ie 0.02 4500= Rs 90) on this trade if stop is hit. Therefore the no, of shares I would buy will be (2% 4500/stoploss amount=0.02 4500/(200-198))=45 shares. Hence the position size for this trade is Rs 200 * 45 shares = Rs 9000. After the trade is executed, the cash balance in my account will be (4500-(9000/20))=Rs 4050 as broker will deduct only 5% of the position size from my account.

Brokerage is also deducted, which i did not consider for sake of simplicity.Only two trades are considered for simplicity. Usually my code gives 6 to 8 trades in a day.

I wish the Amibroker backtester to do position sizing exactly the same way.

Any help please

For your second entry in symbol XYZ, the broker would allow you to purchase 450 shares. If you based your value at risk on 2% of Equity, you would buy ~50 shares (depending on what's happened with your ABC trade). If you base your risk on 2% of Cash, you would buy 45 shares. Both of these are well below the 450 shares allowed by your broker. Even if you bought 50 shares (Rs 10000 position value), you could open 10 trades before your broker stopped you from trading. So it appears that you're decreasing your position size with each trade based only on personal preference, not on broker requirements.

By the way, you may have noticed that when your stop loss is defined by a fixed percentage rather than a variable value like volatility / ATR, then risk-based position sizing actually simplifies to % of Equity (or % of Cash) position sizing. With the examples you gave above, your position value will always be 2x your available cash.

As I mentioned previously, if you want to size your positions based on cash rather than equity, then you will need to write your own CBT. As you can see in this post: Position sizing (equal % of equity), @Tomasz recently recommended the same thing to another forum member with the same question.

1 Like

Thanks, I would go through the linked post