Hi, I have a problem in implementing take profit orders, but under condition that limit order has been already filled. Also have some troubles in canceling take profit and stoplosses after the other got filled. I have tried few methods I have seen on forum, but didnt really succeed.
Mia Alissi
From the provided code, it seems like you are trying to implement a trading strategy where you place a limit order to enter a position and then place a stop market order as a stop loss. However, I noticed that you are not implementing a take profit order after your limit order gets filled.
To implement a take profit order, you can use the
LimitOrder
function again with a higher price for a long position or a lower price for a short position. This order will get executed when the price reaches the specified level, thus securing your profit.Also, you mentioned that you are having trouble canceling the take profit and stop loss orders after one gets filled. To achieve this, you can use the
OrderTicket
objects returned by the order functions (LimitOrder
,StopMarketOrder
, etc.) and theOrderTicket.Cancel()
method.You can store the
OrderTicket
objects of your stop loss and take profit orders in instance variables and then in theOnOrderEvent
method, check if one of them gets filled. If it does, you can cancel the other one.Here is a simplified example based on the information provided:
Please replace the placeholders with your actual trading logic and values. This is a basic example and might need adjustments based on your specific needs.
For more information, you can refer to the following sources:
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.
Warmi
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!