You could use a loop, or you could use some construct (DataSeries or Array or List) to hold the series of the accumulated value for all bars. Then the sum over the last x bars is simply the current accumulated value less the accumulated value x bars ago.
You would accumulate as you stream, by simply adding the current value to the previous accumulated value, so you NEVER use a loop anywhere in the code.
Leave a comment: