I am using this code in Pine Script but getting the "mismatched input 'a' expecting 'end of line without line continuation'" error.
How to fix that error with this function code?
val(s) =>
if s != s[1]
a = s-s[1]
if s = s[1]
a
a
In Pine there is a built-in offset function which shifts the values of a series to the right while discarding 'out of range' values. The advantage of the offset function lies in the fact that its result can be used in other expressions to execute complex calculations.
Second, when one operand is NaN (“not a number”, a value that's caused by invalid operations; Albahari & Albahari, 2012), then the arithmetic operators return NaN also (Pine Script Language Tutorial, n.d.).
Click the “More” (three dots) button on the top panel of the editor. Choose one of the options: “Open the Pine Editor in a new window…” or “Open the Pine Editor in a new tab…”. If you edit the code of the indicator added to the chart and click “Save”, the changes will be immediately applied to the indicator.
The 'end of line without continuation' error happens when there's an indentation mistake in the TradingView Pine code.
Looking at your code (and assuming copying it into StackOverflow went right), there is indeed an indentation problem:
val(s) =>
if s != s[1]
a = s-s[1]
if s = s[1]
a
a
There are two indentation problems in this code:
When we fix those two points the code becomes:
val(s) =>
if s != s[1]
a = s-s[1]
if s == s[1]
a
a
(Note that I also replaced the =
assignment operator with the ==
operator for equality here.)
The above code also triggers the 'undeclared identifier' error because of the a
variable: it is used before it is declared in your function. I wasn't sure if you also wanted that fixed or that the function code you posted is just part of a bigger function.
But if you also want to fix that 'undeclared identifier' error you'd change the function code to:
val(s) =>
a = 0.0
if s != s[1]
a := s-s[1]
if s == s[1]
a
a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With