Need to program the extended level boomers scan

the logic defined is simple.

  1. day 1= 60 day high.
  2. I must have insider bars for atleast 2 days where the high and low are within the range of the bar in day 1.
  3. day 3 need not be insider for day 2 but must be insider for day 1.
  4. I could have any number of bars that are insiders of day 1.
  5. buy= breakout of day 1 high .
    I only got the rules for day 1 and the fact that there should be atleast > 2 bars between #5 and #1

I need some help in defining the afl logic for ensuring that the bars between #1 and #5 are insider in relation to the bar in #1

 // insider bars after 60 day highs.
sixtydayhigh=H>=HHV(H,-60);
barsinbetween60dayhighs=sixtydayhigh AND red(BarsSince(sixtydayhigh)>2,-1);

I can offer one quick note. I'm sure this is not a complete response to your question, because truthfully I don't fully understand the question.

But here's my quick coding note: The function HHV does not take a negative number as a parameter. It needs to be a positive number. So the first line of your code should refer to "60", not "-60."

thanks , here is a better formula with the logic. but it still does not work and let me explain what I am trying to do and hopefully explaining will make me think on the logic clearly.

// insider bars after 60 day highs.
sixtydayhigh=H>=HHV(H,60);  // this marks my 60 day high arrray
last60dayhighsbars=BarsSince(sixtydayhigh ); // I now how many bars since I got the last 60 day high.
highwhensixtydayhigh=ValueWhen(sixtydayhigh,High); // get the highest value of the last 60 day high bar.
Lowwhensixtydayhigh=ValueWhen(sixtydayhigh,Low); // get the lowest value of the last 60 bar high.
highestsincesixtydayhigh=HighestSince(sixtydayhigh,High); // get the highest value since the last 60 bar high.
lowestsincesixtydayhigh=LowestSince(sixtydayhigh,Low); // get the lowest value since the last 60 bar high.
// I will buy when the bars between the two 60 bar high's are ranging within the first 60 bar high and there are aleast 2 or more ranging bars.
Buy=Ref(highestsincesixtydayhigh<=highwhensixtydayhigh AND Lowwhensixtydayhigh>=Lowwhensixtydayhigh  AND last60dayhighsbars>2 ,-1) AND sixtydayhigh;
Sell=False;