Compilation error

Fix “Mismatched input” in Pine Script

Indent every statement that belongs to an `if`, `for`, function, or other local block by four spaces or one tab. The unindented `label.new()` line ends the block before Pine finds its body, so the parser reports mismatched input. Moving the line into the block restores the required script structure. If a different token is named, inspect the line immediately before it as well.

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.
  • A wrapped expression uses indentation that Pine interprets as a new block or global statement.
  • A missing closing delimiter on the previous line makes the next token unexpected.

How the fix was verified

Method
Pineify UAT grammar checker via check-pine-script-grammar.mjs
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