Hello,

I'm trying to get some code to run once a day that checks a bunch of pairs and then trades if certain conditions are met (I've presented the key parts to this below).

My issue is that when I run my code I get the output also shown below - as you can see it looks like it's being executed on the same day over and over. Any ideas where I could have gone so wrong?

 

6652 | 19:32:58: 2018-01-03 13:00:006653 | 19:32:58: 100 of 5006654 | 19:32:58: 200 of 5006655 | 19:32:58: 300 of 5006656 | 19:32:58: 400 of 5006657 | 19:32:58: 500 of 5006658 | 19:32:58: New Day6659 | 19:32:58: 2018-01-03 13:00:006660 | 19:32:58: 100 of 5006661 | 19:32:58: 200 of 5006662 | 19:32:58: 300 of 5006663 | 19:32:58: 400 of 5006664 | 19:32:58: 500 of 5006665 | 19:32:58: New Day6666 | 19:32:58: 2018-01-03 13:00:006667 | 19:32:58: 100 of 5006668 | 19:32:58: 200 of 5006669 | 19:32:58: 300 of 5006670 | 19:32:58: 400 of 5006671 | 19:32:58: 500 of 5006672 | 19:32:58: New Day6673 | 19:32:58: 2018-01-03 13:00:006674 | 19:32:58: 100 of 5006675 | 19:32:58: 200 of 5006676 | 19:32:58: 300 of 5006677 | 19:32:58: 400 of 5006678 | 19:32:58: 500 of 5006679 | 19:32:58: New Day6680 | 19:32:58: 2018-01-03 13:00:006681 | 19:32:58: 100 of 5006682 | 19:32:58: 200 of 5006683 | 19:32:58: 300 of 5006684 | 19:32:58: 400 of 5006685 | 19:32:58: 500 of 5006686 | 19:32:58: New Day6687 | 19:32:58: 2018-01-03 13:00:006688 | 19:32:58: 100 of 5006689 | 19:32:58: 200 of 5006690 | 19:32:58: 300 of 5006691 | 19:32:58: 400 of 5006692 | 19:32:58: 500 of 500

 

 

class PairsTradingAlgorithm(QCAlgorithm): def Initialize(self): ---some parameter stuff here not shown---- tickers = list(set(tickers)) self.symbols = [] for i in tickers: self.symbols.append(self.AddEquity(i,Resolution.Daily).Symbol) self.day_run = self.daily_run self.SetStartDate(2018,1,1) self.SetEndDate(2019,6,30) self.lastSlice = None self.pairs_list = pairs[0:500] def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data''' self.lastSlice = data scheduled_function = self.day_run self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(13, 0), Action(scheduled_function)) def daily_run(self): data = self.lastSlice if data != None: self.Debug('New Day') self.Debug(str(self.Time)) run = 0 count = 0 for pair in self.pairs_list: run += 1 count += 1 if count == 100: self.Debug(str(run) + ' of ' + str(len(self.pairs_list))) count = 0 if not (data.ContainsKey(pair[0]) and data.ContainsKey(pair[1])): return ### need to check this is the last 60 days price_x = self.History([pair[0]], 60)['close'].values price_y = self.History([pair[1]], 60)['close'].values if len(price_x) < 60: return ------------Some trading logic ---------------

 

Author