# of new 99-day highs on a series?

I’ve written this rule:

ShowVar(@Cnt,LoopSum(“Hi(CTR) >= HighVal(99, CTR, #High)”, 99))

…to count the number of new 99-day highs in the last 99 days of the stocks I’m screening.

I’d also like to know if SPY has hit any new 99-day highs within the past 99 days. It looks like I can convert the first reference to:

Hi(CTR, GetSeries(“SPY”))

…but I can’t figure out how to replace #High with the high values of SPY using GetSeries. Or do I need to use a different function?

Or do I need to use closing prices instead?

I’m lost.

Randy - first create a custom formula $SPY = GetSeries(“SPY”)

Then your rule is:

ShowVar(@Cnt,LoopSum(“Hi(CTR) >= HighVal(99, CTR, $SPY)”, 99))

I suggest changing your rule to:

ShowVar(@Cnt,LoopSum(“Hi(CTR) > HighVal(99, CTR+1, $SPY)”, 99))

Steve

Your formula still has the same problem I was trying to resolve – getting HighVal() to get the highest high price from the $SPY vectors. As you have it, it will get the highest closing price of $SPY.

Is there a way to get the series of high prices from $SPY?

P.S. In your formula, Hi(CTR) would need to be Hi(CTR, $SPY).

Randy - you are right on both counts. Here is something that MAY work but is extremely slow and P123 may not appreciate people doing this :slight_smile:

Change the custom formula to: $SPY = LoopMax(“BenchHi(CTR+1)”,99)

Set the benchmark to SPDR S&P 500 ETF Trust

The rule is:

ShowVar(@Cnt,LoopSum(“BenchHi(CTR) > $SPY”, 99))

At least it doesn’t give an error. I suspect the loop inside the loop will be a problem with both using CTR as a variable.

Use of BenchHi may give you some ideas. Also I suggest that you raise a feature request to allow use of BenchHi / BenchLo in custom series. Right now, only BenchClose is supported. Either that or allow an ETF custom universe within a custom series. Use of a custom series should solve this problem.

Steve

Randy - Ignore the above post using a loop within a loop. I just figured out a brute force approach that works (I think). It isn’t pretty. But it is fast.

Copy the following eleven custom formulas:

https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53514&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53515&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53516&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53517&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53518&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53519&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53520&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53521&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53522&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53523&s=1
https://www.portfolio123.com/user_formula_edit.jsp?formulaid=53524&s=1

Then use this screen:

https://www.portfolio123.com/app/screen/summary/165996?st=0&mt=9

This appears to work. I am assuming that putting CTR in the custom formula isn’t causing any issues.

Steve

Thanks!