VariablePeriodSum
Background
AmiBroker's built-in Sum adds up the values of an array over a fixed
number of bars. It is the basis of running totals such as cumulative volume, the
count of signals in a window, or the numerator of a simple moving average.
VariablePeriodSum works the same way but accepts a
period for each bar instead of a single fixed look-back, so the
length of the running total can change as market conditions change. The per-bar
periods often come from an adaptor such as the DominantCycle.
Included formula
This function is one of the building blocks behind the toolbox's Adaptive Smoothed Choppiness Index indicator, which uses it for the running-sum term of the calculation. To see that indicator, open the Charts window in AmiBroker, expand the WiseTraderToolbox group and drag Adaptive Smoothed Choppiness Index onto a chart. It plots the adaptive Choppiness Index in its own pane below price, with the adaptor (which sets the per-bar period) and the smoother set from its parameters.
The exported function
You can also call this function directly in your own formulas — it works just like
AmiBroker's built-in Sum but with a look-back that can change on every
bar.
VariablePeriodSum(DataArray, PeriodsArray)
| Parameter | Description |
|---|---|
| DataArray | The array whose values are summed. |
| PeriodsArray | An array (or value) giving the number of bars to sum over at each bar. |
Usage
periods = DominantCycle( Close );
// Volume accumulated over an adaptive window
cumVol = VariablePeriodSum( Volume, periods );
Plot( cumVol, "Adaptive Volume Sum", colorBlue );