Drawing
Times are unix seconds (barTime()), colors come from rgba(...) or color.*.
Stateless and keyed drawings
Every drawing function takes an optional id:
- No id: a one-off drawing. On a live chart it is redrawn with each run of the current bar.
- With an id: a stateful drawing. Drawing the same id again moves or updates
it;
draw.remove(id)deletes it. Use this for anything that follows price, such as a zone or a trailing level.
A drawing anchored at a na price is skipped.
Simple drawings
draw.marker(barTime(), src.low[0], Shape.ArrowUp, color.green);
draw.line(t1, p1, t2, p2, color.red, 2, Stroke.Dashed, "level");
draw.box(t1, top, t2, bottom, color.withTransp(color.blue, 80));
draw.label(barTime(), src.high[0], "High", color.white, color.black, true);
draw.remove("level");
Full drawing model
draw.lineEx, draw.boxEx and draw.labelEx return builders with every
option. Finish them with .draw(id, pane):
draw.boxEx(t - 3600, low, t, high)
.fill(color.withTransp(color.blue, 85))
.border(color.blue, 1, Stroke.Dashed)
.extend(Extend.Right)
.text("Order block", color.white, Size.Small, Align.Left, Align.Top)
.draw("ob_1");
draw.lineEx(t1, level, t2, level)
.color(color.red)
.style(Stroke.ArrowRight)
.extend(Extend.Right)
.label("BOS", 1.0, color.red)
.draw("bos");
draw.labelEx(t, src.high[0], "Divergence")
.textColor(color.white)
.bg(color.red)
.size(Size.Small)
.style(LabelStyle.LabelDown)
.yloc(YLoc.AboveBar)
.draw("div", "rsi"); // second argument: draw in the "rsi" pane
Plus draw.polyline(times, prices, color, width, curved, closed, id, pane) and
draw.circle(time, price, radiusPx, fill, id, pane).
The chart's own drawing tools
draw.shapeEx(name) places one of the tools the chart already has — a callout,
a price label, a Fibonacci retracement — instead of rebuilding its appearance
out of lines and labels:
draw.shapeEx("callout")
.point(src.time[10], src.high[10])
.point(src.time[0], src.high[0])
.str("text", "supply")
.color("textColor", rgba(38, 166, 154))
.draw("ob1");
Three things to know before reaching for it:
- The point count is the TOOL's. A price label takes one, a callout two, a Fibonacci retracement three. The SDK cannot check this — the arity lives with the host's template — so the host validates and rejects a mismatch. Getting it wrong is an error, not a silent miss.
- Property names are the tool's own (
textColor,backgroundColor,lineColor…) and are not uniform between tools. A Fibonacci tool carries per-level colours that a singlelineColorwill not touch. - Which names are accepted is the host's business. Tools that have their own host-side API — order lines, positions — are normally refused, because a script and the host would then both own one object.
The drawing stays the script's: locked, not persisted, and cleared with the rest of the script's drawings. It is not a user drawing, and the user cannot edit it.
| Enum | Values |
|---|---|
Shape | Circle Square Triangle TriangleDown ArrowUp ArrowDown Cross XCross Flag Diamond LabelUp LabelDown |
Stroke | Solid Dashed Dotted ArrowLeft ArrowRight ArrowBoth |
Extend | None Left Right Both |
LabelStyle | None LabelUp LabelDown LabelLeft LabelRight LabelLowerLeft LabelLowerRight LabelUpperLeft LabelUpperRight LabelCenter TextOutline |
Size | Tiny Small Normal Large Huge |
Align | Left Center Right Top Bottom |
YLoc | Price AboveBar BelowBar |
A script can emit at most 500 drawings per bar and keep at most 500 of each kind on the chart; the oldest are removed first.