Cumulative Relative Performance - 'Mismatched input '|PE|' expecting 'end of line without line continuation'' error with Pine Script

Viewed 58

I want to get a cummulative relative Performance Line.

I get this error message. I don't know what i am doing wrong. Im trying it now for some time now. Can you help me?

Error: "Mismatched input '|PE|' expecting 'end of line without line continuation'."

change = (close[1]-close[2])/close[2])

n = 252 
sum = 0 

sais(change, n) => for i=0 to n-1 
    sum := sum + change [n] 

plot(sais, color=color.blue)
1 Answers

The weird error is most likely caused by the fact that you use both the single-line and the multi-line function declaration syntax. It has to be multiline because of the for cycle, so the first line after => should be empty, and the code should start on the next line, indented. This is how your function should look (formatting-wise):

sais(change, n) => 
    for i=0 to n-1 
        sum := sum + change [n]

Note that this won't work either because the function cannot modify a global variable sum. You'd need to create a local variable inside the scope of the function to store the value and then return it and assign it to your global sum. Depending on what you want to achieve, it might look something like this:

<...>
sum = 0 

sais(change, n) =>
    local_sum = 0
    for i=0 to n-1 
        local_sum := local_sum + change[n] 
    local_sum
    
sum := sais(change, n)
Related