Returns the number that occurs most often in an array.
Items are matched exactly, so it suits whole numbers and rounded prices. When two or more values occur equally often, the smallest of them is returned.
na items are skipped. An array without numbers returns na.
Syntax
array.mode(id: array<int/float>) -> series float
array.mode(id: array<int>) -> series int
array.mode() -> series float
array.mode() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to count. na items are skipped; a tie goes to the smaller value. |
Returns
series float or series int: The most frequent value, or na.
Example
//@version=6
indicator("array.mode: common level", overlay = true)
var seen = array.new_float()
array.push(seen, math.round(close))
if array.size(seen) > 60
array.shift(seen)
plot(array.mode(seen), "Most visited whole price")See also
Runs on Sidechair