Say, I create MarketOrder, broker fills it and I have open position, I add Stop Loss and Take Profit orders.
How to find out that this position was closed and remove Stop Loss and Take Profit order?
P. S. I saw other subjects about SL / TP orders, like this one, but it doesn't answer my question
Jared Broad
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.
Artemiusgreat
I tried to describe possible scenario, maybe I just need to add more details.
Problem: Long position opened with SL / TP, then I open Short position of the same volume, result - positions compensate each other, so I don't have positions at all, but SL / TP orders are still active. OCO cancel orders, so OCO can detect when order gets filled / invalid / cancelled, but in my case initial market order will be closed by NEW UNRELATED POSITION. So, I need some mechanism to define connection between the first 3 orders (Market, SL, TP) and new order that will remove initial market order. Link in the post describes how to deal with 3 orders, it doesn't answer how to cancel existing orders when OCO relations are already defined.
Jing Wu
When you place a trade you receive an OrderTicket for you to access the order. This allows you to update and cancel the order like this
ticket.Cancel()
See this algorithm about order tickets
Artemiusgreat
Yes, I can call "Cancel" method. My question is, WHEN I should call it?
Second order is closing initial Long position, but I still have SL / TP active. OCO can define relation between Long / SL and TP, how to define relation between these orders and future Short order? All existing examples show how to connect 3 initial orders - Long / SL / TP, but once Long is filled it's not an order anymore, it's an open position that doesn't have any order status, so it's not clear when to close SL / TP.
Artemiusgreat
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!