Hello Community,
I am trying to schedule a boolean function daily containing a certain condition, that if fulfilled, the OnData function will fire and do some work, otherwise I will wait for the firing of the scheduled function the next day. However, I am facing many weird problems:
1) In my log file, I am witnessing many SKIPPED days:
2013-10-11 00:00:00 Yesterday Close is: 1.349315 2013-10-11 00:00:00 The Close before yesterday is: 1.35674 2013-10-11 01:00:00 Test returned false 2013-10-17 01:00:00 Yesterday Close is: 1.35136 2013-10-17 01:00:00 The Close before yesterday is: 1.3567 2013-10-17 01:00:00 Test returned false 2013-10-22 01:00:00 Yesterday Close is: 1.367605 Why is there so many skipped days although I have scheduled the function to run daily? 2) The condition is not being fulfilled correctly; the OnData function is not firing when I want it to be fired, that is when test function is True. What is the reason behind that?def Initialize(self):
self.SetStartDate(2013,10, 11) #Set Start Date
self.SetEndDate(2013,11,11) #Set End Date
self.SetCash(10000) #Set Strategy Cash
self.AddForex("EURUSD", Resolution.Daily)
self.Schedule.On(self.DateRules.EveryDay(),self.TimeRules.At(00, 00),self.test)
def OnData(self, data):
if(self.test()):
self.Debug("We are in OnData, and test returned true")
else:
self.Debug("Test returned false")
def test(self):
eur_hist = self.History(['EURUSD'],2,Resolution.Daily)
if (eur_hist.loc['EURUSD']['close'][0] > eur_hist.loc['EURUSD']['close'][-1]):
self.Debug("Yesterday Close is: " + str(eur_hist.loc['EURUSD']['close'][-1]))
self.Debug("The Close before yesterday is: " + str(eur_hist.loc['EURUSD']['close'][0]))
return True
return False
3) I had an "Index out of bounds" error when I put ['EURUSD']['close'][1] and had to change it to -1 for it to work. Why is that?
Thanks in advance,
Best Regards.
Alexandre Catarino
I did a little test to assert the scheduled event is fired every day:
# In Initialize self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(00, 00), self.test2) def test2(self): self.Log(str(self.Time))
and I verified it was fired every day.
Lean does not log repeated messages.
In this case, when test() returns False multiple times, we will only read "Test returned false" once.
Finally, "index is out of bounds" because the historical data has only returned one data point. I would advise you to ask for more data point (5 instead of 2) and use the last two.
Lord Odin
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!