Hi guys,
Sorry to raise this, but I couldn't find appropriate example within existing topics. I've got the idea that in order to track stop-loss order there is need to save ticket at the class level. However, I am wondering what's the best approach to group order with the stop-loss order? This especially makes sense when there are multiple orders opened by algorithm. Is it good to use tags in this case? I have defined a separate class which holds initial ticket. When it's filled I am attaching stop-order ticket. Please take a look at the code and let me know what do you think and how you group
Derek Melchin
Hi Nikolay,
This implementation looks reasonable. To simplify things, we could remove the OrderWithStopLoss class and just make _orders map from the market order OrderTicket to the stop loss OrderTicket.
Also note that in the current implementation, since it uses daily data, the stop loss order is submitted 1 trading day after the initial market is submitted.
Best,
Derek Melchin
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.
Nikolay Zdravkov
Thank you for you time Derek.
How in your opinion then stopMarket orders should be submitted? Will firing event at 14:00-16:00 to rebalance portfolio will be better rather than using OnData? Will switching to a hourly resolution would be better overall for testing algorithm? I am sorry if I am asking dumb questions, quite new in the algorithmic trading.
Louis Szeto
Hi Nikolay
Since the Stop order is submitted after the primary order was filled, it would essentially delayed for one day (1-bar) as the order can only be filled by that time. If you would like to reduce the delay, you could consider using a denser resolution like minute resolution.
Best
Louis
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.
Nikolay Zdravkov
Thank you guys,
Couple of comments if you will be reviewing. Not sure if I've done right the map for entryOrder/stopLossOrder. There is implicit conversion of OrderTicket to int (OrderId), but not vice-versa, as of this I have to loop through the dictionary, which doesn't seems to be right. I've added OrderTicketEqualityComparer, which compares OrderTickets by OrderId
Switching to smaller resolution seems helped. However, seems I am not getting Filled event, as I see only see one log entry on the same day,
I understand that with a big probability RSI doesn't work alone, and it won't be profitable to trade the SPY with it. However, this is more to learn the basic stuff and write in my own a simple algorithm, while getting in touch with QuantConnect and Lean. If you have a “production-like” examples, this would really help. As for example I am not covering partial-fillings at all at the moment.
Louis Szeto
Hi Nikolay
Sorry for the delay. You can use Transactions.GetOrderTicket(orderId) to retrive the original order ticket. For example algorithms, you may visit our GH repo to have a look, although not all are profitable.
Best
Louis
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.
Nikolay Zdravkov
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!