Edgoro
Compile error · Syntax and indentation

Pine Script: no viable alternative at character (fix)

"no viable alternative at character" means Pine found a character it can't read, usually smart quotes or dashes pasted from a web page. Here is the fix.

Pine Editor console · line 2
no viable alternative at character "“"

Cause

The script contains a character that isn't part of Pine Script's syntax. Curly "smart" quotes copied from a web page, a word processor or a chat app are the usual culprits.

Broken code

TradingView reports the error on line 2.

Pine Script v6
//@version=6
indicator(“My indicator”, overlay = true)
plot(ta.sma(close, 20))

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("My indicator", overlay = true)
plot(ta.sma(close, 20))

Why it works

Pine strings must be enclosed in straight double quotes " or straight single quotes '. Curly quotes look similar but are different characters, so the compiler can't match them to anything. Replace them and save again; if more remain, the next one is reported.

Inside a string or a comment, any character is fine: "Trend “strong”" compiles, because the curly quotes are just text there.

Characters to look for

Pasted characterReplace with
“ ” curly double quotes"
‘ ’ curly single quotes'
— or – dashes- (minus)
× multiplication sign*
$ or other template placeholdersthe value they stand for

The Pine Editor's search (Ctrl+F, or Cmd+F on a Mac) finds them quickly. A dash in an expression, such as close — open, gives no viable alternative at character "—".

Questions

Why does code copied from a website give "no viable alternative at character"?

Many websites, documents and messaging apps turn straight quotes into curly quotes and hyphens into dashes. Pine reads those as unknown characters. Copy code from a plain-text source, or replace the characters in the Pine Editor.

Can I use emojis or accented letters in Pine Script?

Inside strings and comments, yes, so label text and titles can contain them. Quotes, operators and names in the code itself must use plain characters.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.