MedianArray (Function)
The MedianArray function looks at an array of values and returns the median value.
Syntax
MedianArray(PriceArray, Size)
Returns (Double)
A numeric value containing the median value for the array.
Parameters
|
Name |
Type |
Description |
|
PriceArray |
Numeric Array |
Specifies the name of a numeric array containing values upon which the median value is calculated. |
|
Size |
Numeric |
Sets the number of data elements (size) in the array to evaluate. |
Usage
If you had an array with 4 values, the function would sort the array in ascending order, choose the second and third largest values, and average them. See Table 1. If the array contained 5 values, the function would sort the array in ascending order, and choose the third (middle) value. See Table 2.
Table 1
|
ArrayElement |
Value |
Rank (1 = smallest) |
Median |
|
ArrayElement[1] |
3646.6 |
|
|
|
ArrayElement[2] |
3625.0 |
Œ |
|
|
ArrayElement[3] |
3667.1 |
|
|
|
ArrayElement[4] |
3669.6 |
|
|
|
|
|
|
3656.8 |
Table 2
|
ArrayElement |
Value |
Rank (1 = smallest) |
Median |
|
ArrayElement[1] |
3646.6 |
|
|
|
ArrayElement[2] |
3625.0 |
Œ |
|
|
ArrayElement[3] |
3667.1 |
|
|
|
ArrayElement[4] |
3669.6 |
|
|
|
ArrayElement[5] |
3670.0 |
|
|
|
|
|
|
3667.1 |
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 MedianArray function only works with one-dimensional arrays. All array-based referencing begins with array element 1.
This array function is similar to Median except that you can build an array of values that does not necessarily include contiguous bar values.
Example
Assigns to Value1 the median value of the specified named array MyArray with 10 elements.
Array: MyArray[10](0);
{… add EL statements here to assign price values to array elements... }
Value1 = MedianArray(MyArray,10);