Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.darvas.app/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The str namespace provides a set of string helpers. All functions are pure (no side effects) and available globally as str.*. Use them primarily for console.log formatting or building label text for Label entities.

Function reference

FunctionReturnsDescription
str.format(template, ...args)stringPrintf-style formatting
str.length(s)numberCharacter count
str.substring(s, start, len)stringExtract a portion
str.contains(s, substring)booleanSubstring presence check
str.split(s, sep)string[]Split into array
str.upper(s)stringConvert to upper case
str.lower(s)stringConvert to lower case
str.trim(s)stringRemove leading/trailing whitespace

str.format - placeholder syntax

str.format uses {} placeholders, filled left-to-right from the remaining arguments:
const msg = str.format("RSI: {} | EMA: {}", 72.4, 42300);
// "RSI: 72.4 | EMA: 42300"

const priceLabel = str.format("{} @ {}", ctx.instId, math.round(ctx.close(), 2));
// "BTC-USDT-SWAP @ 67832.14"

Practical example

const src = input.source("Source", "close");

onBar(() => {
  const rsi = ta.rsi(src, 14);
  if (na(rsi)) return;

  if (ctx.isLast()) {
    const label = str.format(
      "RSI({}) = {} | {}",
      14,
      math.round(rsi, 1),
      rsi > 70 ? "OB" : rsi < 30 ? "OS" : "Neutral"
    );
    console.log(label);
  }

  plot("RSI", rsi);
});

Splitting instrument IDs

// ctx.instId = "BTC-USDT-SWAP"
const parts = str.split(ctx.instId, "-");
const base  = parts[0]; // "BTC"
const quote = parts[1]; // "USDT"
const kind  = parts[2]; // "SWAP"

Case conversion

const upper = str.upper("hello"); // "HELLO"
const lower = str.lower("WORLD"); // "world"
const trimmed = str.trim("  foo  "); // "foo"
For the full list of available str.* functions, see the custom indicator spec. The table above covers the most commonly used subset.

math.*

Numeric utilities - use with str.format for formatted labels.

Label entity

Display formatted text on the chart canvas.