Skip to content

string() - Pine Script Function

string() casts a const or simple value to a const string. It is typically used when you must supply a literal text argument—such as the default title for a plot—constructed from compile-time constants.

string(x) → const string
NameTypeDescription
xconst int/float/bool/colorValue to convert into a string literal at compile time.

const string — Textual representation of the argument.

  • Because the result is a const string, string() cannot process series or runtime values. For dynamic conversion, use str.tostring() instead.
  • When you need to concatenate constants (e.g., indicator(string("My") + " Strategy")), casting with string() ensures Pine treats the result as a literal.
//@version=5
indicator(string("Breakout ") + "Monitor", overlay=true)
length = input.int(20, "Range length")
upper = ta.highest(high, length)
lower = ta.lowest(low, length)
plot(upper, "Upper band")
plot(lower, "Lower band")