Appearance
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.
| Name | Description |
|---|---|
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): numberAdds a line and returns its id.
Types: DrawLineOptions
draw.label()
ts
draw.label(options: DrawLabelOptions): numberAdds a label and returns its id.
Types: DrawLabelOptions
draw.box()
ts
draw.box(options: DrawBoxOptions): numberAdds a box and returns its id.
Types: DrawBoxOptions
draw.set()
ts
draw.set(id: number, patch: Partial<DrawLineOptions & DrawLabelOptions & DrawBoxOptions>): booleanChanges 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): booleanDeletes one object. Returns false if the id is gone.
draw.clear()
ts
draw.clear(): voidDeletes 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.
| Field | Type | Description |
|---|---|---|
x1 | number | |
y1 | number | |
x2 | number | |
y2 | number | |
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.
| Field | Type | Description |
|---|---|---|
x | number | |
y | number | |
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.
| Field | Type | Description |
|---|---|---|
left | number | |
top | number | |
right | number | |
bottom | number | |
color? | string | |
bgColor? | string | |
width? | number | |
style? | "solid" | "dashed" | "dotted" | |
text? | string | |
textColor? | string |
