How would I go about only selecting stocks from the top 50th percentile industries or sectors? I would like to adjust my strategies, and also compare with the reverse (selecting stocks from the bottom 50th percentile industries or sectors.

<< bad stocks in top performing industries will perform better than good stocks in poor performing industries >>

Hello, you didn’t specify the period. I’ll use 4 week return and I will use the screener. Here’s the public screen

There are two ways:

Using the cap-weighted Industry time series

FOrder("mktcap",#industry,#desc)=1 // returns largest stock in each industry (90 of them)
FOrder("close(0,#industry)/close(20,#industry)" , #all, #desc, TRUE) <= 45

The first rule screens for the largest stock by MktCap from each industry which returns 90 stocks. This tells me that there are 90 Industries in total. You can now disable this rule.

The next rule uses the Industry time series to calculate the 4 week return (latest value vs value 20 bars ago). It also uses FOrder to select the top 45 industries. The 4th parameter is very important since it bases the order on distinct values. See the reference for FOrder for more details

Using the pre-built Ind factors

There are 4 pre-bult Ind factors for performance (4w, 13w, 26w and 52w) that can be used, so it’s more limiting. In addition Ind factors are computed using Aggregate function which averages the statistic for the constituents after trimming 16.5% of the outliers. So it’s not the same as the cap-weighted time series above. For the 4 week use this Ind factor:

Forder("Pr4W%ChgInd" , #all, #desc, TRUE) <= 45

Let me know what you think.

NOTE1: you will not get exactly 1/2 the stocks of the universe because industries contain different number of stocks.
NOTE2: the two methods use different metric and will return different stocks also because of NOTE1