I tried using the DateTime constructor and passing algorithm.Time date values plus the hour and minute values for right before close but that didn't work, got messages saying the date was in the past.
QUANTCONNECT COMMUNITY
I tried using the DateTime constructor and passing algorithm.Time date values plus the hour and minute values for right before close but that didn't work, got messages saying the date was in the past.
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.
Rahul Chowdhury
Hey Fabien,
We can create insights with specific expiration DateTimes. We can set our insights to expire at 2 minutes before market close, so that our algorithm can submit liquidate targets at 3:59 PM.
var now = algorithm.Time; // close insight 2 minutes before market close var nextClose = algorithm.Securities[symbol].Exchange.Hours.GetNextMarketClose(algorithm.Time, false).AddMinutes(-2); var insight = Insight.Price(symbol, close, InsightDirection.Up);
I've attached a simple example of this in action. In the example, I also restricted the algorithm to create insights for a symbol only if that symbol hasn't yet been invested in and to not create insights if the current time is after 3:58 PM.
Best
Rahul
Fabien
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!