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.
//@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.
//@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 character | Replace with |
|---|---|
“ ” curly double quotes | " |
‘ ’ curly single quotes | ' |
— or – dashes | - (minus) |
× multiplication sign | * |
$ or other template placeholders | the 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.