I trying to do something fairly simple: before market day, select stocks to invest and place orders. On next day, review invested stocks, sell if needed or renew stop-loss orders.
What I see is:
- I select stocks in coarse selection
- Inside scheduled event, I placing orders
On next day, I not select any stocks since I already invested. For some reason, I getting event of “OnSecuritiesChanged" and all stocks which I placed orders for a day before - removed. This is unexpected since documentation says:
"When you remove an asset from a universe, LEAN usually removes the security from the Members collection and removes the security subscription. However, it won't remove the security in any of the following situations:
- You own the security.
- You have an open order for the security."
I do have open orders for all of these stocks - so why they removed?
Mia Alissi
To address the unexpected removal of securities from your universe despite having open orders, consider the following steps:
Ensure Order Status: Double-check the status of your orders. Make sure that they are indeed in a state that prevents removal, such as 'Submitted', 'PartiallyFilled', or 'Working'.
Time-in-Force (TIF) Setting: Verify the Time-in-Force (TIF) setting for your orders. If orders are set with a Daily TIF, they may expire at the end of the trading day, thus not existing as open orders in the logic for the next day.
Debugging and Logging: Implement extensive logging in your
on_securities_changed
method to understand the exact sequence of events. This could include timestamps, order statuses, and universe membership.Review Universe Logic: Ensure your universe selection logic correctly updates to reflect continued interest or orders in the assets.
Here’s an example of using the
on_securities_changed
method to debug and track changes:This method logs when securities are added or removed, helping you identify unexpected behavior regarding universe changes. Ensure that orders persist in a valid state and check if they might have been inadvertently canceled due to TIF settings or other logic.
Sources: Key Concepts - QuantConnect.com, Seasonality Effect Based On Same Calendar Month Returns, Event Handlers - QuantConnect.com, Key Concepts - QuantConnect.com, Head & Shoulders TA Pattern Detection
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.
Evgeni Aizikovich
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!