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.

1. Open the indicator editor

In Darvas, open /terminal, click Add indicator in the chart sidebar, and select Custom indicator. The script editor opens with a default template.

2. Paste this script

const len = input.int("Length", 14);
const src = input.source("Source", "close");

plot("MA", null, { color: "#22c55eFF", linewidth: 2 });
plot("Diff", null, { color: "#a78bfaFF", style: "histogram" });

onBar(() => {
  const ma = ta.sma(src, len);
  plot("MA", ma);
  plot("Diff", ctx.close() - ma);
});

3. Click “Add to chart”

The script runs against the visible bars. You will see two new series on your chart pane: a moving average overlay (MA) and a histogram of the close-minus-MA distance (Diff).

4. Iterate

Edit the script, change len from 14 to 50, click Add to chart again. The chart redraws with the new parameter. Your draft lives in the browser until you save it.

Anatomy of the script

// Top-level: runs ONCE when the script is loaded.
const len = input.int("Length", 14);    // user-tweakable parameter
plot("MA", null, { color: "#22c55eFF" }); // declare a series and its style

// onBar: runs ONCE PER BAR. This is where computation happens.
onBar(() => {
  const ma = ta.sma(src, len);   // compute SMA at this bar
  plot("MA", ma);                // emit the value for this bar
});
Top-level state (the consts above) persists across bars via JavaScript closures. onBar reads them on every bar.
Top-level code runs once. onBar runs per bar. If you compute something in the top-level body that depends on ctx.close(), it will be the close at script-init time (usually the first bar) - almost never what you want. Put per-bar logic inside onBar.

Where to next

Editor walkthrough

Tour the script editor and inputs panel.

Plot styles

Histogram, area, arrows, circles, and more.

Drawing entities

Persistent S/R lines, FVG boxes, order blocks.

Series and history

Access prior-bar values like Pine’s x[1].