NthExtremesArray (Function)
The NthExtremesArray function will return the highest/lowest extreme, second most extreme, third most extreme (and so on) array element, based on the input N.
Syntax
NthExtremesArray(PriceArray, Size, N, HiLo, oExtremeVal, oExtremePosRaw)
Returns (Integer)
The oExtremeVal and oExtremeBar output parameters return' N’th most extreme high/low value and the number of bars ago it occurred. The NthExtremesArray function itself returns a value of 1.
Parameters
Name |
Type |
Description |
PriceArray |
Numeric Array |
Specifies the name of a numeric array containing bar values to compare for highest and lowest extremes. |
Size |
Numeric |
Sets the number of data elements (size) in the array to evaluate. |
N |
Numeric |
Sets which extreme value to search for (that is, 1 = most, 2 = 2nd most, and so on). |
HiLo |
Numeric |
Sets whether the function will return the highest or lowest extreme value. 1=Highest, -1=Lowest. |
oExtremeVal |
Numeric |
Outputs the highest or lowest extreme value found for the range of bars based on the HiLo setting. |
oExtremePosRaw |
Numeric |
Outputs the number of bars ago the extreme value occurred. |
Remarks
Just like the ExtremesArray function, the NthExtremesArray function has the inputs PriceArray and Size. 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 value for the Size input parameter should always be a whole number greater than 0 and is typically equal to the number of data elements in the array.
The NthExtremesArray function only works with one-dimensional arrays. All array-based referencing begins with array element 1.
See Multiple Output Function for more information on using output parameters to return values.
Example
Assigns to Value2 the highest High in the specified named array myArray with 20 elements using the oExtremeVal output parameter, and assigns to Value3 the number of bars ago the highest High occurred using oExtremeBar output parameter. Value1 is assigned a value of 1:
Array: myArray[20](0);
Vars: oExtremeVal(0), oExtremePosRaw(0);
{… add EL statements here to assign High values to array elements... }
Value1 = NthExtremesArray (myArray, 20, 1, oExtremeVal, oExtremePosRaw);
Value2 = oExtremeVal;
Value3 = oExtremePosRaw;