static and add to it with :=. An ordinary variable is created again on every bar, so an ordinary total
restarts on every bar; a static variable is initialised once, on the first bar, and keeps its value from bar to bar.
static is the only keyword that persists a value across bars (intra persists only across the runs of one forming bar).
Restart the total each session
Testsession.isfirst and seed the total from the bar’s own value on the first bar of a session:
Built-in totals
talib.cum(source) accumulates a series with no declaration of your own, but it cannot be restarted. orderflow.cvd() is the
cumulative delta; it restarts each session.
Guard a value that can be na
Addingna to the total gives na from then on. Wrap a value that may be missing in nz, which turns na into 0. Order flow values are na on a bar without footprint data:
A total over the last N bars
talib.sum(source, length) adds the last length values: plot(talib.sum(volume, 20)). To keep the window yourself, see How to keep the last N values in an array.