5 day high

I am having trouble with something that should be very simple. Could someone suggest an expression to screen for- stocks whose high in the last five days equal or exceed the 52 week high.

Unfortunately Hi(-1) is most you can look back.

The high in the last 5 days can’t exceed the high of the last 52 weeks because the last 52 weeks includes the last 5 days.

But if what you want is stocks whose high in the last 5 days exceeds the high of the (last 52 weeks + 5 days but not counting the most recent 5 days), that would look something like this (I think): HighVal(5,0,#high) >= HighVal(260,5,#high)

Adjust 260 for however many days you think are in 52 trading weeks (some people use 251 or 252)

If you’re looking for whether the 52 week high occurred within the last five bars, I think this should work;

HighValBar(#Year, 0)<=5

Walter

try HighVal(5)>=PriceH

It needs to be >=

You nailed it. I had a mental block about the last 5 days are included in the last 52 weeks. Thanks so much.

Thanks everyone learned something new.

How would you do Hi(-1)>Hi(-2) and Hi(-2)>Hi(-3)

Regards,
Mark V.

Hi Mark,

What do you want to do? Neg numbers look into the future.

Walter

Thanks Walter my mind was a little foggy with looking back and looking forward I get them mixed up often.

What I was trying to ask is it possible to look back 1-n days without hard coding like the following:

hi(0) > hi(1) AND hi(1) > hi(2)

Can you screen for stocks that have had consecutive highs for as many days as you want?

Thanks again,
MV

MV - see this screen: https://www.portfolio123.com/app/screen/summary/161534?mt=1

It is set to look back 5 days but you can go back to 50 days.

Steve

The Loop functions now support up to 100 iterations.

Walter

I hope my comment is not off topic too much but I wish to express the opinion that P123 still lacks one or two major functions that it sort of takes a stab at with the aforementioned HighValBar function but which could be so much more powerful with slight modification.

The HighValBar function returns the number of bars since the last high over a given period. That kind of function could be much more powerful if instead of being restricted to finding the highest bar it could be opened up to user-defined condition such as the one found in the LoopSum function. LoopSum counts the number of times a user-defined condition occurs over a given period. Getting the number of bars since the last time a user-defined condition occurred is just as useful.

Thanks Everyone,

Extended functionality has been added to the LoopSum and company; if you specify the 6th parameter (break) as TRUE, you can exit the loop if the formula becomes N/A, and the result of the loop function will be over all valid values before N/A. noNAs is ignored, when break is specified.
E.g., to count the number of days prior to today in which a stock had a non-negative daily return:
ShowVar(@c, LoopSum(“Eval(Close(CTR)<Close(CTR + 1), NA, 1)”, 21, 0, 1, FALSE, TRUE))

If the Loop function supports up to 100 iterations the help file should be updated to reflect that.