CODESCRIPT

Text

23 entries. What each one takes, what it returns, and a working example.

color(hex, alpha)

A color in #rrggbbaa form with the opacity applied.

hex
color
A color (#rgb or #rrggbb).
alpha
number
Opacity 0-1 (0 fully transparent, 1 fully opaque). Defaults to 1.
NOTE

alpha is clamped to 0-1. If an invalid hex is given the input is returned unchanged. Ideal for making fills and backgrounds semi-transparent.

CODESCRIPT
plot(close, color=color("#26a69a", 0.5))

Plots price in a half-transparent green (#26a69a80).

contains(metin, parça)

true if part occurs anywhere in the text, otherwise false.

metin
string
The text to search within.
parça
string
The substring being searched for.
NOTE

Case sensitive. For classifying text such as a symbol name or a session label.

CODESCRIPT
plot(iff(contains("BTCUSDT", "USD"), 1, 0))

Since "BTCUSDT" contains "USD", it plots 1.

endsWith(metin, son)

true if the text ends with that suffix, otherwise false.

metin
string
The text being checked.
son
string
The suffix searched for at the end.
NOTE

Case sensitive. Handy for spotting a quote currency (…USDT).

CODESCRIPT
plot(iff(endsWith("BTCUSDT", "USDT"), 1, 0))

Since "BTCUSDT" ends with "USDT", it plots 1.

format(şablon, ...değerler)

Text with placeholders filled; behaves the same as text.

şablon
string
Text with {0} {1} or {} placeholders.
...değerler
any
Values to fill the placeholders.
NOTE

An alias of text. {0} fills by index, {} in order; a decimal is trimmed to at most 4 places.

CODESCRIPT
if barstate.islast {
  infoTable(format("O:{0} C:{1}", open, close))
}
plot(close)

Joins open and close on one line and writes it into the panel.

formatTime(zaman)

A date-time text in "YYYY-MM-DD HH:MM" form (UTC); an empty text on invalid input.

zaman
number
The timestamp to format (seconds or milliseconds).
NOTE

Auto-detects a seconds or milliseconds stamp. Output is in UTC. For showing a time on a label/panel.

CODESCRIPT
if barstate.islast {
  label(close, formatTime(time), barIndex)
}
plot(close)

Writes the last bar's time onto a label as a readable date-time.

gradient(value, lo, hi, loColor, hiColor)

A color blended between the two colors by mapping value across [lo,hi] (a color series if a series is given).

değer
series
The value or series that selects the color.
lo
number
Lower bound (maps to loColor).
hi
number
Upper bound (maps to hiColor).
loColor
color
The color at the lower bound.
hiColor
color
The color at the upper bound.
NOTE

If value falls outside the range it is pinned to the ends. For heatmap-like coloring — e.g. showing RSI shifting color from oversold to overbought.

CODESCRIPT
plot(close, color=gradient(rsi(close, 14), 30, 70, "#ef5350", "#26a69a"))

Colors price red near RSI 30 and green near 70.

indexOf(metin, parça)

The position of the first occurrence of part (0-based), or -1 if not found.

metin
string
The text to search within.
parça
string
The substring whose position is sought.
NOTE

Positions count from 0. A not-found result is signalled by -1.

CODESCRIPT
plot(indexOf("merhaba", "h"))

Since "h" is at position 3 in "merhaba", it plots 3.

lower(metin)

The text with all letters converted to lowercase.

metin
string
The text to lowercase.
NOTE

To compare case-insensitively, normalize both sides with lower.

CODESCRIPT
if barstate.islast {
  label(close, lower("MERHABA"), barIndex)
}
plot(close)

Places a label reading "merhaba" on the last bar.

regexMatch(metin, desen)

The FIRST substring matching the pattern, or an empty text if there is no match.

metin
string
The text to search in.
desen
string
The regular-expression pattern to search for.
NOTE

Returns only the first match. Can be paired with toNumber to extract a number or pattern from text.

CODESCRIPT
plot(toNumber(regexMatch("abc123def", "[0-9]+")))

The first digit block "123" is extracted, converted to a number, and plotted.

repeat(metin, n)

The text written n times in a row.

metin
string
The text to repeat.
n
number
The number of repetitions.
NOTE

If n is zero or negative it returns an empty text. Handy for a simple progress bar / separator strip.

CODESCRIPT
plot(strLength(repeat("ab", 3)))

"ab" is repeated 3 times ("ababab"); its length 6 is plotted.

replace(metin, eski, yeni)

The text with only the FIRST match replaced.

metin
string
The text to modify.
eski
string
The substring searched for.
yeni
string
The replacement substring.
NOTE

Replaces only the first match; use replaceAll for every match.

CODESCRIPT
if barstate.islast {
  label(close, replace("aXbXc", "X", "-"), barIndex)
}
plot(close)

The first X is replaced; the label reads "a-bXc".

replaceAll(metin, eski, yeni)

The text with every match replaced.

metin
string
The text to modify.
eski
string
The substring searched for.
yeni
string
The replacement substring.
NOTE

Replaces all matches; use replace to change only the first.

CODESCRIPT
if barstate.islast {
  label(close, replaceAll("aXbXc", "X", "-"), barIndex)
}
plot(close)

All X's are replaced; the label reads "a-b-c".

startsWith(metin, ön)

true if the text starts with that prefix, otherwise false.

metin
string
The text being checked.
ön
string
The prefix searched for at the start.
NOTE

Case sensitive.

CODESCRIPT
plot(iff(startsWith("BTCUSDT", "BTC"), 1, 0))

Since "BTCUSDT" starts with "BTC", it plots 1.

str(değer)

The text form of the value; if a series is given, an element-wise text series. na → "NaN".

değer
any
The number, boolean or series to convert to text.
format
string
Optional. A format: a pattern like "#.##", or "percent", "volume" or "mintick".
NOTE

Without a format it shows up to 10 decimals and trims trailing zeros. "percent" appends %, "volume" abbreviates large numbers with K/M/B/T, "mintick" rounds to the symbol's price step.

CODESCRIPT
if barstate.islast {
  label(close, str(close, "#.##"), barIndex)
}
plot(close)

Converts close to text with two decimals and places it as a label on the last bar.

strFormat(şablon, ...değerler)

Text with placeholders filled; behaves the same as text/format.

şablon
string
Text with {0} {1} or {} placeholders.
...değerler
any
Values to fill the placeholders.
NOTE

Another alias of text — the formatting behavior is identical.

CODESCRIPT
if barstate.islast {
  infoTable(strFormat("H:{0} L:{1}", high, low))
}
plot(close)

Joins high and low on one line and writes it into the panel.

strLength(metin)

The number of characters in the text (a number).

metin
string
The text whose length is requested.
NOTE

Returns 0 for an empty text.

CODESCRIPT
plot(strLength("merhaba"))

Since "merhaba" has 7 characters, it plots 7.

string(değer)

The same text if the input is text, or the na text if it is na.

değer
any
The value to convert to text (text or na only).
NOTE

Only accepts text/na; passing a number or boolean raises an error. Use str to turn a number/series into text.

CODESCRIPT
plot(strLength(string("merhaba")))

The text input is returned unchanged; its length 7 is plotted.

substring(metin, başla, bitir?)

The substring in the range [start, end).

metin
string
The text to slice.
başla
number
Start position (0-based).
bitir
number
Optional. End position (exclusive); if omitted, to the end.
NOTE

Positions are 0-based and end is excluded; if end is omitted it runs to the end of the text.

CODESCRIPT
plot(strLength(substring("merhaba", 0, 3)))

The first 3 characters ("mer") are taken; their length 3 is plotted.

text(template, ...values)

Text with the placeholders filled by the given values.

şablon
string
Text containing {0} {1} or sequential {} placeholders.
...değerler
any
Values to fill the placeholders (number/text/series).
NOTE

{0} fills by index, {} fills in order. A decimal is trimmed to at most 4 places; if a series is given its last valid value is written.

CODESCRIPT
if barstate.islast {
  infoTable(text("Kapanis: {0}", close))
}
plot(close)

On the last bar writes a "Kapanis: " line into the top-right panel.

CODESCRIPT
label(close, text("RSI {0}", rsi(close, 14)), 50)
plot(close)

Places a label at bar 50 embedding the RSI value.

toNumber(metin)

The numeric value of the text, or na if it cannot be converted.

metin
string
The text to convert to a number.
NOTE

Leading/trailing spaces are ignored. Invalid text does not raise an error, it returns na.

CODESCRIPT
plot(toNumber("3.14"))

Converts the text "3.14" to the number 3.14 and plots it.

toString(değer)

The text form of the value; behaves the same as str.

değer
any
The number, boolean or series to convert to text.
format
string
Optional. A format pattern (same as str).
NOTE

An alias of str — it accepts the same format options. May be preferred for readability.

CODESCRIPT
if barstate.islast {
  label(close, toString(rsi(close, 14)), barIndex)
}
plot(close)

Converts the RSI value to text and writes it as a label on the last bar.

trim(metin)

The text with leading and trailing whitespace removed.

metin
string
The text to trim.
NOTE

Only removes whitespace at the ends; interior spaces are kept.

CODESCRIPT
plot(strLength(trim("  ab  ")))

The edge spaces are stripped; the remaining "ab" has length 2, which is plotted.

upper(metin)

The text with all letters converted to uppercase.

metin
string
The text to uppercase.
NOTE

Handy for normalizing symbol names to a single form.

CODESCRIPT
if barstate.islast {
  label(close, upper("btc"), barIndex)
}
plot(close)

Places a label reading "BTC" on the last bar.