Text
23 entries. What each one takes, what it returns, and a working example.
Adds transparency to a color (alpha 0..100).
A color in #rrggbbaa form with the opacity applied.
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.
plot(close, color=color("#26a69a", 0.5))
Plots price in a half-transparent green (#26a69a80).
Whether the text contains the substring (true/false).
true if part occurs anywhere in the text, otherwise false.
Note
Case sensitive. For classifying text such as a symbol name or a session label.
plot(iff(contains("BTCUSDT", "USD"), 1, 0))
Since "BTCUSDT" contains "USD", it plots 1.
Whether the text ends with the suffix. Result: True
true if the text ends with that suffix, otherwise false.
Note
Case sensitive. Handy for spotting a quote currency (…USDT).
plot(iff(endsWith("BTCUSDT", "USDT"), 1, 0))
Since "BTCUSDT" ends with "USDT", it plots 1.
Formats a template string ('{0}'/'{1}'/'{}'). Result: 1-2
Text with placeholders filled; behaves the same as text.
Note
An alias of text. {0} fills by index, {} in order; a decimal is trimmed to at most 4 places.
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.
Converts epoch time to a 'YYYY-MM-DD HH:MM' (UTC) string.
A date-time text in "YYYY-MM-DD HH:MM" form (UTC); an empty text on invalid input.
Note
Auto-detects a seconds or milliseconds stamp. Output is in UTC. For showing a time on a label/panel.
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)
Color gradient between two colors by value.
A color blended between the two colors by mapping value across [lo,hi] (a color series if a series is given).
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.
plot(close, color=gradient(rsi(close, 14), 30, 70, "#ef5350", "#26a69a"))
Colors price red near RSI 30 and green near 70.
Gives the position where a piece starts inside a text, or -1 when it is not there. ⚠ Check for -1 before using the result, otherwise you cut from the wrong place when the piece is missing.
The position of the first occurrence of part (0-based), or -1 if not found.
Note
Positions count from 0. A not-found result is signalled by -1.
plot(indexOf("hello", "h"))
Since "h" is at position 3 in "merhaba", it plots 3.
Converts to lowercase. Result: btc
The text with all letters converted to lowercase.
Note
To compare case-insensitively, normalize both sides with lower.
if barstate.islast { label(close, lower("MERHABA"), barIndex) } plot(close)
Places a label reading "merhaba" on the last bar.
First match against the regex pattern (empty string if none). Result: 123
The FIRST substring matching the pattern, or an empty text if there is no match.
Note
Returns only the first match. Can be paired with toNumber to extract a number or pattern from text.
plot(toNumber(regexMatch("abc123def", "[0-9]+")))
The first digit block "123" is extracted, converted to a number, and plotted.
Repeats the text n times. Result: ==========
The text written n times in a row.
Note
If n is zero or negative it returns an empty text. Handy for a simple progress bar / separator strip.
plot(strLength(repeat("ab", 3)))
"ab" is repeated 3 times ("ababab"); its length 6 is plotted.
Replaces the first match. Result: a+b-c
The text with only the FIRST match replaced.
Note
Replaces only the first match; use replaceAll for every match.
if barstate.islast { label(close, replace("aXbXc", "X", "-"), barIndex) } plot(close)
The first X is replaced; the label reads "a-bXc".
Replaces every match inside a text with a new piece — all of them, not just the first. Used to change a decimal separator or to clean up a text.
The text with every match replaced.
Note
Replaces all matches; use replace to change only the first.
if barstate.islast { label(close, replaceAll("aXbXc", "X", "-"), barIndex) } plot(close)
All X's are replaced; the label reads "a-b-c".
Whether the text starts with the prefix. Result: True
true if the text starts with that prefix, otherwise false.
Note
Case sensitive.
plot(iff(startsWith("BTCUSDT", "BTC"), 1, 0))
Since "BTCUSDT" starts with "BTC", it plots 1.
Does the same job as `toString`, under a shorter name. Turns a number or a series into text; given a series it produces text for each bar.
The text form of the value; if a series is given, an element-wise text series. na → "NaN".
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.
When to use
To write a numeric value onto a label, panel or table — to turn it into text before joining with fixed text.
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.
Same as format().
Text with placeholders filled; behaves the same as text/format.
Note
Another alias of text — the formatting behavior is identical.
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.
Gives the number of characters in a text. Used when splitting a text into pieces or checking whether it fits in a panel.
The number of characters in the text (a number).
Note
Returns 0 for an empty text.
plot(strLength("hello"))
Since "merhaba" has 7 characters, it plots 7.
Type conversion: text and na only (na is preserved). Use str.tostring to convert a number/bool to text.
The same text if the input is text, or the na text if it is na.
Note
Only accepts text/na; passing a number or boolean raises an error. Use str to turn a number/series into text.
Not for
Not for converting a number or boolean to text — use str (or toString) for that.
plot(strLength(string("hello")))
The text input is returned unchanged; its length 7 is plotted.
Cuts a piece out of a text, from a start position to an end position. Positions start at zero and the end position is not included. Used to take the first letters of a symbol name or to split a number.
The substring in the range [start, end).
Note
Positions are 0-based and end is excluded; if end is omitted it runs to the end of the text.
plot(strLength(substring("hello", 0, 3)))
The first 3 characters ("mer") are taken; their length 3 is plotted.
Formats values into text (for labels/tables).
Text with the placeholders filled by the given values.
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.
When to use
To embed a numeric value into a label, panel or table — for combining fixed text with a live value on one line.
if barstate.islast { infoTable(text("Close: {0}", close)) } plot(close)
On the last bar writes a "Kapanis:
label(close, text("RSI {0}", rsi(close, 14)), 50) plot(close)
Places a label at bar 50 showing the RSI value.
Converts text to a number. The WHOLE text must match number syntax (optional sign, decimal point, exponent: 42 / -2.5 /.5 / 1e3). Anything else returns an empty value: "1,5" (comma is not accepted as a decimal separator - use a dot), "12abc", "0x10", empty text. Check with na().
Note
Leading/trailing spaces are ignored. Invalid text does not raise an error, it returns na.
plot(toNumber("3.14"))
Converts the text "3.14" to the number 3.14 and plots it.
Turns a number into text, which you need to show it in a panel or a label. The second value sets the format (`"#.##"` for two decimals). ⚠ The format is not language aware: the decimal separator is a dot and no thousands separator is added — for local formatting you have to arrange the text yourself.
The text form of the value; behaves the same as str.
Note
An alias of str — it accepts the same format options. May be preferred for readability.
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.
Trims leading/trailing whitespace.
The text with leading and trailing whitespace removed.
Note
Only removes whitespace at the ends; interior spaces are kept.
plot(strLength(trim(" ab ")))
The edge spaces are stripped; the remaining "ab" has length 2, which is plotted.
Converts to uppercase. Result: BTC
The text with all letters converted to uppercase.
Note
Handy for normalizing symbol names to a single form.
if barstate.islast { label(close, upper("btc"), barIndex) } plot(close)
Places a label reading "BTC" on the last bar.
Position of the substring, na if not found. Indexing starts at 0.
The position of the first occurrence of the part (0-based), or na if not found.
Note
Positions count from 0. The only difference from `indexOf` is the not-found case: `strPos` returns na, `indexOf` returns -1. Use `strPos` when you test the result with `na(...)`, because -1 is not na and that test would always be wrong.
strPos("BTCUSDT", "USD")
Finds where "USD" starts inside "BTCUSDT"; it draws nothing and returns the position.
Turns a number into text using local writing: the thousands and decimal separators follow the user's language (`2,505.18` in English, `2.505,18` in Turkish). The second value does two jobs — pass text to pick the region (`"tr"` / `"en"`), or a number to set how many decimals to show. Pass nothing and the region comes from the user's language while the decimals come from the number itself. ⚠ `toString` does not do this: it always writes a dot decimal and no thousands separator.
The number as text, written the local way.
Note
⚠ `toString` does NOT do this and should not: it matches the reference language — always a dot decimal, no thousands separator. Use this one when you want a readable number in a panel or a label. Rounding is half-up: 2.675 to two decimals gives 2.68.
price = 2505.18 alert(formatNumber(price)) alert(formatNumber(price, "en")) alert(formatNumber(price, 4))
Formats a number for reading and sends it as an alert; the thousands separator and the number of decimals can be set.