Skip to content

Shape

Kind: module

Namespace: shape

Plots a symbol at a price level for each bar, handy for signals, highlights, and short labels. Use style, location, color, and optional text to control how it looks (Styles, Location).

Each shape series maintains one value per bar. A new value is added when a new bar starts and replaced when the current bar updates.

shape()

Kind: func

Plots one symbol at the given value for each active shape call.

Syntax

shape(value) → void
shape(value, {title, style, offset, location, overlay, color, textColor, text}) → void

Arguments

NameTypeDescription
valuenumber, seriesValue or series to plot

Options

Static (captured on the first call, ignored afterwards):

NameTypeDefaultDescription
title?stringnullDisplay name in the legend
style?constshape.STYLE_XCROSSVisual style (see Styles)
offset?int0Horizontal offset in bars (positive = right)
location?locationlocation.ABOVE_BARVertical placement (e.g. location.ABOVE_BAR, location.BELOW_BAR)
overlay?booleantrueDraw on the main price chart (true) or in a separate pane (false)

Dynamic (can change per bar):

NameTypeDefaultDescription
color?colornullShape color
textColor?colornullText label color (independent of the shape color)
text?string""Text label. Passing null or omitting is the same as "" (no text)

Returns

void

Caveats

  • Must be called inside onTick(), not in the init section
  • Must be at the top level of onTick(), not inside conditionals or loops. This ensures the call count and order remain constant across ticks

Pitfall

javascript
function onTick() {
    if (bar.isConfirmed()) {
        shape(close);  // ❌ inside conditional
    }
}

Example

javascript
const length = input.double("length", 20);

function onTick() {
    const sma = ta.sma(close, length);

    shape(close > sma ? high : NaN, {
        title: "Above SMA",
        style: shape.STYLE_ARROW_UP,
        location: location.ABOVE_BAR,
        color: color.LIME,
    });
}

Styles

Visual style constants for shape() output. Use with the style option.


shape.STYLE_TAG

Kind: constant

Value: TAG

Tag shape at the data point.


shape.STYLE_ARROW_UP

Kind: constant

Value: ARROW_UP

Upward arrow at the data point.


shape.STYLE_ARROW_DOWN

Kind: constant

Value: ARROW_DOWN

Downward arrow at the data point.


shape.STYLE_XCROSS

Kind: constant

Value: XCROSS

Diagonal cross (X) at the data point.


shape.STYLE_CROSS

Kind: constant

Value: CROSS

Plus cross (+) at the data point.


shape.STYLE_BEACON

Kind: constant

Value: BEACON

Beacon (diamond-style) marker at the data point.


shape.STYLE_CIRCLE

Kind: constant

Value: CIRCLE

Circle at the data point.


See location for the full list of vertical placement constants. Common choices for shape() are location.ABOVE_BAR and location.BELOW_BAR.