Charts
Concepts

Outputs

Show values in the legend, send alerts and log to the console.

Legend

legend returns the values shown in the script's indicator list entry, and in the status line at the crosshair:

legend: (s, crosshairTime, ctx) => {
  const point = crosshairTime === null ? s.points.at(-1) : s.points.findLast((p) => p.time <= crosshairTime);

  return point ? [{ label: "VWAP", value: point.vwap.toFixed(2), color: "#f59e0b" }] : [];
},

crosshairTime is the bar time under the crosshair, null without crosshair: show the latest values then.

The list also shows the script's errors and its time per frame (handler and draw, mean over the last second).

Alerts

ctx.alert(message) shows a toast and plays a sound. History replays through the same handlers, so alert only live:

if (ctx.phase === "Live") ctx.alert(`Whale ${trade.size} at ${trade.price}`);

Console

ctx.log(...values) writes a line to the editor's Console panel. Errors the runtime caught show there too.

Axis labels

Chart surfaces can put labels on the axes from draw: g.priceLabel(price, text, background, textColor) and g.timeLabel(time, text, background, textColor).

On this page