Count of number of highs within a period

This has been asked in the past without success but not in over 15 years, so I’m wondering if it has become possible.

To give a simple example of what I’m looking for: Would it be possible to create a ranking function based on the number of 52-week highs a stock has made over the last 52-weeks?

See the “52W #Hi” column on this page to help understand what I’m looking for: All US Exchanges 52-Week New highs - Barchart.com

This should count the number of new daily high bars over the past year. Doing weekly would be harder.

LoopSum("HighValBar(252-CTR,CTR)=CTR",252,0)
1 Like

That’s great. Thanks. And a quick follow up. What if I wanted to add a rule (I guess to the strategy that this ranking function is used with) that would require the count to be greater than a certain value?

If the certain value is 50, for example;
LoopSum(“HighValBar(252-CTR,CTR)=CTR”,252,0)>50

Also, make sure there are at least 252 bars available. I’m not sure what happens if fewer bars exist.

1 Like