+1 888 340 6572

# NthPriceBar

Article/Author: Omega Research Inc., 1996

File Includes: Function - NthPriceBar

Description: This Function works just like the NthPrice Function, but instead of returning the Nth
Highest/Lowest value, it instead returns the number of bars since the Nth Highest/Lowest value.
Inputs:
HiLo - determines if the Highest or the Lowest will be sought. 1 = Highest, -1 = Lowest.
Nth - determines which occurrance of the Highest or Lowest: 1 = highest/lowest, 2 = 2nd highest/lowest...
Price - specifies which price asset is to be used.
Length - determines the number of trailing bars to consider.

EasyLanguage Code:
```INPUTS: HILO(NUMERICSIMPLE), NTH(NUMERICSIMPLE), PRICE(NUMERICSERIES), LENGTH(NUMERICSIMPLE);
ARRAY: PRICEARRAY[200](0),BARNUMARRAY[200](0);
VARS : X(0),Y(0),Z(0);

IF NTH <= LENGTH  AND NTH <= 200 THEN BEGIN
FOR X = 0 TO LENGTH-1 BEGIN
PRICEARRAY[X] = PRICE[X];
BARNUMARRAY[X] = X;
END;
FOR X = 0 TO NTH-1 BEGIN
FOR Y =  X+1 TO LENGTH-1 BEGIN
IF HILO = 1 THEN BEGIN
IF PRICEARRAY[Y] > PRICEARRAY[X] THEN BEGIN
VALUE1 = PRICEARRAY[X];
PRICEARRAY[X] = PRICEARRAY[Y];
PRICEARRAY[Y] = VALUE1;
VALUE1 = BARNUMARRAY[X];
BARNUMARRAY[X] = BARNUMARRAY[Y];
BARNUMARRAY[Y] = VALUE1;
END;
END;
IF HILO = -1 THEN BEGIN
IF PRICEARRAY[Y] < PRICEARRAY[X] THEN BEGIN
VALUE1 = PRICEARRAY[X];
PRICEARRAY[X] = PRICEARRAY[Y];
PRICEARRAY[Y] = VALUE1;
VALUE1 = BARNUMARRAY[X];
BARNUMARRAY[X] = BARNUMARRAY[Y];
BARNUMARRAY[Y] = VALUE1;
END;
END;
END;
END;
NTHPRICEBAR = BARNUMARRAY[NTH-1]+ CURRENTBAR - BARNUMBER;
END
ELSE
NTHPRICEBAR = -1;```