Finding first Close above 52week highest

Hi Guys,
can someone help please? I am trying to explore to find the stock , which close is above the 52week hightest. But I want to find that it is the first close above the 52week highest high, not the subsequent hightest high.

Something like below could allow you identify new breakout closing highs across a list of securities.

LengthNeeded = Param("LengthNeeded",50,1,252,1); //How many days do you need the basing period to be?
base = BarsSince(Close==HHV(Close,252));
freshHigh = Close == HHV(Close,252) AND Ref(base,-1) >= LengthNeeded;

Filter = freshHigh;

If you want to look for new intraday highs instead, just replace all "Close" with "High" in the code.

1 Like

HI Qedges,

Can you please explain the code? I am trying to follow it and not understanding it?

Thank you for your help.

Explanation lines are in code below:

LengthNeeded = Param("LengthNeeded",50,1,252,1);
base = BarsSince(Close==HHV(Close,252));  //how long has is been since the last 252-day high?
freshHigh = Close == HHV(Close,252) AND Ref(base,-1) >= LengthNeeded; //today is a 252-day high AND yesterday the it had been at least 50 day since the last 252 day high

Filter = freshHigh;

Perhaps easiest way to fully understand code like this would be to run an exploration on all the arrays. So change the explore to something like below and then run it for a longer period on just 1 security to see what is happening.

Filter = 1;
AddColumn(Ref(base,-1) >= LengthNeeded,"Ref(base,-1) >= LengthNeeded");

Thank you QEdges. Now I understand clearly. Thank again for your kind explanation.

Hi QEdges,

One more question if you don't mind please. Why Param() function was used ? Why not just LengthNeeded = 50 or something like that?

You can use LengthNeeded = 50; as well. Param() is just optional feature allowing to change the values from GUI instead of code.

Thanks for pointing out Tomasz. And Thank you for the amazing software

Hi All,

I'm interested in progressing this topic of finding first close above the x-period highest high value. Leon Wilson in his book "Break Through Trading " delivered a well-explained section in Chapter 8 on initial 21-week highs and effectively turned this concept into an indicator he used to determine what was considered a reasonable entry trigger.

Continuing, he states "In order for the initial high indicator to re-plot above price action, price action must first experience 20 consecutive weeks of lower highs than the high of 21 weeks ago. This must occur in order to identify the first new high."

The basic rules that determine how the indicator plots are as follows:

  • The indicator can only plot above declining price action.
  • The indicator will only re-plot once declining price action over a 20-week period is less than the high of 21 weeks ago.

The indicator effectively references two periods in trend development simultaneously, as follows:

  • The indicator references a prominent high, which in this case is 21 periods ago. It uses this position as the starting position for future reference in regard to declining price action.
  • It also references the ensuing 20 weeks of price action following the prominent high, ensuring that the 20 weeks of subsequent price action is lower than the prominent high.

Only when the above criteria are met will the indicator plot above declining price action.
(The following image shows periodicity in days not weeks as described above.)


Based on the above discussion, I've attempted to convert the two conditions above into AFL code using a nested IIF statement as follows , however I am stuck on the part of referencing the "PREV" value (for the 2nd nested "true" statement:

IIf(Ref(HHV(Close,21),-1) >= HHV(Close,21), HHV(Close,21),IIf(Ref(HHV(Close,21),-1)<HHV(Close,21),PREV,0));

Is someone able to assist me in converting the above into an indicator as described in Leon's book , and from the work QEdges as put forward?

Thanks, your help would be much appreciated!

(Credit to QEdges for the solution thus far and to Leon Wilson for demonstrating the ability to convert into indicator form)