Edgoro
Compile error · Syntax and indentation

Pine Script error: Mismatched input (fix)

"Mismatched input ... expecting end of line without line continuation" in Pine Script: what the parser expected, and how to fix indentation and empty blocks.

Pine Editor console · line 6
Mismatched input "label" expecting set "end of line without line continuation"

Cause

The parser met a token it didn't expect at that position. Most of the time the line before opens a block (if, for, while, switch or a function with =>) and the next line isn't indented, so the block is empty.

Broken code

TradingView reports the error on line 6.

Pine Script v6
//@version=6
indicator("Crossover labels", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
label.new(bar_index, low, "Buy")
plot(fast)

Fixed code

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

Pine Script v6
//@version=6
indicator("Crossover labels", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if ta.crossover(fast, slow)
    label.new(bar_index, low, "Buy")
plot(fast)

Why it works

An if statement needs a body: one or more lines indented by 4 spaces (or one tab) more than the if itself. Without the indentation, Pine reads label.new(...) as a new top-level statement while it is still waiting for the end of the if line, so it reports the first word of that line. Indenting it by 4 spaces makes it the body of the if.

The quoted token is where Pine got confused. The actual mistake is usually at the end of the line above or in the indentation of the reported line.

Other causes

  • A function whose body isn't indented. f(src) => followed by an unindented line gives the same message.
  • A loop body at column 0. for i = 0 to 9 needs its body indented by 4 spaces, exactly like if.
  • A switch case with the wrong indentation. Each case sits 4 spaces deeper than the switch line.

If the message says Syntax error at input instead, see Syntax error at input: it is usually the same family of indentation problems.

Questions

What does "expecting end of line without line continuation" mean in Pine Script?

Pine expected the current statement to end there, and found the quoted token instead. In practice it points at a line that should have been indented into a block, or at a statement that was split across lines incorrectly.

Should I use tabs or spaces in Pine Script?

Either works for blocks: one tab or 4 spaces per level. Avoid mixing them in the same block, and never indent a wrapped line by a multiple of 4 spaces, because Pine then reads it as a block.

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.