Requested size is less than MinShares

Tags: #<Tag:0x00007f2d7e5d5f68> #<Tag:0x00007f2d7e5d5b30>


Hello! First post so go easy.
I’m not sure if this post should go here or in the ‘.afl programming’ section but here goes.

In my backtest report I am getting the the following error:
‘xxx not entered because the requested size is less than MinShares/MinPosValue’.

I have set MinShares to 1 and MinPosValue to 500. I don’t know what the requested size is but I’ve setup some backtesting parameters as follows:

InitEquity = Param("Initial Capital", 25000, 10000, 1000000, 5000);
MaxPos = 20;
Tradesize = InitEquity/MaxPos;
SetOption("InitialEquity", InitEquity);
SetOption("MaxOpenPositions", MaxPos);
SetOption("MinShares", 1);
SetOption("MinPosValue", 500);
PosType = -1;
PosType = ParamToggle("Compounded?", "Not Compounded|Compounded", 1);
if( PosType == 0)
	SetPositionSize(Tradesize, spsValue);
if (PosType == 1)

This happens several times throughout the detailed backtest report. In fact, often the system does not open any more positions. I would understand if the cash available was low (less than $500 if most positions are open). However, I’ve seen times when, while the cash amount is less than the initial equity, it is still large enough to handle the requested entry. For example, I’ve seen this error happen when there is 22K in cash/equity (init equity = 25K). Position sizing is based on 5% of equity. Allowing Position size shrinking doesn’t make a difference.

The only pattern I can see is that it happens when the account is much less than the initial equity. How does this effect position sizing?

I feel like I’m missing something simple. I’ll have to give myself a smack on the back of the head when I find out.


The program clearly tells you already everything. You have requested position size that is smaller than MinShares/MinPosValue. It is not about cash. It is about constraints that you have activated yourself. Remove / comment-out constraints that you have put

//SetOption("MinShares", 1); // remove
//SetOption("MinPosValue", 500); // remove

and it will enter this trade.

Keep in mind that you might have also round lot size set in the Settings and that might play the role too. For example, if you have set round lot size = 100, then if you wanted to buy 5% of equity of 20K equity that would be $1000, but if stock price is $15 what would be 66 shares and that rounded to 100 (round lot size) gives 0 (zero) shares (round lot sizing always rounds DOWN).

The other factor is described in the Knowledge Base article here:
The program by default prevents from taking trade that is larger than 10% of market volume for given stock at given bar (see the article). Check your data. Your data may be limiting the trade size below limit you have defined.

It goes like this:

  1. PositionSize defined in formula is taken, then
  2. Per-bar volume limit is applied (as defined in the Settings)
  3. Round Lot Sizing applied (as defined in the Settings)

Resulting value is “requested position size” and it is checked against constraints (MinPosValue/MinShares).

If you don’t understand your own code you need to add _TRACE and/or AddColumn to get insight into what is happening in your code:


@Tomasz How to set the per-bar volume limit programmatically without using the GUI?


It is GUI-only option. But when you save project into APX file all settings are stored.


Thanks Tomasz. Thanks for the explanation. I’ll try your suggestions.