Guides
Plotting
- Where things are drawn
- Colors
- Series:
plot,histogram,candle,fill - Lines and backgrounds:
hline,level,bg_color,bar_color - Markers
- Objects:
line.new,box.new,label.new - Tables
- Drawing inside a bar's column
- Statistics row:
stat - Simple per-bar drawings
- Panes and scales
Where things are drawn#
- A script with
overlay: true(the default) draws on the price chart. A script withoverlay: falsegets its own pane below the prices. - A script with its own pane can still draw some elements on the price chart with
overlay: true(orpane: "price") on that call:plot,histogram,candle,level,hline,bg_color,bar_color,fill,marker,label,bubble,box,line,alert,signal. - The place of a series is fixed by its first call.
E948 is raised when:
- a script drawn on the prices uses
overlay: falseorpane: "panel"on a call (it has no pane of its own); overlay:is not a bool,pane:is not"price"or"panel", or both are given and disagree;- a pane script uses
overlay: trueoncell,hbar,draw.*,line.new,box.new,label.new,table.new,stat, orcandle(…, x:, w:)— these stay in the script's own area; filljoins a plot on the prices with a plot in the pane, or is given its ownoverlay:.
Unknown named options of a drawing function are ignored.
Colors#
| Form | Example |
|---|---|
| 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 setting | input.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#
| Function | Signature | Notes |
|---|---|---|
plot | plot(value, color?, color:, title:, width:, style:) → handle | The 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. |
histogram | histogram(value, color?, color:, title:) → handle | Bars starting from 0. |
candle | candle(o, h, l, c, color?, color:) → handle | A candle series. |
fill | fill(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.
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)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#
| Function | Signature | Notes |
|---|---|---|
hline | hline(value, color:, style:, width:, text:) → handle | A horizontal line. Does not change the automatic scale. na draws nothing. |
level | level(price, color:, text:) → handle | A horizontal line that is part of the automatic scale. |
bg_color | bg_color(color) | Background of the bar's column. na = none. |
bar_color | bar_color(color) | Color of the bar's candle. |
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#
marker(condition, shape:, location:, price:, color:, size:, text:, tip:)- Draws a shape on the bars where
conditionis true. One marker per call place and per bar. shape:"triangle_up","triangle_down","arrow_up","arrow_down","circle","cross","diamond","square". Default:triangle_downabove,triangle_upbelow,circleat a price.location:"above"(default),"below", or"price", which requiresprice:.size:"small","normal"(default),"large".text:writes a short text next to it;tip:is shown when hovering.- Any value outside these lists, or
location: "price"withoutprice:, gives E927.
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.
| Constructor | Signature |
|---|---|
line.new | line.new(t1, p1, t2, p2, color:, width:, style:, glow:, pulse:) |
box.new | box.new(t1, top, t2, bottom, color:, border:, text:, text_color:, fade: "left" \| "right", glow:) |
label.new | label.new(t, price, text, color:, bg:, text_color:, glow:, pulse:) |
- Times are
timevalues (bar.time,t.time,s.time…). A time that is not a time gives E928. A price that isnacreates nothing and returnsna. glow:is a halo from 0 to 40 px.pulse:makes the object pulse for a duration up to 60 s (true= 3 s).- A script keeps at most 500 objects; beyond that the oldest are deleted.
- Fields:
time1,price1,time2,price2,text,deleted(aliases:time,price,top,bottom). - Methods:
set_start(t, p),set_end(t, p),set_left(t),set_right(t),set_top(p),set_bottom(p),set_time(t),set_price(p),set_text(s),set_color(c),set_border(c),set_glow(px),set_fade(side),set_bg(c),pulse(d),delete(). Any other method gives E933.
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#
t = table.new(position, columns, rows, bg:, border:, frame:, text_color:, size:)
t.cell(col, row, text, text_color:, bg:, size:, align:)position:"top_left","top_center","top_right","middle_left","middle_center","middle_right","bottom_left","bottom_center","bottom_right"(E928 otherwise).- 1 to 50 columns and rows (E928 otherwise). At most 20 live tables. Calling
table.newagain at the same place in the code, with the same position, replaces the previous table. Only the table's last state is drawn. - Cells are indexed from 0; a cell outside the table gives E928.
align:"left","center","right".size:"tiny"(8 px),"small"(10),"normal"(11),"large"(14),"huge"(18), or a number of pixels from 6 to 40. - Other methods:
clear(),clear(col, row),set_position(p),set_bg(c),set_border(c),set_frame(c),set_text_color(c),set_size(s),delete(). Fields:position,columns,rows,deleted.
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).
| Function | Signature | Notes |
|---|---|---|
cell | cell(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. |
hbar | hbar(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.rect | draw.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.text | draw.text(price, text, x: 0.5, align: "center", color:, size: 11, bold:, ticks:, tip:) | align: "left", "center", "right" (E937 otherwise). |
draw.line | draw.line(p1, p2, x1: 0, x2: 1, color:, width: 1, style:) | A segment inside the column. |
draw.candle | draw.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).
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:
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#
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.
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:
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.