Increase portfolio position size depending on the open risk

If possible I would like to code a strategy which runs on a portfolio of stocks with a trailing stop.
I would like to increase the max position size if a stock is out of the risk. I mean by that if the trailing stop is higher as the entry price. With a dynamic max position size depending on the portfolio open risk.

Is this somehow possible?

Thank you

For solution, see this:

and this:

I believe that there is a final closing curly brace missing in the code on this page:

Also, I am very interested in rebalancing portfolios. For example, suppose I had ten stocks in a portfolio, $10,000 spent on each for a port value of $100,000, Now one doubles, the new portfolio value is $110,000. I would like to automatically rebalance to equal weights, 10 $11,000 positions. Is using the CBT as described there still the recommended procedure?

As usual, a tip of the hat to all!

 John

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