TradingCharts

Text and Shapes

ChartScript exposes three declarative shape plotters (plotshape, plotchar, plotarrow) and one drawing primitive (label.new).

plotshape()

Renders a shape on each bar whose value is non-na.

plotshape(cond, title, style, location, color, text?, textcolor?, size?,
          offset?, show_last?, display?, editable?, force_overlay?)
Parameter Type Default Meaning
cond series bool/int required Truthy → emit a shape at location.
style const shape.triangleup See Shape styles.
location const location.abovebar .abovebar, .belowbar, .top, .bottom, .absolute.
color series color #2962FF
text const string "" Caption rendered next to the shape.
textcolor series color plot colour
size const size.auto .tiny, .small, .normal, .large, .huge.
cross = ta.crossover(close, ta.sma(close, 20))
plotshape(cross, "Cross up", shape.triangleup, location.belowbar,
          color=color.lime, size=size.tiny)

Shape styles

shape.triangleup, shape.triangledown, shape.cross, shape.xcross, shape.circle, shape.square, shape.diamond, shape.flag, shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown.

location.absolute

Place the shape at the exact price in location.absolute's value:

level = ta.pivothigh(5, 5)
plotshape(not na(level) ? level : na, style=shape.circle, location=location.absolute,
          color=color.red, size=size.tiny)

plotchar()

Renders a single character glyph. Faster to render than a shape; the glyph can be anything in the Unicode BMP:

plotchar(ta.crossover(rsi, 70),  "RSI OB", "▲", location.abovebar, color=color.red,  size=size.tiny)
plotchar(ta.crossunder(rsi, 30), "RSI OS", "▼", location.belowbar, color=color.lime, size=size.tiny)

plotarrow()

Up/down arrows sized by magnitude:

delta = close - open
plotarrow(delta, "Body size", colorup=color.lime, colordown=color.red,
          minheight=5, maxheight=50)
  • Positive values render an up arrow, negative values a down arrow, na nothing.
  • Arrow pixel height scales linearly between minheight and maxheight from the smallest-magnitude bar to the largest.

label.new()

A drawing object — supports multiline text, tooltip, custom style, and update/delete:

label.new(x, y, text?, xloc?, yloc?, color?, style?, textcolor?, size?,
          textalign?, tooltip?, font_family?)
pivot = ta.pivothigh(5, 5)
if not na(pivot)
    label.new(bar_index[5], pivot, str.tostring(pivot, "#.##"),
              style=label.style_label_down, color=color.new(color.red, 80),
              textcolor=color.white, size=size.small)

Label styles

label.style_label_up, label.style_label_down, label.style_label_left, label.style_label_right, label.style_label_center, label.style_label_lower_left, label.style_label_lower_right, label.style_label_upper_left, label.style_label_upper_right, label.style_arrowup, label.style_arrowdown, label.style_square, label.style_circle, label.style_diamond, label.style_cross, label.style_xcross, label.style_none (text only, no shape).

yloc

  • yloc.price (default) — place at the supplied y value.
  • yloc.abovebar — anchor against this bar's high (y is ignored).
  • yloc.belowbar — anchor against this bar's low.

Updating a label

label.set_text(l, "updated")
label.set_xy(l, bar_index, close)
label.set_color(l, color.aqua)
label.set_tooltip(l, "detailed hover text here")
label.delete(l)

Multiline and alignment

Newlines in text are preserved. textalign controls horizontal alignment inside the label box: text.align_left, text.align_center (default), text.align_right.

See also