@Ciaran Y., A method that you might employ that would simplify your processing is to use the X__ ETFs as proxies to your S&P500 sectors. Follow those and then when the time is ripe, according to your algorithm, sample out of the components of those ETFs a set of securities you'd like to trade.
The primary limitation to this, and to your strategy in general, is that you have a limited number of securities you can work with, 200 in fact. There are ways around this that may or may not work but in general, you may want to just stick with that number to start. So, your first step would be to select N number of components from each ETF from this list: "XLB","XLE","XLF","XLI","XLK","XLP","XLU","XLV","XLY".
There are other sector based ETFs but those are common and proven. Research each one selecting say, 20, securities from each. (For the remaining 20 (9 x 20 = 180) of the maximum 200 you could select a list of treasury and or commodity type ETFs, i.e. GLD, SLV,TLT,AGG...) Setup an array for each sector ETF and add symbols(...) to each.
Now you have your super groups based on the ETFs which you can use as your primary logic drivers. And you have the sub groups, the securities within each ETF, you can use as your trading vehicles.
No doubt there are holes in this blanket strategy, legs come and go within ETFs; a biased 20 picked from each sector, 200 is not 500, etc. But, given the restrictions imposed here by the Q's platform, I'd posit that this proposed technique would get you ~75% of the way there.