- cumulative sum

Moving averages, summation

Cum( Value )
FUNCTION Calculates a cumulative sum of the ARRAY from the first period in the chart.

Note: Starting from AmiBroker 5.30, the Cum() function does NOT force using all bars. In the past versions Cum() functions effectively turned OFF QuickAFL feature by requesting all bars to be processed. Since Cum() function was popular it caused that many legacy formulas that used it were not benefiting from QuickAFL.

To enable QuickAFL with such formulas now Cum() function does NOT affect required bars count (previously it forced all bars).

This change may lead to different results when comparing with old versions. If you are interested in getting old behaviour and use all bars just add:

SetBarsRequired( sbrAll )

anywhere in your formula.

EXAMPLE The formula cum( 1) calculates an indicator that rises one point for each day since the beginning of the chart - this is an equivalent of bar number - especially useful if you want to detect the last bar: ThisIsLastBar = cum( 1 ) == lastvalue( cum( 1 ) );
SEE ALSO SUM() function


Graham Kavanagh
gkavanagh [at]
2004-08-09 07:49:35
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


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

More information:

See updated/extended version on-line.