nhab
nhab

Reputation: 1

Pine script error: "Mismatched input 'to' expecting 'end of line without line continuation'." without indentation problem

I got "Mismatched input 'to' expecting 'end of line without line continuation'." error. I have already checked my indentation.Here is my simple code:

//@version=5
indicator("My Script",overlay=true)
n=55
s=0.0
s2=0.0
m=0.0
float[] r = na

for i=0 to n-1
    s:=s+close[i]
    r[i]=5

    
plot(s/n,color=color.red)

Upvotes: 0

Views: 1230

Answers (1)

vitruvius
vitruvius

Reputation: 21342

It's because [] in pine-script is not arrays. It is called History Reference Operator. In order to use arrays, you need to use appropiate functions.

Try this:

//@version=5
indicator("My Script",overlay=true)
n=55
s=0.0
s2=0.0
m=0.0
r = array.new_float(n, na)

for i=0 to n-1
    s:=s+close[i]
    array.set(r, i, 5)
    
plot(s/n,color=color.red)

Upvotes: 0

Related Questions