NthExtremes (Function)

image\trumpet2.gif Disclaimer

The NthExtremes function will return the highest/lowest extreme, second most extreme, third most extreme (and so on) price over a specified number of bars.

Syntax

NthExtremes(Price, Length, N, HiLo, oExtremeVal, oExtremeBar)

Returns (Integer)

The oExtremeVal and oExtremeBar output parameters return the 'N'th most extreme Price and the number of bars ago it occurred.  The Extremes function itself returns a value of 1 if successful or -1 when N or Length is out of range.

Parameters

Name

Type

Description

Price

Numeric

Specifies which bar value (price, function, or formula) to compare for highest or lowest extremes.

Length

Numeric

The number of trailing bars to consider.

N

Numeric

How extreme (that is, 1 = most, 2 = 2nd most, and so on).

HiLo

Numeric

A switch setting that determines whether the function will return the highest or lowest extreme value.  1=Highest, -1=Lowest.

oExtremeVal

Numeric

Output variable that returns the value of the extreme price.

oExtremeBar

Numeric

Output variable that returns the number of bars ago that the extreme value occurred.

Remarks

Just like the Extremes function, the NthExtremes function has the inputs Price and Length. In addition, it also has the input N. This is the input that specifies if it is the second most extreme, third most extreme (and so on) value desired.

  The Length input in the NthExtremes function should always be a positive value equal to or less than 100. The value for N should not be greater than the value for the input Length.

See About Functions - Multiple Output Function for more information on using output parameters to return values.

Example

Assigns to Value2 the 3rd highest High of the last 30 bars using the oExtremeVal output parameter, and assigns to Value3 the number of bars ago the 3rd highest High occurred using oExtremeBar output parameter. Value1 is assigned a value of 1:

vars: oExtremeVal(0),oExtremeBar(0);

Value1 = Extremes(High, 30, 3, 1, oExtremeVal, oExtremeBar);

Value2 = oExtremeVal;

Value3 = oExtremeBar;