How to define Highest/Lowest after last Highest/Lowest values?

 

Hy Everybody,

I have the following situation:

extern double A=1.1111;

double L, M;

L=(Close[1]+Close[0])/2-A;

M=(Low[1]+Low[0])/2-A;

N= (L+ M)/2;

The question: Is there any way to find out next "N" Highest or Lowest values since "N" Last Highest or Lowest values(they can happen in any amount of periods ) ?

Thanks a lot in advance to everyone.

Reason: