I can't delete this post, but wanted to put a note in here acknowledging that I realized the error in my code. I was not using .Symbol in my two new scheduled events, causing them to fail. Once added back in, I was able to add multiple lines for multiple securities. Thanks!
I'd like to have my algorithm close all positions at the end of the day using the ode below. However, it seems to only work for single security objects and having duplicate schedules for individual securities does not seem to work. Am I able to modified this code so it doesn't just close out “SPY” positions, rather, it closes out all equity positions??
# schedule an event to fire every trading day for a security the
# time rule here tells it to fire 10 minutes before SPY's market close
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 0), self.EveryDayAfterMarketClose)
Dario Teodori
Hi James,
The easiest way I can think of is the following.
This will liquidate all positions in your portfolio by EOD
Fred Painchaud
Hi James,
There is also an event fired at the end of each trading day in QCAlgorithm:
It is called once, 10 minutes before close (so you can liquidate) for each invested asset (10 minutes before the close of the asset or end of day if asset trade 24/7).
Fred
James Hawkins
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!