Skip to content
ChartDeck ChartScript docs Account Open the terminal

Legend items

Showing status text, color keys and badges in the script's legend row with legend.info, legend.key and legend.badge.

Every study has a row in the chart's legend: its name, its settings and its values. A script can add items to that row, as ChartDeck's own studies do: a status ("updated 13:00 UTC"), a color key ("▬ longs ▬ shorts"), or a badge ("Model estimate").

FunctionShows
legend.info(text, tooltip, warn, priority)muted text after a dot; warn = true in the warning color
legend.key(text, color, palette, dashed, group, priority)a swatch and its text; palette (a heatmap.palette_*) shows that palette's gradient
legend.badge(text, tooltip, warn)a small outlined badge at the end of the row

The row shows the items of the newest bar: call them on every bar, or only if (barstate.islast). Each run of the newest bar (a live update) replaces them.

ChartScriptOpen in editor
//@chartscript 1
indicator("Trend with a key", { overlay: true })
const fast = ta.ema(close, 20)
const slow = ta.ema(close, 50)
plot(fast, "Fast", color.up)
plot(slow, "Slow", color.down)
if (barstate.islast) {
    legend.key("fast", color.up)
    legend.key("slow", color.down)
    legend.info(fast > slow ? "uptrend" : "downtrend", "The fast average against the slow one")
    if (volume == 0) {
        legend.badge("No volume", "This market reports no volume.", true)
    }
}

#When the row is narrow

On a small pane the legend drops items: the ones with the highest priority number first (3 before 2; 1 is always kept), and of equal priority the last one first. Keys with the same group go together. The defaults are 2 for legend.info, 3 for legend.key and 1 for a badge. The full text of every item is the tooltip of the row's info part.

#Limits

At most 24 items a script, each at most 120 characters. Items are ignored inside a request expression (CS3120 when called from one).

The ChartScript documentation is in English for now; translations will follow.