array.mode() - Pine Script Function
array.mode()
Section titled “array.mode()”Overview
Section titled “Overview”The function returns the mode of an array’s elements. If there are several values with the same frequency, it returns the smallest value.
Syntax
Section titled “Syntax”array.mode(id) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | array<int/float> | An array object. |
Returns
Section titled “Returns”The most frequently occurring value from the id array. If none exists, returns the smallest value instead.
Remarks
Section titled “Remarks”- Returns na if the id array is empty.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("array.mode example")a = array.new_float(0)for i = 0 to 9array.push(a, close[i])plot(array.mode(a))