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
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: http://www.amibroker.com/kb/2014/11/10/troubleshooting-procedure-when-backtest-shows-no-trades/
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:
PositionSize defined in formula is taken, then
Per-bar volume limit is applied (as defined in the Settings)
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:
Hi Tomasz,
Can I suggest some users would find this useful to control via code? AB seems to default this value to non-zero, and it's one of those things that if it gets set wrong and the user forgets - it can go unnoticed for a long time (or it did with me!) . I like to make sure everything is set in the code to avoid surprises. Cheers,
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.
I just realized the real danger is that every time I open a new analysis window it goes back to default setting? Other things, like commissions remain the same once set, shouldn't this param be the same?
Sorry, although I saw the value reset in the past, now it does seem to stay at "0" if I set it there. Still, would be great to control from code. Cheers,
No it doesn't go to default. The Analysis Project (APX) stores ALL settings (from "Settings" dialog) and when you load analysis project ALL settings are loaded as they were set when project was saved. So there is NO problem and NOTHING to worry about. Just set the settings and save the Analysis project the way you want.
If i use analysis window without saving it, then on the next run, whatever settings i used last seem to be retained.
It doesn't go to any sort of default. so i think all these settings are also stored in the registry maybe ?
@ezekiel I don't think the Analysis goes to default as in like fresh installation.
You are not saving project file. So you are doing exact opposite from what I wrote.
If you don't save project file then obviously what you set in the settings is held and used for new Analysis windows because otherwise you would need to re-do all changes all the time whenever you create new Analysis.