Pine Script error: Script must have at least one output function call
Fix "Script must have at least one output function call" in Pine Script: add a plot, a background colour, a label, an alert or another output.
TradingView stops with "Script must have at least one output function call (e.g. plot, barcolor, etc.)" when an indicator works out values but never shows or sends anything. A script has to produce at least one output: a plot, a colour change, a drawing, an alert or a log line. Add one, usually a plot() of the value you calculated, and the error goes away.
What causes it
An indicator exists to put something on the chart or to raise an alert. If the code only assigns variables, Pine has nothing to display, so it refuses to compile the script.
Calculating a value and forgetting to show it
This is the most common case, often from a script that was half written or trimmed down. This code FAILS on TradingView:
//@version=6
indicator("Nothing")
x = ta.sma(close, 20)
The moving average is calculated on every bar, but nothing uses it for output. The message is the same whether the script has one line of maths or a hundred.
Deleting or commenting out the last plot
While debugging, people often comment out plot() lines to see what changes. Comment out the last one and the script has no output left. The same happens when you copy the calculation part of someone else's indicator into a new script and leave its plotting section behind.
Planning to show the value only sometimes
Some people leave the plot out because they only want to see the value under a condition, and then are not sure where to put it. plot() has to sit at the top level of the script. Putting it inside an if triggers a different error, covered in Cannot use 'plot' in local scope; the fix there is to make the plotted value conditional.
What counts as an output
Any one of these satisfies Pine:
plot,plotshape,plotchar,barcolor,bgcolor,hlineorfill;- a drawing: a
label,line,boxortable; - an alert:
alertconditionoralert; - a
logcall.
In a strategy, the strategy.* order calls count as output too, so a strategy that places orders but plots nothing is fine.
How to fix it
Decide what the script should actually do, then add the output that matches.
Plot the value
If you calculated a line, plot it. Tested version of the broken script above:
//@version=6
indicator("SMA 20 shown")
x = ta.sma(close, 20)
plot(x, "SMA 20")
Use a different kind of output
You do not have to draw a line. A script that colours the background when a fast average is above a slow one, and offers an alert on the cross, has no plot() at all and still compiles. Tested:
//@version=6
indicator("Background and alert", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
bgcolor(fast > slow ? color.new(color.green, 85) : na)
alertcondition(ta.crossover(fast, slow), "EMA cross up", "EMA 9 crossed above EMA 21")
Here bgcolor() and alertcondition() are both outputs. Either one alone would be enough.
For a helper script
Sometimes a script is a scratch pad where you only want to check a number. Plot it, or write it out with a log call. Either one gives the script its output and lets you see the value.
What SuperCharting's Script Editor shows
SuperCharting's engine is more lenient here and runs this code. The broken "Nothing" example compiles and runs on sample bars without this error. If the script must also work on TradingView, fix it the way shown above. Both tested fixes also run in SuperCharting.
To check a script:
- Open a chart and open the Script Editor with Ctrl + E.
- Paste the script into the code area.
- Read the console, then press Add to chart.
Since SuperCharting accepts a script with no output, a clean console does not tell you that TradingView will accept it. Before you copy a script across, make sure it has at least one of the outputs listed above. If you are writing your first script, write your first indicator walks through indicator() and plot() step by step, and the Pine Script code checker page explains the console messages.
Related errors
Cannot use 'plot' in local scope is the error you get if you try to fix this one by putting plot() inside an if block. If you added a plot from an old script and it fails on a name such as sma, see Could not find function or function reference. For a script that stops because a name was never declared, see Undeclared identifier.
Frequently asked questions
Does a label or a table count as an output?
Yes. Drawings made with label, line, box or table count, so a script that only draws a table, such as a dashboard, compiles.
Is alertcondition() enough on its own?
Yes. alertcondition() and alert() both count as outputs, so an alert-only script is allowed.
Do strategies need a plot?
No. In a strategy, the strategy.* order calls count as output, so a strategy that only places orders compiles without any plot().
Does a log call count as an output?
Yes. A log call is enough to satisfy the rule, which helps when you only want to print a value while testing.
TradingView and Pine Script are trademarks of TradingView, Inc. SuperCharting is independent and not affiliated with it.