What the Pine Script error fixer does
Pine Script errors are terse. TradingView points at a line, prints a short message such as "Undeclared identifier", "Mismatched input" or "Cannot use 'plot' in local scope", and leaves you to work out the cause. The fixer reads your script and the error message together, explains each problem in plain English, and returns a complete corrected script in Pine Script version 6, followed by a list of what changed and why.
It keeps your logic: the same inputs, calculations, colors and outputs. It fixes what stops the script from compiling or running and upgrades older syntax to v6. It does not add features, tune your parameters or "improve" a strategy.
How to use it
- Open the script in TradingView's Pine Editor, select everything and copy it.
- Paste it into the code box. The fixer reads up to 8,000 characters; for a longer script, paste the section around the error together with the inputs it uses.
- Copy the error message from the console under the Pine Editor and paste it into the second box. It is optional, but it points the AI at the right line straight away.
- Click Fix my script. The answer arrives in four parts: what went wrong, the corrected script, what changed, and what to check before you use it.
- Copy the corrected script back into the Pine Editor, save it and add it to the chart. Compare it with the original on a few bars before you rely on it.
You get 3 free fixes a month without an account. Edgoro does not save the code you paste.
The errors it sees most often
- Cannot use 'plot' in local scope. plot(), plotshape(), bgcolor(), alertcondition() and the other drawing calls only work at the top level of the script, never inside an if block, a loop or a function. The fix plots a conditional value instead: a value on the bars that qualify and na everywhere else.
- Undeclared identifier. A variable used before it is declared, a typo, or an old function name without its namespace: ema() became ta.ema(), crossover() became ta.crossover(), security() became request.security().
- Mismatched input. Usually indentation or a missing bracket on the line above. Local blocks are indented by 4 spaces or a tab; a long line continued on the next one must not be indented by a multiple of 4 spaces.
- Cannot modify global variable in function. A function cannot reassign a global with :=. Return the value from the function and assign it outside.
- Could not find function or function reference. Typically study(), the v4 name of indicator(), or a function from a library that is not imported.
- Loop takes too long, or too many drawings. Runtime limits: the fix narrows the loop or reuses drawings instead of creating one per bar.
Each of these, and two dozen more, has its own page in the Pine Script errors reference: the exact message, a broken script that reproduces it and the corrected version.
What changes from v5 to v6
Most public scripts are still written in v4 or v5. Version 6 keeps almost everything from v5 but tightens a few rules, which is why a script can fail as soon as its first line says //@version=6:
- Booleans can no longer be na. A bool is true or false, so na(myBool) and na branches in boolean expressions must go.
- Numbers no longer turn into booleans on their own: "if volume" becomes "if volume > 0".
- and / or are evaluated lazily: the right side is skipped when the left side already decides the result. It matters when the right side calls a function that must run on every bar.
- Dividing two integer constants can return a fraction (5 / 2 is 2.5), so code that relied on truncation needs int() or math.floor().
- timeframe.period includes the multiplier: "1D" rather than "D".
- The when argument of strategy.entry(), strategy.exit() and the other order functions is gone: put the call inside an if block.
From v4, the bigger renames still apply: study() is indicator(), security() is request.security(), rsi() is ta.rsi(), and the transp argument gave way to color.new(). The Pine Script v6 guide for beginners covers the language from the start.
Worked example
Click Try an example to load this v5 script and its error:
//@version=5
indicator("EMA cross", overlay=true)
fastLen = input.int(9, "Fast EMA")
slowLen = input.int(21, "Slow EMA")
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
if ta.crossover(fast, slow)
plot(fast, color=color.green)
bgcolor(ta.crossunder(fast, slow) ? color.red : na, transp=80)
The error, "Cannot use 'plot' in local scope", comes from line 8: plot() sits inside an if block. A typical answer moves it to the top level as plot(ta.crossover(fast, slow) ? fast : na, ...) and draws it as circles, because a line cannot connect values that exist on isolated bars. It also spots the second problem before TradingView does: bgcolor() has no transp argument, so the color becomes color.new(color.red, 80). The first line becomes //@version=6, and the "What changed" list shows each of these edits with the reason.
Limits worth knowing
- The AI does not run your script. It reads the code the way an experienced Pine developer would, so always compile the result in the Pine Editor. If a new error appears, paste it with the corrected script and run the fixer again.
- It cannot see what you import. Libraries, the chart's symbol and your input values are invisible to it; when a fix depends on them, the answer says so rather than guessing.
- No repainting shortcuts. It will not add lookahead to request.security() without an offset, and it flags code that peeks at future bars. See Pine Script repainting explained.
- A script that compiles is not a tested strategy. Backtest it before you trade with it.
Would you rather start from a clean script? The Pine Script generator writes complete v6 indicators and strategies from a plain-English description.