Edgoro
Compile error · Types and qualifiers

Pine Script: series string used but const string expected

plotshape() and plotchar() text, and plot titles, must be constant strings in Pine Script. How to show dynamic text with label.new() instead.

Pine Editor console · line 4
Cannot call "plotshape" with argument "text"="call "str.tostring" (series string)". An argument of "series string" type was used but a "const string" is expected.

Cause

The text of plotshape() and plotchar() must be a fixed string written in the code. A value built from price, such as str.tostring(close), changes on every bar.

Broken code

TradingView reports the error on line 4.

Pine Script v6
//@version=6
indicator("Close on up bars", overlay = true)
up = close > open
plotshape(up, "Up bar", shape.labelup, location.belowbar, color.teal, text = str.tostring(close))

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("Close on up bars", overlay = true, max_labels_count = 500)
up = close > open
plotshape(up, "Up bar", shape.triangleup, location.belowbar, color.teal, size = size.tiny)
if up
    label.new(bar_index, low, str.tostring(close, format.mintick), yloc = yloc.belowbar, style = label.style_label_up, color = color.teal, textcolor = color.white)

Why it works

plotshape() draws one series of shapes that share the same text, decided when the script compiles. Labels are drawings created while the script runs, so each one can carry its own text. A script keeps the last 50 labels by default; max_labels_count = 500 raises that to the maximum, and older labels are removed automatically.

The same error with plot titles

Plot titles must be literal strings too. plot(close, title = "SMA " + str.tostring(len)) fails with An argument of "simple string" type was used but a "const string" is expected. Use a fixed title such as "SMA": the length already shows in the indicator's status line and settings.

Questions

How do I show a number on the chart in Pine Script?

Use label.new() to place text at a bar and price, or a table to show values in a fixed corner of the chart. plotshape() and plotchar() only accept fixed text.

Why are my old labels disappearing?

Pine keeps the last 50 labels by default. Set max_labels_count up to 500 in indicator() or strategy(); beyond that, the oldest labels are deleted automatically.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.