How can I have 2 different take profit levels for 1 position for example, when TP1 is hit it removes 50% of the order and moves StopLoss to TP1 Level while heading to TP2?
QUANTCONNECT COMMUNITY
How can I have 2 different take profit levels for 1 position for example, when TP1 is hit it removes 50% of the order and moves StopLoss to TP1 Level while heading to TP2?
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.
Varad Kabade
Hi Itumeleng Moreotlotlo,
We suggest creating a limit order at TP1 for half the quantity of assets currently in the portfolio to implement the above. When the limit order gets filled, we can create a Stop-limit order with Stop price as TP1 and limit price as TP2.
Refer to the attached backtest for reference.
Best,
Varad kabade
Itumeleng Moreotlotlo
Hi Varad kabade, can you please add comments on your code it does not make sense to me
Regards
Itumeleng
Varad Kabade
Hi Itumeleng Moreotlotlo,
In the attached algorithm, we have added a brief description and comments. Note that, unlike the previous algorithm, instead of using StopLimitOrder when TP1 is reached, we are putting two limit orders at TP1 and TP2, and after achieving TP1, we are putting a StopMarketOrder with stop loss as TP1. For further assistance regarding any code snippet, please post in this thread along with the code snippet. Refer to the attached backtest.
Best,
Varad Kabade
Itumeleng Moreotlotlo
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!