Converts a value to the string type; string(na) gives a na that is typed as a string.
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
string(x: const string) -> const string
string(x: input string) -> input string
string(x: simple string) -> simple string
string(x: series string) -> series stringArguments
| Name | Type | Default | Description |
|---|---|---|---|
| x | const/ | required | The 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
//@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