So you want to optimize position size? Try virtual hedging. On every run, exit your position and enter long or short your desired position size. At the end of the run, you will be placed at the desired position.
https://manual.zorro-project.com/hedge.htm