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.
//@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.
//@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.