Guides

Plotting

Where things are drawn#

E948 is raised when:

Unknown named options of a drawing function are ignored.

Colors#

FormExample
Hexadecimal literal#26a69a, #26a69a80 (last two digits = opacity, 00 transparent to ff opaque)
rgb(r, g, b, transparency = 0)rgb(38, 166, 154); r, g, b from 0 to 255, transparency from 0 (opaque) to 100
alpha(color, opacity)alpha(#26a69a, 30): opacity from 0 to 100
mix(c1, c2, t)mix(#26a69a, #ef5350, 0.5): t from 0 (c1) to 1 (c2)
A settinginput.color("Up", #26a69a)

na as a color means "nothing" on that bar for fill, bg_color and bar_color. Values outside the ranges are clamped; alpha and mix on something that is not a color give E928.

Series: plot, histogram, candle, fill#

FunctionSignatureNotes
plotplot(value, color?, color:, title:, width:, style:) → handleThe color may change on every bar. style: is "solid" (default), "dashed", "dotted", "step", "circles", "cross", "area" or "columns"; an unknown style draws a solid line. na leaves a gap.
histogramhistogram(value, color?, color:, title:) → handleBars starting from 0.
candlecandle(o, h, l, c, color?, color:) → handleA candle series.
fillfill(p1, p2, color?), fill(p, 0, color), fill(p, h) with h = hline(…)Fills between two plots, or between a plot and a value. The color may change per bar; na fills nothing on that bar. Any other form gives E926.

The title appears in the legend and in the Settings tab, where the user can change each plot's color, width and style, or hide it.

StrateScript
indicator "EMA cloud" { overlay: true }
fast = ema(close, 9)
slow = ema(close, 21)
pf = plot(fast, #26a69a, title: "Fast", width: 2)
ps = plot(slow, #ef5350, title: "Slow", style: "dashed")
fill(pf, ps, fast > slow ? #26a69a30 : #ef535030)
StrateScript
indicator "Absorbed volume" { overlay: false }
absorbed = volume - abs(delta)
p = plot(absorbed, #2962ff, title: "Absorbed")
fill(p, 0, #2962ff20)
plot(ema(close, 20), #e8c15a, title: "EMA", overlay: true)
marker(absorbed > stats.percentile(absorbed, 100, 90), shape: "diamond", location: "below", overlay: true)

Lines and backgrounds: hline, level, bg_color, bar_color#

FunctionSignatureNotes
hlinehline(value, color:, style:, width:, text:) → handleA horizontal line. Does not change the automatic scale. na draws nothing.
levellevel(price, color:, text:) → handleA horizontal line that is part of the automatic scale.
bg_colorbg_color(color)Background of the bar's column. na = none.
bar_colorbar_color(color)Color of the bar's candle.
StrateScript
indicator "Session shading" { overlay: true }
bg_color(session.rth ? na : #ffffff06)
bar_color(delta > 0 ? #26a69a : #ef5350)
level(prev.close, color: #e8c15a, text: "prev close")

Markers#

Text
marker(condition, shape:, location:, price:, color:, size:, text:, tip:)
StrateScript
indicator "Cross markers" { overlay: true }
fast = ema(close, 9)
slow = ema(close, 21)
marker(crossover(fast, slow), shape: "arrow_up", location: "below", color: #26a69a, text: "X", tip: "cross at " + str(close, "0.00"))
marker(crossunder(fast, slow), shape: "arrow_down", location: "above", color: #ef5350)
marker(volume > 2 * sma(volume, 50), location: "price", price: close, shape: "circle", size: "small", color: #e8c15a)

Objects: line.new, box.new, label.new#

Objects are created once and can then be moved, changed or deleted. They are the right tool for zones and lines that extend over time.

ConstructorSignature
line.newline.new(t1, p1, t2, p2, color:, width:, style:, glow:, pulse:)
box.newbox.new(t1, top, t2, bottom, color:, border:, text:, text_color:, fade: "left" \| "right", glow:)
label.newlabel.new(t, price, text, color:, bg:, text_color:, glow:, pulse:)
StrateScript
indicator "Session box" { overlay: true }
state zone = na
if session.is_new or na(zone) {
  zone = box.new(bar.time, high, bar.time, low, color: #35CE0020, border: #35CE00, fade: "left", glow: 10)
}
zone.set_right(bar.time)
zone.set_top(max(zone.price1, high))
zone.set_bottom(min(zone.price2, low))

Tables#

Text
t = table.new(position, columns, rows, bg:, border:, frame:, text_color:, size:)
t.cell(col, row, text, text_color:, bg:, size:, align:)
StrateScript
indicator "Bar table" { overlay: true }
state t = table.new("top_right", 2, 2, bg: #101010, text_color: #ffffff)
if bar.last {
  t.cell(0, 0, "Delta", align: "left")
  t.cell(1, 0, str(delta, "+0"), text_color: delta > 0 ? #22c55e : #ef4444)
  t.cell(0, 1, "Volume", align: "left")
  t.cell(1, 1, str(volume, "0.0k"))
}

Drawing inside a bar's column#

These functions draw at a price inside the column of a bar, which is how footprint-style displays are built. Horizontal positions x: and w: are fractions of the bar's width (0 = left edge, 1 = right edge).

FunctionSignatureNotes
cellcell(price, text, side:, bg:, color:, size:, ticks:, bar:, col:, cols:, x:, w:, tip:)A cell one row high (or ticks: rows). side: "left", "right" or "full" (default; E927 otherwise). col: k, cols: n uses the k-th of n sub-columns (E936 if out of range). bar: targets an earlier bar by index.
hbarhbar(price, value, max, side:, width:, color:, ticks:, bar:, col:, cols:, x:, w:, tip:)A horizontal bar of length value / max of width bars (default 1). side default "left". Nothing when max ≤ 0 or na.
draw.rectdraw.rect(low, high, x:, w:, fill:, border:, radius:, tip:) or draw.rect(price, ticks: n, …)A rectangle between two prices, or n rows from a price.
draw.textdraw.text(price, text, x: 0.5, align: "center", color:, size: 11, bold:, ticks:, tip:)align: "left", "center", "right" (E937 otherwise).
draw.linedraw.line(p1, p2, x1: 0, x2: 1, color:, width: 1, style:)A segment inside the column.
draw.candledraw.candle(o, h, l, c, x: 0.4, w: 0.2, color:, wick:)A candle inside the column.
candle(…, x:, w:, wick:)The same, drawn bar by bar like draw.candle. It returns na, not a handle.

chart.row_ticks(min_px) and chart.columns(min_px) adapt the layout to the zoom: rows of a round number of ticks at least min_px high, and the number of columns of at least min_px that fit in a bar (see Market data).

StrateScript
indicator "Bar columns" { overlay: true, candles: false }
draw.candle(open, high, low, close, x: 0.35, w: 0.3, color: close >= open ? #26a69a : #ef5350, wick: #c8c8c8)
draw.text(high, str(volume, "0k"), x: 0.5, align: "center", size: 9)
cell(close, str(delta, "+0"), side: right, color: #ffffff, size: 9)
hbar(low, volume, 2000, side: left, color: #2962ff60)

A footprint drawn level by level from bar.footprint, with rows grouped to stay readable at any zoom:

StrateScript
indicator "My footprint" { overlay: true, candles: false }
rows = chart.row_ticks(14)
fp = bar.footprint.rows(rows)
for lv in fp.levels {
  c = lv.delta > 0 ? #26a69a : #ef5350
  cell(lv.price, str(lv.sell), side: left, color: #ffffff, size: 9, ticks: rows)
  cell(lv.price, str(lv.buy), side: right, color: #ffffff, size: 9, ticks: rows, bg: alpha(c, 25))
}
draw.rect(fp.poc, ticks: rows, x: 0, w: 1, border: #e8c15a)

Statistics row: stat#

Text
stat("Title", value, format:, color:, bg:)

Adds a row of values under the bars, one row per call place, titled on the left. format: uses the same codes as str (see Reference: functions); na leaves the cell empty.

StrateScript
indicator "Stats rows" { overlay: true }
stat("Delta", delta, format: "+0", color: delta > 0 ? #26a69a : #ef5350)
stat("Volume", volume, format: "0.0k")

Simple per-bar drawings#

label(time, price, "text", color:), box(t1, p1, t2, p2, color:, border:, text:), line(t1, p1, t2, p2, color:, width:, style:) and bubble(price, size, color) draw once on the current bar, and several per bar are allowed. They cannot be changed afterwards: prefer label.new, box.new and line.new. bubble draws a dot of fixed size at the price.

Panes and scales#

For a script with overlay: false, the header controls its pane:

StrateScript
indicator "Delta pane" { overlay: false, height: 200, background: #0b1d33, min: -500, max: 500, format: "compact", precision: 0, labels: true }
histogram(delta, delta >= 0 ? #26a69a : #ef5350, title: "Delta")
hline(0, color: #888888)

See the display keys in The language. candles: false hides the chart's own candles while the script is shown, which is useful when the script draws its own.

STRATE / PRODUCT SCREENSHOT

Actual platform screenshot.