Hello my beloved community, 

I need serious help that may be easy for someone moderately well endowed in Python to help me out with. I am a beginner who is new to universe selection and doesn't understand classes very well. 

Questions - I have no idea to how to make OnData, Consolidated functions, Scheduled events, inclusive to my universe that is changing every day with a different amount of symbols potentially each day. I am very new 

Strategy - I want this algorithm to filter by volume, and then by which of those stocks have had earnings report recently, then some sort of buy logic. 

Buy Logic - The buy logic contains a consolidated data function where two variables are assigned every day.  The OnData method is going to check price every minute relative to the two variables declared shortly after market open

Here is the code just in case it does not show up without a backtest attached. 

#region imports
from AlgorithmImports import *
class EarningsORB(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2023, 2, 2)
self.SetEndDate(2023, 2, 5)

# Scheduled events
self.Schedule.On(self.DateRules.EveryDay(),self.TimeRules.AfterMarketOpen(60), self.RangeToggle)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen(), self.UpdateUniverse)

# Universe Selection
self.volumeBySymbol = {}
self.symbols = []

# Toggles
self.range_toggle = False

# Consolidated data
# Sixty Min Bars
sixty_min_consolidator = TradeBarConsolidator(timedelta(minutes=60))
self.SubscriptionManager.AddConsolidator(self.symbol.Symbol, sixty_min_consolidator)
sixty_min_consolidator.DataConsolidated += self.OnSixtyMinBar
self.sixtyMinBarWindow = RollingWindow[TradeBar](1)

def MyCoarseFilterFunction(self, coarse):
# Price above 10 and dollar volume above 10mil
filtered = [ x for x in coarse if x.Price > 10 and x.DollarVolume > 10000000 ]

# Adds to VolumeBySymbol Dictionary
for x in filtered:
if x.Symbol not in self.volumeBySymbol:
self.volumeBySymbol[x.Symbol] = SymbolData(x.Symbol, self)
self.volumeBySymbol[x.Symbol].Update(x.EndTime, x.Volume)

# Filter based on recent earnings report - This is where the filter logic would go, this is example code, it is not correct
# Maybe this is where the 'estimize' code is supposed to go?
self.symbols = []
for symbol in self.volumeBySymbol.keys():
last_report_date = self.Fundamentals.GetLastReport(symbol).ReportDate
if (self.Time - last_report_date).days <= 1: # Only include symbols with earnings report in the last day

# Log
symbol_strings = [str(symbol.Value) for symbol in self.symbols]
self.Log(f"Symbols with recent earnings reports: {symbol_strings}")

return self.symbols

# Scheduled events
def UpdateUniverse(self):
# Refresh universe

def RangeToggle(self):
self.range_toggle = True

# Consolidated Data
def OnSixtyMinBar(self, sender, bar):
if not self.sixtyMinBarWindow.IsReady:

trigger_bar = self.sixtyMinBarWindow[0]

if self.range:
self.trigger_sixty_min_open = trigger_bar.Open
self.trigger_sixty_min_close = trigger_bar.Close

self.range = False

# Buy Logic
def OnData(self, data):
# Check buy criteria every minute
for symbol in self.symbols:
# Enter long when it crosses sixty min high
if self.Securities[symbol].Price > self.trigger_sixty_min_close[symbol]: # am i supposed to add [symbol] there? Do i add [symbol] anywhere else? Like in the consolidated data function?
self.SetHoldings(symbol, 1 / len(self.symbols))

# Symbol Data class
class SymbolData:
def __init__(self, symbol, algo):
self.algo = algo
self.symbol = symbol
self.sma = SimpleMovingAverage(30)
history = algo.History(symbol, 30, Resolution.Daily)
if not history.empty:
for time, row in history.loc[symbol].iterrows():
self.sma.Update(time, row['volume'])

def Update(self, time, vol):
self.sma.Update(time, vol)


Thank you for taking the time to read this and maybe help me out as usual.