Sidechair

str.repeat()

Browse the reference

Returns a string made of the source repeated a number of times, with an optional separator between copies.

Try it in the editor

str.repeat("ab", 3) returns "ababab". Add a separator and it goes between copies: str.repeat("ab", 3, "-") returns "ab-ab-ab".

A count below 1 returns an empty string. Fractions are rounded down.

Syntax

Pine Script
str.repeat(source: const string, repeat: const int, separator: const string (optional)) -> const string
str.repeat(source: input string, repeat: input int, separator: input string (optional)) -> input string
str.repeat(source: simple string, repeat: simple int, separator: simple string (optional)) -> simple string
str.repeat(source: series string, repeat: series int, separator: series string (optional)) -> series string

Arguments

NameTypeDefaultDescription
sourceconst/input/simple/series stringrequiredThe text to copy. It is joined to itself repeat times, with separator between copies.
repeatconst/input/simple/series intrequiredHow many copies of source to join. 0 gives an empty string.
separatorconst/input/simple/series string""Text placed between copies.

Returns

const/input/simple/series string: the repeated text.

Remarks

  • Use it to draw simple text bars, for example a row of block characters sized by a value.

Example

Pine ScriptLength of a built barOpen in editor
//@version=6
indicator("Repeat")
n = math.max(1, math.round(ta.rsi(close, 14) / 10))
plot(str.length(str.repeat("#", n)), "Bar length", color = color.teal, style = plot.style_stepline)

See also

Runs on Sidechair