1

Basically creating a custom indicator and need the previous indicator value added up. I’m currently using the following code:

exampleName = exCloseVal + exCloseVal[1] + exCloseVal[2] + exCloseVal[3] + exCloseVal[4] + exCloseVal[5]

Now let’s say I wanted the past 100 bar close values added up, would there be an alternative way to add them up, rather than typing it out the way I am up to 100?

Many thanks for reading and would greatly appreciate any help.

Lew2234
  • 21
  • 4

1 Answers1

1

You can use math.sum for that.

math.sum(source, length) → series float

The sum function returns the sliding sum of last y values of x.

RETURNS
Sum of source for length bars back.\

ARGUMENTS
source (series int/float) Series of values to process.
length (series int) Number of bars (length).

exCloseVal_sum = math.sum(exCloseVal, 100)
vitruvius
  • 15,740
  • 3
  • 16
  • 26