Returns the arithmetic mean of the numbers in an array.
The sum of the numbers divided by how many there are. Items that are na are left out of both, so a single gap does not spoil the result.
An array with no numbers returns na.
Syntax
array.avg(id: array<int/float>) -> series float
array.avg(id: array<int>) -> series int
array.avg() -> series float
array.avg() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to average. na items are skipped, so they do not drag the mean down. |
Returns
series float or series int: The mean of the numbers, or na.
Remarks
- It matches
ta.sma()when the array holds the last N values of a series.
Example
//@version=6
indicator("array.avg: 7-bar mean", overlay = true)
var win = array.new_float()
array.push(win, close)
if array.size(win) > 7
array.shift(win)
plot(array.avg(win), "Mean close")See also
Runs on Sidechair