Compilation error

Fix “Mismatched input” in Pine Script

Indent every statement belonging to an `if`, `for`, or function block by four spaces or one tab. For wrapped expressions, distinguish block indentation from continuation: current v6 allows any indentation inside parentheses or square brackets. Outside those delimiters, follow the documented continuation rules. Moving unindented statements into their parent local block and closing all open parentheses restores proper script structure. If mismatched input persists, inspect the token immediately before the reported line.

This link opens the Pine Script AI Coding Agent overview. It does not run or change code on this page.

Before and after

Make the smallest reviewable change

Both artifacts include the version declaration and the code needed to inspect the stated problem. The diff lists the lines that change between them.

Broken code.pine
//@version=6
indicator("Mismatched input demo", overlay = true)
if close > open
label.new(bar_index, high, "Up")
Fixed code.pine
//@version=6
indicator("Mismatched input demo", overlay = true)
if close > open
    label.new(bar_index, high, "Up")
Diff.pine
--- broken.pine
+++ fixed.pine
@@
 if close > open
-label.new(bar_index, high, "Up")
+    label.new(bar_index, high, "Up")

Root causes

  • A local block has no indented statement after its header (if, for, or function declaration).
  • A multi-line expression breaks across lines without valid line continuation indentation, triggering end of line errors.
  • An unclosed parenthesis, bracket, or string literal leaves the parser expecting continuation tokens on subsequent lines.
  • A wrapped expression uses indentation that Pine Script mistakenly interprets as a new local block or global statement.

How the fix was verified

Method
Pineify MCP pine-script-syntax-checker; static diagnostics only
Broken result
Returned a mismatched-input diagnostic at line 4, column 1.
Fixed result
Returned no grammar diagnostics.
Limit
The checker normalized the expected-token set, so the page treats the filled message as observed wording.

Bring the actual script, not just the message

Open the Coding Agent overview to paste editable Pine Script, explain the intended behavior, and request a review. Compile and test the result in TradingView before using it.

Paste your code to fix this error