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.
Two phases of execution
Every custom indicator script has two distinct execution phases:Top-level code runs once. Per-bar computation goes inside
onBar. Mixing them up is the most common mistake new authors make.The i argument
onBar receives a single argument i - the current bar index (0 = oldest bar in the window, ctx.length - 1 = newest). It is equivalent to calling ctx.i() inside the callback.
What belongs where
| Top level (runs once) | Inside onBar (runs per bar) |
|---|---|
input.* declarations | plot(name, value) - writing values |
plot(name, null, opts) - series registration | ta.* calculations |
Series(name) creation | Entity .set() / .delete() calls |
hline(value, opts) | bgcolor / barcolor calls |
Line/Box/Label/Marker initial creation | console.log for per-bar debugging |
Side-effect ordering
- All
input.*values are resolved from the Inputs panel (or defaults). - All
plot(name, null, opts)calls register plot series. onBarcallback is registered but not yet invoked.- The runtime replays all historical bars, calling
onBar(i)for each in ascending bar-index order. - On each realtime update,
onBar(i)is called again for the current bar.
Minimal template
Related pages
Inputs
All input types and the form controls they produce.
Bar context
ctx.open, ctx.close, ctx.i, ctx.isLast and friends.
Series
Persistent indexed storage across bars.
Plot basics
How to register and emit plot values.