I am also setting position size in my code. I am using a single-position strategy, optimizing several variables. One of the variables I want to optimize is the number of positions. In other words, I set the portfolio cash size and then break that into multiple positions. The position size is determined from the number of positions, which is an optimization variable:
CODE:
Please log in to see this code.
In the Wealth Lab UI I set Position Size > Portfolio Simulation Mode > Wealth Script Override (SetShareSize), and I set the Starting Capital = 100,000 as in the code. This works fine during optimization. However, if I then set Preferred Values based on an optimization and then run with those PVs on a different time frame, I get messages saying that trades were not included due to insufficient capital. Since my code is using the same portfolio size as the UI ($100K) I am not clear how it can have insufficient capital, unless it is simply the portfolio losing money along the way due to losing trades.
In any case, what I want to do is run a full test, with all trades executed, based on the variable values from the optimization. Portfolio Mode does not seem to do this since it drops some trades. Raw Profit mode also does not seem to work because it uses the position size from the UI, whereas I want to use the position size that is calculated from the code above, based on the optimized number of positions (maxPositions), which is one of the PVs.
To clarify my ultimate objective, I am trying to optimize (among other things) how many increments to slice the investable cash into when trading a single symbol. E.g. given $10K, is it better to buy and sell in increments of $10K or e.g. N increments of size ($10K / N).
Any suggestions?
Thanks,
Ron