Cannot use "fill" in local scope
Call fill() at the top level and choose its colour with the condition: na leaves the gap unfilled on the other bars.
Updated 23 October 2026. Runs in your browser; nothing you type is uploaded.
Try a worked example
My script, Pine v6 indicator
TradingView's compiler stops at line 7
Cannot use "fill" in local scope
Static checks, which read the code as written: Passes static repaint & Pine Script v6 checks. Edit the script and the compiler line goes; the checks below follow your edits.
Critical repaint flags
0
0 caution flags to verify
Bar-close gate
Not found
barstate.isconfirmed or a bar-close alert
Higher-timeframe calls
0
request.security() calls, of a 40 limit
Plots and alerts
2
Plots, of a 64 limit; 0 alerts
Repaint and lookahead
No lookahead leaks, unshifted request.security() calls or realtime-only signal branches found in this snippet.
Pine Script v6 migration checklist
Declares //@version=6, and none of the migration patterns this checker reads were found. TradingView's compiler is the final word.
Want TradingView indicators whose Pine Script v6 source already passes every check?
Every desk in Pine Pro Library ships as readable .pine v6 source with confirmed higher-timeframe requests and barstate.isconfirmed event logging.
What causes it
fill() is one of the calls that create the script's outputs (plots, shapes, fills, background colours, horizontal lines, alert conditions), and Pine accepts those only at the top level of the script, not inside an if, for, switch or function block. The set of outputs is fixed before the first bar runs, so a condition can change what an output shows, not whether it exists.
The fix, compiled
Call fill() at the top level and choose its colour with the condition: na leaves the gap unfilled on the other bars.
//@version=6
indicator("My script", overlay = true)
bull = close > open
p1 = plot(high)
p2 = plot(low)
if bull
fill(p1, p2, color.new(color.green, 80))//@version=6
indicator("My script", overlay = true)
bull = close > open
p1 = plot(high)
p2 = plot(low)
fill(p1, p2, bull ? color.new(color.green, 80) : na)Scope: where a call or an assignment may go
- Cannot use "plot" in local scope
- Cannot use "plotshape" in local scope
- Cannot use "bgcolor" in local scope
- Cannot use "alertcondition" in local scope
- Cannot use "hline" in local scope
- Cannot modify global variable "count" in function
- Function arguments cannot be mutable ("x")
- "a" is already defined
Compiled on TradingView 23 October 2026. The checker above reads repaint and v6 migration patterns; TradingView's compiler is the final word on whether a script compiles.
Have your AI fix the next one
- Pine Fixer An AI skill pack for 45 compiler-verified Pine v6 failure classes, with a repaint clinic. $9.99 once.