Returns the middle value of the numbers in an array once they are sorted.
With an odd count it is the center item. With an even count it is the mean of the two center items. na items are skipped before ranking.
The median ignores outliers that would drag array.avg() away from the typical value, which makes it useful on spiky data such as volume.
Syntax
array.median(id: array<int/float>) -> series float
array.median(id: array<int>) -> series int
array.median() -> series float
array.median() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to take the middle of. na items are skipped. |
Returns
series float or series int: The median, or na when the array holds no numbers.
Example
//@version=6
indicator("array.median: robust volume", overlay = false)
var vol = array.new_float()
array.push(vol, volume)
if array.size(vol) > 30
array.shift(vol)
plot(array.median(vol), "Median", color.blue)
plot(array.avg(vol), "Mean", color.orange)See also
Runs on Sidechair