I can find lots of info on adjusting these if I do not use the algorithm framework. But if I am using the framework, how can I adjust these daily in AlphaModel.Update()?
I can get each stock I hold from QCAlgorithm.Portfolio and from that the SecurityHolding.Price. And from that I now know what I want for the new adjusted stop loss & limit order.
But how do I then set those? And first, get the existing values because I only want to adjust those up, never down.
Mak K
Hi Dave,
Just so we are on the same page, you are planning to adjust stop loss and profit target based on the price for each security, or am I misunderstanding you?
Â
Thanks!
David Thielen
Correct. Each day, as the price (hopefully) goes up, I want to adjust the stop loss to be 2% below the new close price. And for the limit order, it's a bit more complicated calculation, but same thing, a new value based on the day's close.
thanks
Mak K
Sounds like you might want to use a trailing stop for this, how does that sound to you? It is available in the algorithm framework already
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Framework/Risk/TrailingStopRiskManagementModel.py
For the profit target I don't think there is a ready made model for what you are trying to do but I would bet the trailing stop model could be duplicated and changed to function as a recalculating profit target aswell, but would need more details on what exactly you are trying to do for that.
Also please shoot any question that you have about this and I will answer to the best of my ability, thanks!
David Thielen
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!