Hi,
I am trying to set a stop loss and take profit for a market order:
OrderTicket orderTicket = MarketOrder(_ticker, quantity);
if (orderTicket.Status == OrderStatus.Filled) {
// set stop loss
decimal stopLoss = StopLoss(_price);
OrderTicket stopLossTicket = StopMarketOrder(_ticker, -quantity, stopLoss);
_orders.Add(stopLossTicket);
// set take profit
decimal takeProfit = TakeProfit(_price);
OrderTicket takeProfitTicket = LimitOrder(_ticker, -quantity, takeProfit);
_orders.Add(takeProfitTicket);
}
But the second pending order is always invalid. I guess I can only enter a position for a quantity that i actually have? So as a solution I will enter one position (for example stop loss) and handle the other one manually in code. Is there some other better solution to handle stop loss and take profit?
Thanks
Michael Manus
search in the forum, you will find some stuff:
https://www.quantconnect.com/forum/discussion/1700/support-for-one-cancels-the-other-order-oco
https://www.quantconnect.com/forum/discussion/799/strategy-opening-range-breakout/p1Simon Nebesky
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!