ChartnautDocs

Drawings and overlays

Two ways to put your own marks on a chart:

Drawings (chart.draw)

Overlays (chart.overlays)

What they are

The chart's own drawing tools: a line looks and behaves like one the person drew

Your data, drawn by the chart: many points at once

Saved

Yes, with the chart, like the person's own

Never. Gone when the terminal reloads

The person can

Select and move them, unless you lock them

Only look at them

Use them for

A stop line, a zone to watch, a note

Signals from your database, a series of levels, your own indicator's line

Drawings

import { createTerminal } from "@chartnaut/charts";

const terminal = createTerminal(document.getElementById("terminal")!, {
  charts: { main: { symbol: "NAS100", timeframe: "15m" } },
});
const main = terminal.chart("main");

async function mark() {
  const stop = await main.draw.hline(21480, { text: "Stop", style: { color: "#f43f5e", line_style: "dashed" }, locked: true });
  await main.draw.zone({ time: 1789462800, price: 21540 }, { time: 1789471800, price: 21510 }, { style: { fill: "rgba(59,130,246,0.15)" } });
  await main.draw.markers([
    { time: 1789466400, price: 21512, text: "Entry", style: { shape: "arrow_up" } },
    { time: 1789470000, price: 21590, text: "Exit", style: { shape: "arrow_down" } },
  ]);
  await stop.update({ points: [{ price: 21495 }] }); // move it
}
mark();

Call

Draws

draw.hline(price), draw.vline(time)

A horizontal or vertical line

draw.line(a, b), draw.ray(a, b), draw.arrow(a, b)

Between two points

draw.rect(a, b), draw.zone(a, b)

A box; a zone has a fill and no border

draw.fib(a, b)

A Fibonacci retracement

draw.text(at, text), draw.priceLabel(at)

Text at a point

draw.marker(at), draw.markers([...])

A dot or an arrow; many in one call

draw.many([...])

Any kinds in one call. One bad drawing refuses them all

A point is { time, price }, with time in unix seconds, a Date or ISO text with an offset. Each call returns a handle with update, remove and select. Give a drawing your own id to find it after a reload with chart.drawings.handle(id), and clientId so a retry never draws twice.

The person's drawings

import { createTerminal } from "@chartnaut/charts";

const terminal = createTerminal(document.getElementById("terminal")!, {
  charts: { main: { symbol: "NAS100", timeframe: "15m" } },
});
const main = terminal.chart("main");

main.drawings.on("created", (e) => {
  if (e.data.by === "user") console.log("They drew", e.data.drawing?.kind, e.data.drawing?.points);
});

async function tidy() {
  const all = await main.drawings.get();
  console.log(all.length, "drawings");
  await main.drawings.clear({ onlyMine: true }); // only yours, the person's stay
}
tidy();

get lists every drawing on the chart with by: "user" or by: "app". Events: created, updated, removed, selected.

Overlays

import { createTerminal } from "@chartnaut/charts";

const terminal = createTerminal(document.getElementById("terminal")!, {
  charts: { main: { symbol: "NAS100", timeframe: "5m" } },
});

async function showSignals() {
  const signals = await terminal.chart("main").overlays.add(
    "markers",
    [
      { time: 1789466400, price: 21512, text: "Long" },
      { time: 1789470000, price: 21590, text: "Flat" },
    ],
    { style: { color: "#22c55e" } },
  );
  await signals.append([{ time: 1789471800, price: 21600, text: "Long" }]);
}
showSignals();

Four kinds: markers (time, price, text), line (time, value, up to 5,000 points), levels (price, optionally from and to) and zones (from, to, top, bottom). update replaces the data, append adds to it, remove takes it off.