Indicators/probuilder · probacktest · proorder · proscreener

Summation

Summation in ProBuilder returns the sum of a price or series over the last N bars, a building block for custom averages and oscillators. Syntax, examples.

Syntax

probuilder
summation[N](price)

Parameters

NameTypeDefaultDescription
NintegernoneNumber of bars included in the sum. Must not exceed the amount of loaded history.
priceseriescloseAny price type or numeric series: open, close, high, low, volume, a boolean expression, or a custom variable.

Formula

code
summation[N](price) = price + price[1] + price[2] + ... + price[N-1]

A rolling window sum: each new bar adds the newest value and drops the value that falls out of the window.

How it works

On every bar, ProBuilder adds up the N most recent values of the given series and returns the total. Unlike cumsum, which accumulates from the first loaded bar and never forgets, summation uses a fixed-length sliding window, so the result reflects only recent history.

The function accepts any numeric series, not just prices. Two idioms follow from this. First, dividing a summation by its period reproduces a simple moving average, which makes the function useful when the intermediate total itself is needed. Second, summing a boolean expression counts occurrences, because comparisons evaluate to 1 when true and 0 when false: summation[20](close > open) returns how many of the last 20 bars closed up.

Sums of volume are a third common use, for relative-volume filters that compare today's activity against the recent total or average.

Examples

Example 1, Gap between summed opens and closes (Indicator)

probuilder
// Total opening and closing prices over the last 10 bars
i1 = summation[10](open)
i2 = summation[10](close)
// Absolute difference between the two totals
RETURN ABS(i1-i2)

Sums the last 10 opens and the last 10 closes and returns the absolute difference, a rough measure of how much net intrabar drift accumulated over the window.

Example 2, Counting up bars as an entry filter (ProOrder)

probuilder
// Count bullish bars among the last 20
upBars = summation[20](close > open)

IF NOT OnMarket THEN
  // Require broad participation before joining the move
  IF upBars >= 14 AND close > Average[50](close) THEN
    BUY 1 CONTRACT AT MARKET
  ENDIF
ELSIF upBars < 10 THEN
  SELL AT MARKET
ENDIF

Uses summation over a boolean series to count up-closes: at least 14 of the last 20 bars must be bullish for an entry, and the position closes when the count fades.

Example 3, Relative volume scan (ProScreener)

probuilder
// Today's volume versus the average of the prior 20 bars
avgVol = summation[20](volume[1]) / 20
relVol = volume / avgVol
SCREENER[relVol > 2](relVol AS "Rel volume")

Returns instruments trading at more than twice their 20-bar average volume, with the ratio shown in the results column.

Interpretation

Summation is a computational primitive rather than a signal generator, so interpretation depends entirely on what is being summed:

  • Prices. A rolling sum of prices tracks the same shape as a moving average scaled by N; it is mostly useful as an intermediate quantity.
  • Booleans. The sum is a count, readable as breadth or persistence: how many of the last N bars satisfied a condition.
  • Volume. Rolling volume totals underpin relative-volume and accumulation-style measures.

Common errors and gotchas

  • Window exceeding loaded history. If N is larger than the number of available bars, the early portion of the chart or backtest is computed on incomplete data. Keep N well inside the loaded range, or discard initial bars.
  • Summation versus cumsum. summation[N] is a sliding window; cumsum accumulates everything since the first bar and depends on how much history is loaded. Swapping one for the other changes results silently.
  • Forgetting the offset in comparisons. summation[20](volume) includes the current bar. For a baseline that excludes the forming bar, sum the shifted series, as in summation[20](volume[1]).
  • Precision on large windows. Summing large prices over hundreds of bars produces big totals; prefer derived ratios or averages over raw sums when displaying results to keep scales readable.
  • cumsum, cumulative sum from the first loaded bar.
  • Average, simple moving average, equal to a summation divided by its period.
  • WeightedAverage, average with linearly weighted terms.
  • Highest, maximum value over a window, another rolling aggregate.
  • Lowest, minimum value over a window.
  • ABS, absolute value, used with sums of signed quantities.
  • Momentum, difference across a window rather than a total.
  • OBV, cumulative volume balance, a signed running sum.