I got TradingView's 'end of line without continuation' error with Pine Script

ⅰ亾dé卋堺 提交于 2019-12-07 04:29:21

问题


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

回答1:


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:

  • The first 4 lines of the function are indented with 5 spaces (or 1 Tab plus a space). But code lines of a function need to be indented with 4 spaces (or 1 Tab) in TradingView Pine.
  • The two lines that follow after the if statements are not indented. But they do need to be: with 4 spaces (or 1 Tab) or a multiple thereof.

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


来源:https://stackoverflow.com/questions/51724359/i-got-tradingviews-end-of-line-without-continuation-error-with-pine-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!