Sum

Returns the sum of historical values of a Series for a given period.

Accepts the following parameters:

Parameter NameTypeDefault ValueNotes
valueSeries<Number>--
periodNumber--

Returns: Series<Number>

Sum is a built-in function - you can use it directly. Below is an example implementation:

1 function Sum(value, period):
2 series sum:
3 once:
4 initialSum = 0
5 for i from 0 to period - 1
6 initialSum = initialSum + value[i]
7 initialSum
8 then: sum[1] - value[period] + value