Skip to main content
Functions for manipulating and working with text strings in your indicators.

split()

Split a string into an array using a delimiter.

Signature

split(text: string, delimiter: string): string[]

Parameters

ParameterTypeDescription
textstringThe string to split
delimiterstringCharacter(s) to split on

Example

var parts = split("BTC-USDT", "-");
// Returns ["BTC", "USDT"]

var words = split("Hello World", " ");
// Returns ["Hello", "World"]

concat()

Concatenate multiple strings together.

Signature

concat(str1: string, str2: string, ...): string

Parameters

ParameterTypeDescription
str1, str2, ...stringStrings to concatenate

Example

var combined = concat("BTC", "-", "USDT");
// Returns "BTC-USDT"

var label = concat("Price: ", "45000");
// Returns "Price: 45000"

substring()

Extract a portion of a string.

Signature

substring(text: string, start: number, end?: number): string

Parameters

ParameterTypeDescription
textstringThe source string
startnumberStart index (0-based)
endnumberEnd index (optional)

Example

var result = substring("BTCUSDT", 0, 3);
// Returns "BTC"

var result = substring("BTCUSDT", 3);
// Returns "USDT"

length()

Get the length of a string.

Signature

length(text: string): number

Example

var len = length("BTCUSDT");
// Returns 7

toUpperCase()

Convert string to uppercase.

Signature

toUpperCase(text: string): string

Example

var upper = toUpperCase("btcusdt");
// Returns "BTCUSDT"

toLowerCase()

Convert string to lowercase.

Signature

toLowerCase(text: string): string

Example

var lower = toLowerCase("BTCUSDT");
// Returns "btcusdt"

includes()

Check if a string contains a substring.

Signature

includes(text: string, search: string): boolean

Example

var hasUSD = includes("BTCUSDT", "USD");
// Returns true

var hasBNB = includes("BTCUSDT", "BNB");
// Returns false

replace()

Replace occurrences of a substring.

Signature

replace(text: string, search: string, replacement: string): string

Example

var result = replace("BTC-USD", "-", "/");
// Returns "BTC/USD"

Practical Examples

Symbol Parsing

//@version=2

define(title="Symbol Info", position="onchart", axis=false);

// Parse symbol components
var parts = split(currentSymbol, "-");
var base = parts[0];   // "BTC"
var quote = parts[1];  // "USDT"

var symbolLabel = concat(base, "/", quote);
// Use in labels or display

Dynamic Labels

//@version=2

define(title="Dynamic RSI", position="offchart", axis=true);

var period = input(name="period", type="number", defaultValue=14, label="Period");
timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var rsiValue = rsi(source=ohlcvData.close, period=period);

// Create dynamic label
var labelText = concat("RSI (", period, ")");

plotLine(value=rsiValue, width=2, colors=["purple"], label=[labelText], desc=["Relative Strength Index"]);

Exchange Detection

//@version=2

define(title="Exchange-Aware Indicator", position="offchart", axis=true);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

// Check exchange for specific handling
var isBinance = includes(currentExchange, "BINANCE");
var isCoinbase = includes(currentExchange, "COINBASE");

// Adjust parameters based on exchange
var period = isBinance ? 14 : 20;
var rsiValue = rsi(source=ohlcvData.close, period=period);

plotLine(value=rsiValue, width=2, colors=["blue"], label=["RSI"], desc=["Exchange-adjusted RSI"]);

Tips

String Immutability

Strings in kScript are immutable. Operations like concat() and replace() return new strings.

Case Sensitivity

String comparisons are case-sensitive. Use toUpperCase() or toLowerCase() for case-insensitive comparisons.

Symbol Formats

Different exchanges use different symbol formats. Use string functions to normalize symbols across exchanges.