Skip to content

draw ​

Lines, labels and boxes a script places at chart coordinates (TradingView line.new, label.new, box.new). Create them in a handler such as event.onCandle and keep the ids to move or delete them later.

NameDescription
draw.line()Adds a line and returns its id.
draw.label()Adds a label and returns its id.
draw.box()Adds a box and returns its id.
draw.set()Changes some properties of an existing object (e.g.
draw.remove()Deletes one object.
draw.clear()Deletes every object.

draw.line() ​

ts
draw.line(options: DrawLineOptions): number

Adds a line and returns its id.

Types: DrawLineOptions

draw.label() ​

ts
draw.label(options: DrawLabelOptions): number

Adds a label and returns its id.

Types: DrawLabelOptions

draw.box() ​

ts
draw.box(options: DrawBoxOptions): number

Adds a box and returns its id.

Types: DrawBoxOptions

draw.set() ​

ts
draw.set(id: number, patch: Partial<DrawLineOptions & DrawLabelOptions & DrawBoxOptions>): boolean

Changes some properties of an existing object (e.g. moves a line's end). Returns false if the id is gone.

Types: DrawLineOptions, DrawLabelOptions, DrawBoxOptions

draw.remove() ​

ts
draw.remove(id: number): boolean

Deletes one object. Returns false if the id is gone.

draw.clear() ​

ts
draw.clear(): void

Deletes every object.

Types ​

DrawLineOptions ​

A line between two chart points. x values are bar times in ms (e.g. candle.time.at(5)), y values prices.

FieldTypeDescription
x1number
y1number
x2number
y2number
color?string
width?number
style?"solid" | "dashed" | "dotted"
extend?"none" | "left" | "right" | "both"extend past the points: "none" (default), "left", "right" or "both"

DrawLabelOptions ​

A text label at a chart point; style is where its pointer goes: "down" sits above the point, "up" below it.

FieldTypeDescription
xnumber
ynumber
text?string
color?string
textColor?string
style?"up" | "down" | "left" | "right" | "none"
size?"tiny" | "small" | "normal" | "large"

DrawBoxOptions ​

A rectangle between two times and two prices, optionally with text inside.

FieldTypeDescription
leftnumber
topnumber
rightnumber
bottomnumber
color?string
bgColor?string
width?number
style?"solid" | "dashed" | "dotted"
text?string
textColor?string

AlphaScript language v0.1 · runtime 0.2.0