Liquidity limit hit, was: SetPositionSize

I am testing futures data which I have imported into Amibroker and I am having a weird problem where SetPositionSize does not work correctly but only for certain tickers.

I am using SetPositionSize(200000, spsValue); for all trades. I have set Account Margin to 10 so that 10x leverage is allowed and initial equity to 100000.

The weird thing is that the position size is set correctly for NQ but when I run the same backtest on CL with all the same settings, it uses all kinds of random position sizing as can be seen from the screenshots below. I have no idea why this is happening and would appreciate if anyone can help! :slight_smile:

Settings

NQ

CL

Your post lacks details, follow this advice: How to ask a good question

Use DETAILED LOG use advice given here: How do I debug my formula?

Never ever assume error in AmiBroker but ALWAYS in your coding, settings or understanding of AmiBroker.
Position sizes are not random.

If they are lower than requested it means they were shrunk DOWN because you have hit liquidity limit. It was covered many times on forum:

1 Like

Hello I figured out the solution, the problem was that my Settings > Portfolio > Limit trade size as a % of entry bar volume was set incorrectly. Once I changed that, it works as expected.

Please mark as solved.

@gambleditall you wrote that you are trading Futures but on your settings you have chosen not to tick the Futures mode box?
image

2 Likes

And @portfoliobuilder is right, for futures you should use Futures mode, detailed instructions here: Back testing systems for futures contracts not account margin, because account margin is for stock account.

1 Like

Yeah I am just doing some preliminary tests before using futures mode.

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