+1 888 340 6572

# NthPrice

Article/Author: Omega Research Inc., 1996

File Includes: Function - NthPrice

Description: The Highest and Lowest functions are perfect for finding the highest and
lowest values returned by the parameter PRICE for the number of bars specified by the parameter LENGTH.
However, there may be times when you want to find the second or third highest or lowest value.
The NthBar Function combines the NthHighest and NthLowest Functions, allowing the user to choose
which is to be used by the Inputs. In addition the reference limit is increased from 25 to 500.
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);
VARS: X(0),Y(0);

IF NTH <= LENGTH  AND NTH <= 200 THEN BEGIN

FOR X = 0 TO LENGTH-1 BEGIN
PRICEARRAY[X] = PRICE[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;
END;
END;

IF HILO = -1 THEN BEGIN
IF PRICEARRAY[Y] < PRICEARRAY[X] THEN BEGIN
VALUE1 = PRICEARRAY[X];
PRICEARRAY[X] = PRICEARRAY[Y];
PRICEARRAY[Y] = VALUE1;
END;
END;
END;
END;
NTHPRICE = PRICEARRAY[NTH-1];
END
ELSE
NTHPRICE = 0;```