Ying
Ying

Reputation: 15

Pine Script: Sum() function is not working for Version 5 pine script

Good day everyone, below is the pine script for the Heatmap Volume indicator for Version 4. When I apply it in Version 5, it shows "Could not find function or function reference 'sum'", is it means that the sum function is not applicable in Version 5?

// Calculations
length2 := length2 > bar_index + 1 ? bar_index + 1 : length2
slength := slength > bar_index + 1 ? bar_index + 1 : slength

pstdev(Series, Period) =>
    mean = sum(Series, Period) / Period
    summation = 0.0
    for i=0 to Period-1
        sampleMinusMean = nz(Series[i]) - mean
        summation := summation + sampleMinusMean * sampleMinusMean
    result = sqrt(summation / Period)

May I know does it have any other ways to modify it so that it suits the version 5 pine script?

Upvotes: 0

Views: 3110

Answers (1)

user20003129
user20003129

Reputation:

The sum() function in v4 was changed to math.sum() in v5.

pstdev(Series, Period) =>
    mean = math.sum(Series, Period) / Period
    summation = 0.0
    for i=0 to Period-1
        sampleMinusMean = nz(Series[i]) - mean
        summation := summation + sampleMinusMean * sampleMinusMean
    result = sqrt(summation / Period)

Upvotes: 0

Related Questions