Sum
- sum data over specified number of bars

Moving averages, summation


SYNTAX Sum( ARRAY, periods )
RETURNS ARRAY
FUNCTION Calculates a cumulative sum of the ARRAY for the specified number of lookback periods (including today). The function accepts periods parameter that can be constant as well as time-variant (array).
EXAMPLE The formula "sum( CLOSE, 14 )" returns the sum of the preceding 14 closing prices. A 14-period simple moving average could be written "sum(C,14) / 14."
SEE ALSO CUM() function

Comments:

Graham Kavanagh
gkavanagh@e-wire.net.au
2004-08-09 07:52:41
Sum adds up the last "n" number of bars. It sums whatever you put into the first part of the sum formula.

Cum(1) adds 1 to the previous value of Cum, so the first bar is 1 and it just keeps adding one to the last bar value of cum(1).
You can use Cum to add anything, like how many times you get rising days in the entire chart:

Rise = C>O; //this gives results of 0 or 1
TotalRise = Cum(Rise);

You could limit this as well to time periods, or any other condition Example would be one for total rise days since 1995:

RecentRise = C>O and Year()>=1995; //this gives results of 0 or 1
TotalRise = Cum(RecentRise);


If you wanted to know how many rising days in the last 12 bars you would use:

LastRises = Sum(Rise,12);

Hope this helps

References:

The Sum function is used in the following formulas in AFL on-line library:

More information:

Updated on-line reference