Skip to main content

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

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 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].