Write
Drawings and tables
Labels, lines, boxes, polylines and tables: objects a script places at exact coordinates, and how they behave on Tradequix.
Plots draw one value per bar. Drawings are objects you place yourself: a label at a price, a line between two points, a box around a range, a table pinned to a corner. Each is created with *.new(...) and can be changed later through the id it returns.
Labels and lines on the last bar#
A common pattern is to draw only once, on the last bar, so the object does not repeat on every bar of history.
//@version=6indicator("Last price label", overlay = true)hi = ta.highest(high, 50)lo = ta.lowest(low, 50)if barstate.islast line.new(bar_index - 50, hi, bar_index, hi, color = color.red, width = 2) line.new(bar_index - 50, lo, bar_index, lo, color = color.teal, width = 2) label.new(bar_index, hi, "50-bar high " + str.tostring(hi, format.mintick), style = label.style_label_down, color = color.red, textcolor = color.white) label.new(bar_index, lo, "50-bar low " + str.tostring(lo, format.mintick), style = label.style_label_up, color = color.teal, textcolor = color.white)bar_index counts bars from 0, so bar_index - 50 is fifty bars back.
Keeping one object up to date#
To keep a single object moving rather than creating a new one every bar, store its id in a var and update it:
//@version=6indicator("One moving label", overlay = true)var label tag = label.new(na, na, "")label.set_xy(tag, bar_index, close)label.set_text(tag, str.tostring(close, format.mintick))To remove objects, call label.delete(id), line.delete(id) and so on. Only objects that still exist at the end of the run are drawn.
Boxes#
//@version=6indicator("Range box", overlay = true)len = input.int(30, "Bars", minval = 5)if barstate.islast top = ta.highest(high, len) bottom = ta.lowest(low, len) box.new(bar_index - len + 1, top, bar_index, bottom, border_color = color.new(#8b7cff, 0), bgcolor = color.new(#8b7cff, 85))Tables#
A table is a grid pinned to a corner of the chart or pane: good for a dashboard of current values.
//@version=6indicator("Dashboard", overlay = true)r = ta.rsi(close, 14)a = ta.atr(14)var table t = table.new(position.top_right, 2, 3, bgcolor = color.new(#100e18, 0), border_width = 1, border_color = color.new(#3a3352, 0))if barstate.islast table.cell(t, 0, 0, "Close", text_color = color.gray) table.cell(t, 1, 0, str.tostring(close, format.mintick), text_color = color.white) table.cell(t, 0, 1, "RSI 14", text_color = color.gray) table.cell(t, 1, 1, str.tostring(r, "#.0"), text_color = r > 70 ? color.red : r < 30 ? color.teal : color.white) table.cell(t, 0, 2, "ATR 14", text_color = color.gray) table.cell(t, 1, 2, str.tostring(a, format.mintick), text_color = color.white)Cells are addressed (column, row), both from 0.
Polylines and linefills#
polyline.new(points) draws a path through an array of chart.points, optionally curved or closed and filled. linefill.new(line1, line2, color) shades between two lines. Both are supported.
Coordinates#
- By default the x coordinate is a bar index. Pass
xloc = xloc.bar_timeto use a time in milliseconds instead, for exampletimeor a value fromtimestamp(...). - In a pane script, drawings sit in that pane. Add
force_overlay = trueto put one on the price chart. - Drawings count toward the chart's autoscale, so a label far above price widens the scale to show it.