Median (Function)
The Median function returns the middle value after sorting numbers over a specified range of bars.
Syntax
Median(Price, Length)
Returns (Double)
A numeric value containing the median value of a specified number of sorted values.
Parameters
Name |
Type |
Description |
Price |
Numeric |
Specifies which bar value (price, function, or formula) to use. |
Length |
Numeric |
Sets the number of bars to consider. |
Remarks
The input Price tells the function what values to look at, while the Length input tells the function how many bars to include in the calculations. The function will sort Length number of Price elements in ascending order and return the middle element. If Length is an even number, it will choose the two values that fall at the middle of the sort and average them. See Table 1. If Length is an odd number the function will return the middle value. See Table 2.
Table 1
Bar Number |
Price |
Rank (1 = smallest) |
Median |
Close[0] |
3646.6 |
|
|
Close[1] |
3625.0 |
Œ |
|
Close[2] |
3667.1 |
|
|
Close[3] |
3669.6 |
|
|
|
Length = 4 |
|
3656.8 |
Table 2
Bar Number |
Price |
Rank (1 = smallest) |
Median |
Close[0] |
3646.6 |
|
|
Close[1] |
3625.0 |
Œ |
|
Close[2] |
3667.1 |
|
|
Close[3] |
3669.6 |
|
|
Close[4] |
3670.0 |
|
|
|
Length = 5 |
|
3667.1 |
Price is a numeric series type input. The input Length must be a whole number as it represents the number of bars, and it cannot change on a bar-to-bar basis.
Example
Value1 = Median(Close,10);