Goal: Create a scheduled event to liquidate all positions for a set of symbols 30 minutes before market close. (This set of symbols is found using a dynamic universe from coarse and fine filters.)

Intuitively, I know the event scheduler should be called once which has a method loop through each symbol to liquate the position. I'm struggling with this because of the single symbol callout in the BeforeMarketClose example which always use SPY and not a ‘symbol’ variable. 

Below is an example I found on the discussion forum for a single stock, so I figure it'll take a similar form for an algorithm with a set of symbols. 

Lastly, does the scheduled event belong in Initialize or somewhere else?

# In Initialize
# This defines a scheduled event which fires self.ClosePositions everyday SPY is trading 1 minute before SPY stops trading
self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 1), self.ClosePositions)

def ClosePositions(self):        
    if self.Portfolio.Invested:
        self.Liquidate()

Author