Margin Function is working just fine

I am trying to backtest a trading system in which the position size depends on the present account balance. I am using the following:

SetPositionSize(100,spsPercentOfEquity)

This is working fine by itself.
But I want to have a margin requirement of 15% for which I am using the following

SetOption("AccountMargin", 15 )

This function is also working fine by itself but when I use the above two functions together, the backtest result does not take margin into consideration. It is only trading the amount of stock which can be traded with total equity without considering the margin. Please help.

Again - assumptions instead of reading the docs. It works just fine as documented, not as "assumed". In the users guide https://www.amibroker.com/guide/w_settings.html
we can read that it increases BUYING POWER (ability to open positions). It does NOT say a word that it is changing your equity. Money borrowed from brokerage are NOT yours. So 100% equity refers to your money, not brokerage's money. And if you want to use buying power 2x of your money you need to write

SetPositionSize( 200, spsPercentOfEquity ); // twice MY money
3 Likes