string() - Pine Script Function
string()
Section titled “string()”Overview
Section titled “Overview”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.
Syntax
Section titled “Syntax”string(x) → const stringParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
x | const int/float/bool/color | Value to convert into a string literal at compile time. |
Returns
Section titled “Returns”const string — Textual representation of the argument.
Remarks
Section titled “Remarks”- Because the result is a
const string,string()cannot process series or runtime values. For dynamic conversion, usestr.tostring()instead. - When you need to concatenate constants (e.g.,
indicator(string("My") + " Strategy")), casting withstring()ensures Pine treats the result as a literal.
Example
Section titled “Example”//@version=5indicator(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")