Sidechair

string()

Browse the reference

Converts a value to the string type; string(na) gives a na that is typed as a string.

Try it in the editor

string(x) fixes the type of a text value. The common use is var tag = string(na), which declares a text variable that starts empty so later code can assign text to it.

It does not turn numbers into text. Use str.tostring() for that.

Syntax

Pine Script
string(x: const string) -> const string
string(x: input string) -> input string
string(x: simple string) -> simple string
string(x: series string) -> series string

Arguments

NameTypeDefaultDescription
xconst/input/simple/series stringrequiredThe value to convert. A string or na.

Returns

const/input/simple/series string: The same text.

Remarks

  • string(na) is na.
  • On Sidechair: string() returns its argument as it is; the engine tracks types loosely, so the cast mainly documents intent and fixes the declared type.

Example

Pine ScriptText that starts emptyOpen in editor
//@version=6
indicator("string(na)")
var tag = string(na)
if close > open
    tag := "up"
else
    tag := "down"
plot(tag == "up" ? 1 : -1, "Direction", style = plot.style_columns)

See also

Runs on Sidechair