Sidechair

array.new_string()

Browse the reference

Builds an array of text items, with na as the default so blank slots need an explicit empty string.

Try it in the editor

array.new_string(3, "-") holds three dashes. The default item is na, not an empty string, so pass "" as initial_value when blank slots are what you want.

Fixed-size string arrays suit table captions, per-rule status words and weekday names. array.join() turns the whole array into one string with a separator you choose, and str.split() goes the other way.

Syntax

Pine Script
array.new_string(size: series int (optional), initial_value: series string (optional)) -> array<string>

Arguments

NameTypeDefaultDescription
sizeseries int0How many text slots to start with: 0 or more, up to 100,000. A fixed size works well for captions that are overwritten with array.set().
initial_valueseries stringnaThe string written into every slot. Pass an empty string for blanks, since leaving it out gives na and not "".

Returns

array<string>: A new array of strings with the requested size, every slot holding initial_value or na.

Example

Pine ScriptJoin three status words into one labelOpen in editor
//@version=6
indicator("array.new_string: status line", overlay = true)
var parts = array.new_string(3, "")
array.set(parts, 0, close > open ? "up" : "down")
array.set(parts, 1, ta.rsi(close, 14) > 70 ? "hot" : ta.rsi(close, 14) < 30 ? "cold" : "mid")
array.set(parts, 2, volume > ta.sma(volume, 20) ? "busy" : "quiet")
if barstate.islast
    label.new(bar_index, high, array.join(parts, " / "))
plot(close, "Close")

See also

Runs on Sidechair