I have some trouble with the event scheduling system. Im trying to fire 3 events in a specific order but it doenst work.
( I have inserted a "test"-variable to show the problem)
self.test = 0
self.Schedule.On(self.DateRules.EveryDay("AAPL"), self.TimeRules.At(9, 25), self.BeforeOpen)
self.Schedule.On(self.DateRules.EveryDay("AAPL"), self.TimeRules.BeforeMarketClose("AAPL", 5), self.BeforeClose)
self.Schedule.On(self.DateRules.EveryDay("AAPL"), self.TimeRules.At(16, 5), self.AfterClose)
def BeforeOpen(self):
self.Debug(str(self.Time) + " before open // Test value: {} (expected to be 0)".format(self.test))
self.test = 1
def BeforeClose(self):
self.Debug(str(self.Time) + " before close // Test value: {} (expected to be 1)".format(self.test))
self.test = 2
def AfterClose(self):
self.Debug(str(self.Time) + " after close // Test value: {} (expected to be 2)".format(self.test)) # expected to be 2
self.test = 0 # reset the variable after market close
The result is:
https://i.imgur.com/EPyjuVO.png
As u can see the dates and the value of the test-variable get mixed up. Is there a way to fix this?
Rahul Chowdhury
Hey Paul,
Thank you for your bug report. We've created a github issue, which you can follow here.
If you dont mind having data from extended hours, there is a solution to make your algorithm work as expected.
You can enable extend market hours data by setting the extendMarketHours parameter to True in AddEquity.
AddEquity(ticker, resolution = Resolution.Minute, market = Market.USA, fillDataForward = true, leverage = 0m, extendedMarketHours = false)
Since named parameters are currently not supported for python algorithms on QC, you need to fill in the values for all the parameters.
self.AddEquity("AAPL", Resolution.Minute, Market.USA, True, 0, True)
Paul N. Lee
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!