Adds up all numbers in an array and returns the total.
na items are skipped instead of turning the whole sum into na. An empty array, or one that holds only na, sums to 0.
Divide by array.size() for a simple mean, or call array.avg(), which already ignores na items.
Syntax
array.sum(id: array<int/float>) -> series float
array.sum(id: array<int>) -> series int
array.sum() -> series float
array.sum() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | array<int/ | required | The numeric array to add up. na items are skipped. |
Returns
series float or series int: The sum of the numbers in the array.
Example
//@version=6
indicator("array.sum: rolling volume", overlay = false)
var vol = array.new_float()
array.push(vol, volume)
if array.size(vol) > 12
array.shift(vol)
plot(array.sum(vol), "Volume, last 12 bars", style = plot.style_columns)See also
Runs on Sidechair