CODESCRIPT

Objects

118 entries. What each one takes, what it returns, and a working example.

boxAll()

Returns an array of all currently existing (non-deleted) box handles. Result: Arr(len=0, [])

Returns an array of all currently existing (non-deleted) box handles (in creation order).

Note

Count with arraySize, access with arrayGet; usually to loop and delete/update boxs on barstate.islast. Deleted handles are excluded.

When to use

To bulk-clear/update all boxs on the chart (especially to delete old drawings on each re-run).

CODESCRIPT
boxAll()

Returns every box the code has drawn as a single list; used to count or clear them all at once.

boxCopy(box)

Clones the box.

Returns a NEW box handle copying all properties of the source box.

box
box
A box handle created by boxNew.

Note

Creates an independent clone; changing the copy does not affect the original.

When to use

To make a second box by cloning a similar zone and shifting it.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  k = boxCopy(b)
  boxSetXy1(k, barIndex-30, high)
  boxSetXy2(k, barIndex-15, low)
}

Clones the box and moves it to the previous range.

boxDelete(box)

Removes the box from the chart. Used to clean up zones that are no longer valid.

Returns nothing (na); the box no longer appears on the next draw.

box
box
A box handle created by boxNew.

Note

Marks the box deleted; it is excluded from output at flush time.

When to use

To remove a zone box that is no longer valid.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-10, high, barIndex, low)
  if close > high {
    boxDelete(b)
  }
}

Deletes the box if close breaks above the high.

boxGetBottom(box)

Bottom edge price.

Returns the bottom edge price (price2).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetBottom(b), "x")
}

Plots the bottom edge price.

boxGetLeft(box)

Left edge bar.

Returns the left edge bar index (bar1).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetLeft(b), "x")
}

Plots the left edge bar index.

boxGetRight(box)

Right edge bar.

Returns the right edge bar index (bar2).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetRight(b), "x")
}

Plots the right edge bar index.

boxGetTop(box)

Top edge price.

Returns the top edge price (price1).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetTop(b), "x")
}

Plots the top edge price.

boxGetX1(box)

First-corner bar index.

Returns the first corner's bar index (same value as boxGetLeft).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetX1(b), "x")
}

Plots the first corner's bar index.

boxGetX2(box)

Second-corner bar index.

Returns the second corner's bar index (same value as boxGetRight).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetX2(b), "x")
}

Plots the second corner's bar index.

boxGetY1(box)

First-corner price.

Returns the first corner's price (same value as boxGetTop).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetY1(b), "x")
}

Plots the first corner's price.

boxGetY2(box)

Second-corner price.

Returns the second corner's price (same value as boxGetBottom).

box
box
A box handle created by boxNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a box's edge coordinate in another computation.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  plot(boxGetY2(b), "x")
}

Plots the second corner's price.

boxNew(bar1, price1, bar2, price2, color?, text?, bgcolor?, border_color?, border_width?, border_style?, text_color?, text_halign?, text_valign?, xloc?, extend?, text_size?, bg_color?, text_wrap?, text_formatting?, text_font_family?)

Updatable box object (returns a handle). All of the following are given by name only (they cannot be given in order): bgcolor → fill (interior) color (default transparent; also settable via boxSetBgColor). border_color → an ALTERNATE name for the SAME field as the 5th argument `color` (border color) — precedence: color given by name > border_color given by name > the 5th argument in order (so border_color given by name OVERRIDES even a color given as the 5th argument in order — do not mix the two). text_color → text color. text_halign/text_valign → horizontal/vertical text alignment ("left"/"center"/"right", "top"/"center"/"bottom"). xloc → x-location mode ("bar_index"/"bar_time"). extend → extend direction ("none"/"left"/"right"/"both"). text_size → font size: "tiny"/"small"/"normal"/"large"/"huge", or a raw pixel count (clamped to 7-40). SECOND FORM: two chart points may be given — boxNew(p1, p2).

Returns an updatable box (rectangle) handle; change it with boxSetXy1/boxSetBgColor/boxSetText.

bar1
number
Bar index of the top-left corner (left edge).
price1
number
Price of the top-left corner (top edge; series → its value at that bar).
bar2
number
Bar index of the bottom-right corner (right edge).
price2
number
Price of the bottom-right corner (bottom edge).
color
color
Optional. Border color (default blue #2962ff).
text
string
Optional. Text inside the box.
bgcolor
color
Optional (NAMED argument only). Fill (interior) color — default transparent; also settable later via boxSetBgColor.
border_color
color
Optional (NAMED argument only). An ALTERNATE name for the SAME field as the 5th argument `color` (border color). Precedence: color keyword > border_color keyword > 5th argument given in order — so a border_color keyword OVERRIDES even a color given as the 5th argument given in order. Do not mix the two.
border_width
number
Border thickness (0-20 px). 0 draws no border. Can also be changed later with boxSetBorderWidth.
border_style
string
Border pattern: line.style_solid, line.style_dashed, line.style_dotted.
text_color
color
Optional (NAMED argument only). Text color.
text_halign
string
Optional (NAMED argument only). Horizontal text alignment: left/center/right.
text_valign
string
Optional (NAMED argument only). Vertical text alignment: top/center/bottom.
xloc
string
Optional (NAMED argument only). x-location mode: bar_index/bar_time.
extend
string
Optional (NAMED argument only). Extend direction: none/left/right/both.
text_size
string
Optional (NAMED argument only). Font size: tiny/small/normal/large/huge, or a raw pixel count (clamped to 7-40).
bg_color
color
Same field as `bgcolor` — fill color. Accepted because the setter is `set_bg_color`; both give the same result.
text_wrap
string
What happens when text exceeds the box: text.wrap_none or text.wrap_auto.
text_formatting
string
Text formatting: text.format_none, text.format_bold, text.format_italic.
text_font_family
string
Font family: font.family_default or font.family_monospace.

Note

Draws a rectangle from two corners. The 5th argument is the BORDER color — not the fill; the fill is transparent by default and set with boxSetBgColor. Text is centered by default. Border color (color / boxSetColor / boxSetBorderColor) and fill color (boxSetBgColor) are SEPARATE properties; set both together.

When to use

To highlight a price region (a supply/demand zone, a consolidation range, an area of interest).

Limits

Corners must be single numbers → no bulk-series use, call inside an if block. At most 500 objects per kind are kept (FIFO). For a fill, use boxSetBgColor rather than the 5th argument.

Not for

If you want a panel fixed in a screen corner, use tableNew rather than a box (a box scrolls with price).

Tip

Border color (color / boxSetColor / boxSetBorderColor) and fill color (boxSetBgColor) are SEPARATE properties; set both together.

Draws a rectangle from two corners. The 5th argument is the BORDER color — not the fill; the fill is transparent by default and set with boxSetBgColor. Text is centered by default.

Border color (color / boxSetColor / boxSetBorderColor) and fill color (boxSetBgColor) are SEPARATE properties; set both together.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-20, high, barIndex, low, "#2962ff", "Zone")
  boxSetBgColor(b, "#2962ff22")
}

A box spanning the last 20 bars' high-low range, lightly blue-filled, labeled 'Zone'.

boxSetBgColor(box, color)

Sets the fill colour inside the box. It is separate from the border colour: a transparent fill with a visible border shows the zone without hiding the chart. Set the transparency with `colorNew`.

Returns the same box handle.

box
box
A box handle created by boxNew.
color
color
New fill color (usually with a semi-transparent alpha).

Note

Sets the box's INTERIOR fill color. The fill is transparent by default; usually you pass an alpha color like #rrggbbAA.

When to use

To shade a region so it stands out.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBgColor(b, "#ef535022")
}

Shades the box with a light red fill.

boxSetBorderColor(box, color)

Sets the border colour of the box. It is kept separate from the background: a visible border with a transparent fill gives a readable zone.

Returns the same box handle.

box
box
A box handle created by boxNew.
color
color
New border color.

Note

Sets the box's border color (the borderColor property). Serves the same purpose as boxSetColor; use it when you want to color the border explicitly.

When to use

To set the border color independently of the fill.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBorderColor(b, "#ffffff")
}

Colors the box border white.

boxSetBorderStyle(box, style)

Sets the style of the box's border line: solid, dashed or dotted. Drawing an unconfirmed zone dashed is an easy way to tell it apart from a confirmed one.

Returns the same box handle.

box
box
A box handle created by boxNew.
style
string
Border style: solid / dashed / dotted.

Note

Sets the border style. A non-string value is a no-op.

When to use

To distinguish a projected/tentative zone with a dashed border.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBorderStyle(b, "dashed")
}

Makes the box border dashed.

boxSetBorderWidth(box, width)

Border width.

Returns the same box handle.

box
box
A box handle created by boxNew.
width
number
Border width (pixels, integer).

Note

Sets the border thickness (rounded to an integer). A non-numeric value is a no-op.

When to use

To emphasize an important zone with a thicker border.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBorderWidth(b, 2)
}

Sets the box border to 2 pixels.

boxSetBottom(box, price)

Sets the price the box's bottom edge sits at. Used with `boxSetTop` to update the height of a zone.

Returns the same box handle.

box
box
A box handle created by boxNew.
price
number
New bar index.

Note

Moves the bottom edge (price2) to the given price.

When to use

To align a single edge (bottom edge) of the box without disturbing the others.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBottom(b, low)
}

Aligns the bottom edge to the current low.

boxSetBottomRightPoint(box, point)

Bottom-right corner (chartPoint).

Returns the same box handle.

box
box
A box handle created by boxNew.
point
point
A chartPoint (bar+price drawing point).

Note

Sets the bottom-right corner from a chartPoint (bar2/price2).

When to use

To bind the box's bottom-right corner in a point-based drawing flow.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetBottomRightPoint(b, chartPointNow(low))
}

Moves the bottom-right corner to a low point on the current bar.

boxSetColor(box, color)

Changes the box color.

Returns the same box handle.

box
box
A box handle created by boxNew.
color
color
New border color.

Note

Changes the box border color. Not the fill — use boxSetBgColor for that. A non-string value is a no-op.

When to use

To recolor the box outline by state.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetColor(b, "#26a69a")
}

Colors the box outline green.

boxSetExtend(box, direction)

Box extension (none/left/right/both).

Returns the same box handle.

box
box
A box handle created by boxNew.
direction
string
Extension: none / left / right / both.

Note

Extends the box horizontally beyond its edges. A non-string value is a no-op.

When to use

To extend a zone to the right (future) to see upcoming tests.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetExtend(b, "right")
}

Extends the box to the right.

boxSetLeft(box, bar)

Left edge bar.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
New bar index.

Note

Moves the left edge (bar1) to the given bar.

When to use

To align a single edge (left edge) of the box without disturbing the others.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetLeft(b, barIndex-40)
}

Moves the left edge 40 bars back.

boxSetLefttop(box, bar, price)

Top-left corner.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
Bar index of the top-left corner.
price
number
Price of the top-left corner.

Note

Sets the top-left corner (bar1 + price1) in one call; targets the same corner as boxSetXy1.

When to use

To set the top-left corner by both bar and price.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetLefttop(b, barIndex-25, high)
}

Sets the top-left corner at a high point 25 bars ago.

boxSetRight(box, bar)

Moves the right edge of the box to another bar. Called on each new bar to stretch a zone up to the current bar.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
New bar index.

Note

Moves the right edge (bar2) to the given bar.

When to use

To align a single edge (right edge) of the box without disturbing the others.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetRight(b, barIndex)
}

Moves the right edge to the current bar.

boxSetRightbottom(box, bar, price)

Bottom-right corner.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
Bar index of the bottom-right corner.
price
number
Price of the bottom-right corner.

Note

Sets the bottom-right corner (bar2 + price2) in one call.

When to use

To set the bottom-right corner by both bar and price.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetRightbottom(b, barIndex, low)
}

Sets the bottom-right corner at the current bar-low point.

boxSetText(box, text)

Sets the text written inside the box. Used to show what the zone is or which level it marks, on the box itself.

Returns the same box handle.

box
box
A box handle created by boxNew.
text
string
Text to show inside the box.

Note

Changes the box text. A non-string value is a no-op.

When to use

To label a zone box (e.g. 'Supply', 'Demand', the range width).

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Supply Zone")
}

Writes 'Supply Zone' inside the box.

boxSetTextColor(box, color)

Sets the colour of the text inside the box. With a transparent fill the text must be dark or light enough against the background to stay readable.

Returns the same box handle.

box
box
A box handle created by boxNew.
color
color
Text color.

Note

Sets the box text color. A non-string value is a no-op.

When to use

To keep the text legible over the fill (a contrast color).

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Zone")
  boxSetTextColor(b, "#ffffff")
}

Colors the text white.

boxSetTextFontFamily(box, font)

Text font family.

Returns the same box handle.

box
box
A box handle created by boxNew.
font
string
Font family (e.g. default or monospace).

Note

Sets the box text's font family. A non-string value is a no-op.

When to use

When you want a monospace font so numeric text aligns.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "123.45")
  boxSetTextFontFamily(b, "monospace")
}

Renders the text in a monospace font.

boxSetTextFormatting(box, formatting)

Text formatting (bold/italic).

Returns the same box handle.

box
box
A box handle created by boxNew.
formatting
string
Text formatting: bold / italic (or both).

Note

Applies bold/italic formatting to the box text. A non-string value is a no-op.

When to use

To emphasize the box heading in bold.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Important")
  boxSetTextFormatting(b, "bold")
}

Renders the text in bold.

boxSetTextHalign(box, align)

Horizontal text alignment (left/center/right).

Returns the same box handle.

box
box
A box handle created by boxNew.
align
string
Horizontal alignment: left / center / right.

Note

Sets the text's horizontal alignment inside the box. A non-string value is a no-op.

When to use

To pin the text to one side of the box.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Zone")
  boxSetTextHalign(b, "left")
}

Left-aligns the text.

boxSetTextSize(box, size)

Text size.

Returns the same box handle.

box
box
A box handle created by boxNew.
size
string
Text size: tiny/small/normal/large/huge or a pixel number in 7–40.

Note

Sets the text size. A name maps to its pixel equivalent; a number is clamped to 7–40.

When to use

To enlarge the box label so it stands out.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Zone")
  boxSetTextSize(b, "large")
}

Sets the text to 'large' size.

boxSetTextValign(box, align)

Vertical text alignment (top/center/bottom).

Returns the same box handle.

box
box
A box handle created by boxNew.
align
string
Vertical alignment: top / center / bottom.

Note

Sets the text's vertical alignment inside the box. A non-string value is a no-op.

When to use

To pin the text to the top/bottom of the box.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "Zone")
  boxSetTextValign(b, "top")
}

Top-aligns the text.

boxSetTextWrap(box, mod)

Text wrapping (none/auto).

Returns the same box handle.

box
box
A box handle created by boxNew.
mod
string
Text wrapping: none / auto.

Note

Turns line wrapping on/off so long text fits the box width. A non-string value is a no-op.

When to use

To break long text that overflows the box into multiple lines.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetText(b, "A long description text")
  boxSetTextWrap(b, "auto")
}

Wraps long text across lines to fit the box.

boxSetTop(box, price)

Sets the price the box's top edge sits at. When a zone grows, moving the edge is cheaper than deleting and redrawing the box, and it keeps you under the count limit.

Returns the same box handle.

box
box
A box handle created by boxNew.
price
number
New bar index.

Note

Moves the top edge (price1) to the given price.

When to use

To align a single edge (top edge) of the box without disturbing the others.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetTop(b, high)
}

Aligns the top edge to the current high.

boxSetTopLeftPoint(box, point)

Top-left corner (chartPoint).

Returns the same box handle.

box
box
A box handle created by boxNew.
point
point
A chartPoint (bar+price drawing point).

Note

Sets the top-left corner from a chartPoint (bar1/price1); a missing field on the point is skipped.

When to use

To bind a box corner in a point-based drawing flow.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetTopLeftPoint(b, chartPointNew(barIndex-30, time, high))
}

Moves the top-left corner to a high point 30 bars ago.

boxSetXloc(box, mod)

Location mode.

Returns the same box handle.

box
box
A box handle created by boxNew.
mod
string
Location mode: bar_index / bar_time.

Note

Sets the box's horizontal placement unit (bar order or timestamp). A non-string value is a no-op.

When to use

Use bar_time when you want placement to hold across timeframes.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetXloc(b, "bar_index")
}

Puts the box in bar-index location mode.

boxSetXy1(box, bar, price)

Changes the box's first corner.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
New bar index of the top-left corner.
price
number
New price of the top-left corner.

Note

Moves the box's FIRST corner (top-left: bar1, price1) together. If price is omitted, only the bar moves.

When to use

To reposition the top-left corner of a zone box.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetXy1(b, barIndex-30, high)
}

Moves the top-left corner 30 bars back and to the current high.

boxSetXy2(box, bar, price)

Changes the box's second corner.

Returns the same box handle.

box
box
A box handle created by boxNew.
bar
number
New bar index of the bottom-right corner.
price
number
New price of the bottom-right corner.

Note

Moves the box's SECOND corner (bottom-right: bar2, price2) together.

When to use

To extend the box's right edge as bars advance.

CODESCRIPT
if barstate.islast {
  b = boxNew(barIndex-15, high, barIndex, low)
  boxSetXy2(b, barIndex, low)
}

Moves the bottom-right corner to the current bar and low (grows the box).

chartPointCopy(point)

Copy of a drawing point.

Returns an independent copy of the given drawing point.

point
point
The chartPoint to copy.

Note

Copies all fields (index/time/price) of a chartPoint; changing the copy does not affect the original.

When to use

To derive a second point from the same base and shift its price slightly.

CODESCRIPT
if barstate.islast {
  p = chartPointNow(close)
  k = chartPointCopy(p)
  l = lineNew(p, k)
}

Copies a point and draws a line between the two.

chartPointFromIndex(index, price)

Bar-index-based drawing point.

Returns a bar-index-based drawing point (no time field).

index
number
Bar index (defaults to the last bar).
price
number
Price level.

Note

Builds a chartPoint from index + price; it carries no time, so it suits bar_index placement.

When to use

To build a point by bar order without needing a timestamp.

CODESCRIPT
if barstate.islast {
  p = chartPointFromIndex(barIndex-5, low)
  e = labelNew(close, "N", barIndex)
  labelSetPoint(e, p)
}

Binds a low point 5 bars ago to a label.

chartPointFromTime(time, price)

Time-based drawing point.

Returns a time-based drawing point (no index field).

time
number
Timestamp.
price
number
Price level.

Note

Builds a chartPoint from time + price; it suits bar_time placement (alignment holds across timeframes).

When to use

To anchor a point by timestamp so it stays in the same place across timeframes.

CODESCRIPT
if barstate.islast {
  p = chartPointFromTime(time, close)
  e = labelNew(close, "T", barIndex)
  labelSetPoint(e, p)
}

Binds the current time-price point to a label.

chartPointNew(time, index, price)

Drawing point. Order: time, then bar index, then price. Put na in the one you are not using — na for time with xloc.bar_index, na for index with xloc.bar_time.

Returns a drawing point (chartPoint) carrying index, time and price.

time
number
Timestamp (for bar_time placement).
index
number
Bar index (defaults to the last bar).
price
number
Price level (series → its last value).

Note

Produces an {index, time, price} record used by the point-based APIs of lines/boxes/labels. If price is a series its last value is taken; if index is omitted the last bar is used.

When to use

To create a drawing point once and bind it via lineSetFirstPoint/boxSetTopLeftPoint/labelSetPoint.

CODESCRIPT
if barstate.islast {
  p1 = chartPointNew(barIndex-10, time, low)
  p2 = chartPointNow(high)
  l = lineNew(p1, p2, "#26a69a")
}

Draws a green line between two chartPoints.

chartPointNow(price)

Gives the drawing point on the last bar — its bar number and the current price. Convenient for moving a drawing to the current bar.

Returns a drawing point at the last bar's index.

price
number
Price level (series → its last value).

Note

Builds a chartPoint from the current (last) bar's index + the given price; the most common shortcut in live drawings.

When to use

To attach a drawing's end to the current bar (e.g. the second point of lineNew).

CODESCRIPT
if barstate.islast {
  p = chartPointNow(close)
  l = lineNew(chartPointNew(barIndex-15, time, low), p)
}

Sets the line's second endpoint at the current bar-close.

labelAll()

Returns an array of all currently existing (non-deleted) label handles. Result: Arr(len=0, [])

Returns an array of all currently existing (non-deleted) label handles (in creation order).

Note

Count with arraySize, access with arrayGet; usually to loop and delete/update labels on barstate.islast. Deleted handles are excluded.

When to use

To bulk-clear/update all labels on the chart (especially to delete old drawings on each re-run).

CODESCRIPT
labelAll()

Returns every label the code has drawn as a single list.

labelCopy(label)

Clones the label.

Returns a NEW label handle copying all properties of the source label.

label
label
A label handle created by labelNew.

Note

Creates an independent clone; changing the copy does not affect the original.

When to use

To make a second same-styled label at a different position.

CODESCRIPT
if barstate.islast {
  e = labelNew(high, "Peak", barIndex, "#26a69a")
  k = labelCopy(e)
  labelSetXy(k, barIndex-10, low)
  labelSetText(k, "Low")
}

Clones the label, moves it 10 bars back and changes its text.

labelDelete(label)

Removes the label from the chart. Used to clean up marks that are no longer valid and to stay under the count limit.

Returns nothing (na); the label no longer appears on the next draw.

label
label
A label handle created by labelNew.

Note

Marks the label deleted; it is excluded from output at flush time. Later calls on a deleted handle have no effect.

When to use

To remove a label from the chart when its condition no longer holds.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  if close < open {
    labelDelete(e)
  }
}

Deletes the label on a down bar.

labelGetText(label)

Returns the label text.

Returns the label's text (string); an empty string if the handle is invalid.

label
label
A label handle created by labelNew.

Note

Read-only; does not mutate the label.

When to use

To read a label's text and reuse it in another drawing.

CODESCRIPT
if barstate.islast {
  e = labelNew(high, "Peak", barIndex)
  k = labelNew(low, labelGetText(e), barIndex)
}

Reads one label's text and uses it in a second label.

labelGetX(label)

Label bar index.

Returns the label's horizontal position: time (ms) if xloc is bar_time, otherwise the bar index.

label
label
A label handle created by labelNew.

Note

Read-only; returns the raw x value in the xloc unit (no resolution). Returns na if unset.

When to use

To use the bar a label sits on in another computation.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "X", barIndex)
  plot(labelGetX(e), "x")
}

Plots the label's bar index.

labelGetY(label)

Label price.

Returns the label's price level; na if unset.

label
label
A label handle created by labelNew.

Note

Read-only; does not mutate the label.

When to use

To use a label's price level in another computation.

CODESCRIPT
if barstate.islast {
  e = labelNew(high, "X", barIndex)
  plot(labelGetY(e), "y")
}

Plots the label's price level.

labelNew(price, text, bar?, color?, size?, textcolor?, style?, xloc?, yloc?, tooltip?, text_formatting?, text_font_family?)

Updatable label object (returns a handle). SECOND FORM: the position may be given as a chart point — labelNew(p, "text").

Returns an updatable label handle; store it in a variable and change it later with labelSetText/labelSetXy/labelSetColor.

price
number
Vertical position of the label (price level).
text
string
Label text (per-bar scalar; can be dynamic via str.tostring).
bar
number
Optional. Bar index (default last bar).
color
color
Optional. Background color (default blue #2962ff).
size
string
Optional. tiny/small/normal/large/huge or a pixel number (default normal).
textcolor
color
Text color. Can also be changed later with `set_textcolor`.
style
string
Label style (label.style_label_up, label.style_label_down, shape styles…).
xloc
string
Horizontal unit: xloc.bar_index or xloc.bar_time.
yloc
string
Vertical anchor: yloc.price, yloc.abovebar, yloc.belowbar.
tooltip
string
Tooltip shown on hover.
text_formatting
string
Text formatting: text.format_none, text.format_bold, text.format_italic.
text_font_family
string
Font family: font.family_default or font.family_monospace.

Note

Usually called inside a conditional block: if cond { e = labelNew(...) }. Text is white and the style is fixed downward-pointing (label_down); you set only price, text, bar, color and size. Keep the handle and you can update the same label instead of recreating it. Store the handle in a var variable and update it with labelSetText/labelSetXy instead of creating a new label; that keeps a single label on the chart.

When to use

For a label you will update later (change its text/position/color); ideal for a single live readout pinned to the last bar — update the handle instead of spawning a new label each bar.

Limits

The bar value must be a single number → passing a series directly in a vector run fails; call it bar by bar inside an if block. At most 500 labels are kept on the chart; call it unconditionally on every bar and new labels pile up while the oldest are dropped.

Not for

Not for a fixed shape repeated on every bar — plotshape/plotchar are lighter for that. For a summary pinned in a screen corner that does not scroll, use tableNew. Do not call it unconditionally on every bar; it creates a fresh label each bar, hits the 500 limit and old labels disappear.

Tip

Store the handle in a var variable and update it with labelSetText/labelSetXy instead of creating a new label; that keeps a single label on the chart.

Usually called inside a conditional block: if cond { e = labelNew(...) }. Text is white and the style is fixed downward-pointing (label_down); you set only price, text, bar, color and size. Keep the handle and you can update the same label instead of recreating it.

Store the handle in a var variable and update it with labelSetText/labelSetXy instead of creating a new label; that keeps a single label on the chart.

CODESCRIPT
var e = na
if barstate.islast {
  e := labelNew(close, "Price: " + str.tostring(close), barIndex, "#2962ff")
}

A single blue label on the last bar showing the closing price; its text updates as the chart advances.

CODESCRIPT
if crossover(close, sma(close, 20)) {
  e = labelNew(low, "AL", barIndex, "#26a69a", "large")
}

A large green 'BUY' label at the low level on every 20-SMA cross-above bar.

labelSetColor(label, color)

Changes the label color.

Returns the same label handle.

label
label
A label handle created by labelNew.
color
color
New background color; passing na hides the box/arrow.

Note

Sets the label background color. Passing na (None) hides the box (only the text remains); a string applies the color.

When to use

To recolor the label by state, or hide its box leaving only the text.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetColor(e, iff(close > open, "#26a69a", "#ef5350"))
}

Green background on an up bar, red on a down bar.

labelSetPoint(label, point)

Sets the label's position with a chart point, which carries the bar and the price as one value. Tidier than giving the bar and the price separately in code that computes and stores positions.

Returns the same label handle.

label
label
A label handle created by labelNew.
point
point
A chartPoint (index+time+price drawing point).

Note

Positions the label from a chartPoint: bar index, time and price are all written (time is preserved).

When to use

To bind a label to a point in a point-based drawing flow.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetPoint(e, chartPointNow(high))
}

Moves the label to a high point on the current bar.

labelSetSize(label, size)

Label font size (tiny/small/normal/large or a number).

Returns the same label handle.

label
label
A label handle created by labelNew.
size
string
Size: tiny/small/normal/large/huge or 7–40 pixels.

Note

Sets the label font size. A name maps to its pixel equivalent; a number is clamped to 7–40.

When to use

To enlarge an important label so it stands out.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetSize(e, "large")
}

Sets the label to 'large' size.

labelSetStyle(label, style)

Label style: box-arrow (label_up/down/left/right), none, or shape (label_circle/square/diamond/triangleup/triangledown/arrowup/arrowdown/cross/xcross/flag).

Returns the same label handle.

label
label
A label handle created by labelNew.
style
string
Label style. Box-arrow: label_up / label_down / label_left / label_right. Text-only: none. Shape (a shape at the anchor with text above): label_circle / label_square / label_diamond / label_triangleup / label_triangledown / label_arrowup / label_arrowdown / label_cross / label_xcross / label_flag.

Note

Sets the label's style. Box-arrow styles (label_up/down/left/right) show text in a box; none draws only the text; shape styles (label_circle/square/diamond/triangleup/triangledown/arrowup/arrowdown/cross/xcross/flag) draw a small shape at the anchor with text above. An unrecognized value falls back to label_down and produces a warning.

When to use

To point the label's arrow up/down relative to the bar (e.g. label_down for a top, label_up for a bottom).

Sets the label's arrow/box style. Supported styles: label_up/label_down/label_left/label_right/none. Any other value falls back to label_down and produces a warning.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetStyle(e, "label_up")
}

Turns the label into an upward-pointing style.

labelSetText(label, text)

Changes the text of an existing label. Updating instead of deleting and recreating keeps you from hitting the count limit.

Returns the same label handle.

label
label
A label handle created by labelNew.
text
string
New label text.

Note

Changes the label text. A non-string value is a no-op. Ideal for keeping a handle and updating the text without creating a new label each bar.

When to use

To update the text of a live readout label pinned to the last bar.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetText(e, "Price: " + str.tostring(close))
}

Updates the label text with the current close.

labelSetTextFontFamily(label, font)

Font family.

Returns the same label handle.

label
label
A label handle created by labelNew.
font
string
Font family (e.g. default or monospace).

Note

Sets the label text's font family. A non-string value is a no-op.

When to use

When you want a monospace font so numeric labels align.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetTextFontFamily(e, "monospace")
}

Renders the label in a monospace font.

labelSetTextFormatting(label, formatting)

Text formatting (bold/italic).

Returns the same label handle.

label
label
A label handle created by labelNew.
formatting
string
Text formatting: bold / italic.

Note

Applies bold/italic formatting to the label text. A non-string value is a no-op.

When to use

To emphasize an important label in bold.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetTextFormatting(e, "bold")
}

Renders the label text in bold.

labelSetTextalign(label, align)

Text alignment (left/center/right).

Returns the same label handle.

label
label
A label handle created by labelNew.
align
string
Text alignment: left / center / right.

Note

Sets the alignment of multi-line label text. A non-string value is a no-op.

When to use

To align multi-line label text.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetText(e, "Line1\nLine2")
  labelSetTextalign(e, "left")
}

Left-aligns multi-line text.

labelSetTextcolor(label, color)

Sets the text colour of the label. It is given separately so the text does not blend into the label's background; colouring the text as well speeds up reading on directional labels.

Returns the same label handle.

label
label
A label handle created by labelNew.
color
color
Text color; passing na hides the text.

Note

Sets the label text color. Passing na (None) hides the text; a string applies the color.

When to use

To keep the text legible over the background (a contrast color).

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetTextcolor(e, "#000000")
}

Colors the text black.

labelSetTooltip(label, text)

Tooltip shown on hover.

Returns the same label handle.

label
label
A label handle created by labelNew.
text
string
Tooltip text shown on hover.

Note

Adds a tooltip to the label that appears on hover. A non-string value is a no-op.

When to use

To show extra detail in a tooltip that does not fit in a short label.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetTooltip(e, "RSI: " + str.tostring(rsi(close,14)))
}

Adds the current RSI value as the label tooltip.

labelSetX(label, bar)

Changes the bar position of a label while its price position stays. Used to move a label to the last bar.

Returns the same label handle.

label
label
A label handle created by labelNew.
bar
number
New horizontal position (the label's xloc unit).

Note

Changes only the label's horizontal position; the price is untouched. x is written in the label's xloc unit.

When to use

To slide the label to another bar while keeping its price.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetX(e, barIndex-5)
}

Moves the label 5 bars back.

labelSetXloc(label, x, xloc)

Repositions the label's x-coordinate in the `xloc` unit ("bar_index" or "bar_time"): `x` is the new x value, `xloc` the location mode. (A two-argument call only changes x; the third argument is required to change the mode.)

Returns the same label handle.

label
label
A label handle created by labelNew.
x
number
New horizontal position (in the xloc unit below).
xloc
string
Location mode: bar_index or bar_time. (Named-argument name: xloc.)

Note

Changes the label's horizontal location unit AND rewrites x in that new unit (three arguments: label, x, xloc). Only bar_index/bar_time are accepted as valid modes.

When to use

When you want to switch the label to bar_time and anchor it by timestamp.

Changes the label's horizontal location unit AND rewrites x in that new unit (three arguments: label, x, mode). Only bar_index/bar_time are accepted as valid modes.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetXloc(e, time, "bar_time")
}

Switches the label to timestamp location mode and places it at the current time.

labelSetXy(label, bar, price)

Changes both the bar and the price position of a label in one call.

Returns the same label handle.

label
label
A label handle created by labelNew.
bar
number
New horizontal position (bar or time, per the label's xloc unit).
price
number
New price level.

Note

Moves the label both horizontally (bar) and vertically (price). The x value is written in the label's xloc unit (bar_index → barIndex, bar_time → time).

When to use

To move a live label to the last bar and current price.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetXy(e, barIndex, high)
}

Moves the label to the current bar and high level.

labelSetY(label, price)

Price position.

Returns the same label handle.

label
label
A label handle created by labelNew.
price
number
New price level; na leaves it position-less.

Note

Changes only the label's vertical (price) position. Passing na (None) drops the price (meaningful with abovebar/belowbar yloc).

When to use

To update the label's price level while keeping its bar.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetY(e, high)
}

Moves the label to the current high level.

labelSetYloc(label, mod)

Vertical location mode (price/abovebar/belowbar).

Returns the same label handle.

label
label
A label handle created by labelNew.
mod
string
Vertical location mode: price / abovebar / belowbar.

Note

Sets the label's vertical placement: price uses the price level, abovebar/belowbar pins above/below the bar (the price argument is ignored in those modes). Only one of the three values is valid.

When to use

To pin the label above/below the bar independent of the price level.

CODESCRIPT
if barstate.islast {
  e = labelNew(close, "Note", barIndex)
  labelSetYloc(e, "abovebar")
}

Pins the label above the bar.

lineAll()

Returns an array of all currently existing (non-deleted) line handles. Result: Arr(len=0, [])

Returns an array of all currently existing (non-deleted) line handles (in creation order).

Note

Count with arraySize, access with arrayGet; usually to loop and delete/update lines on barstate.islast. Deleted handles are excluded.

When to use

To bulk-clear/update all lines on the chart (especially to delete old drawings on each re-run).

CODESCRIPT
lineAll()

Returns every line the code has drawn as a single list.

lineCopy(line)

Clones the line (returns a new handle).

Returns a NEW line handle copying all properties of the source line.

line
line
A line handle created by lineNew.

Note

Creates an independent clone; changing the copy does not affect the original. Returns na for an invalid handle.

When to use

To make a parallel channel or a second level by cloning a line and shifting it slightly.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-20, low, barIndex, low)
  k = lineCopy(l)
  lineSetY1(k, high)
  lineSetY2(k, high)
}

Clones the lower line and moves it to the high level to form a parallel upper line.

lineDelete(line)

Removes the line from the chart. Used to clear level lines that are out of date.

Returns nothing (na); the line no longer appears on the next draw.

line
line
A line handle created by lineNew.

Note

Marks the line deleted — it is excluded from the output list at flush time. Later calls on a deleted handle have no effect.

When to use

To remove a line that is no longer valid (e.g. delete the line when support breaks).

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-10, low, barIndex, high)
  if close < low {
    lineDelete(l)
  }
}

Deletes the line if close drops below the low.

lineGetPrice(line, bar)

Returns the line's price at a given bar (linear).

Returns the line's price at the given bar (linear inter/extrapolation); if both ends share a bar, price1 is returned.

line
line
A line handle created by lineNew.
bar
number
The bar index at which to read the price.

Note

Treats the line as a straight line and computes its y value at the requested bar — works beyond the endpoints too (extrapolation). Returns na for an invalid handle.

When to use

To compare price against a trendline's value at a specific bar for a break/touch test.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  plot(lineGetPrice(l, barIndex), "x")
}

Plots the line's (extrapolated) price value at the current bar.

lineGetX1(line)

First-endpoint bar index.

Returns the first endpoint's bar index (as a float).

line
line
A line handle created by lineNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a line's endpoint coordinate in another computation.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  plot(lineGetX1(l), "x")
}

Plots the first endpoint's bar index.

lineGetX2(line)

Second-endpoint bar index.

Returns the second endpoint's bar index.

line
line
A line handle created by lineNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a line's endpoint coordinate in another computation.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  plot(lineGetX2(l), "x")
}

Plots the second endpoint's bar index.

lineGetY1(line)

First-endpoint price.

Returns the first endpoint's price level.

line
line
A line handle created by lineNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a line's endpoint coordinate in another computation.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  plot(lineGetY1(l), "x")
}

Plots the first endpoint's price.

lineGetY2(line)

Second-endpoint price.

Returns the second endpoint's price level.

line
line
A line handle created by lineNew.

Note

Read-only; does not mutate the handle. Returns na for an invalid handle.

When to use

To use a line's endpoint coordinate in another computation.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  plot(lineGetY2(l), "x")
}

Plots the second endpoint's price.

lineNew(bar1, price1, bar2, price2, color?, style?, width?, extend?, xloc?)

Creates an updatable line object (returns a handle). width (7th in order, or by name): line thickness, 1-4 (default 1; out-of-range is clamped). extend (NAMED argument only): "none"/"left"/"right"/"both" (default "none") — same fields as lineSetWidth/lineSetExtend, settable already at creation. xloc (NAMED argument only): x-location mode "bar_index" (default, bar1/bar2 are treated as bar indices) or "bar_time" (bar1/bar2 are treated as millisecond Unix timestamps) — same field as lineSetXloc/lineGetX1/lineGetX2. SECOND FORM: two chart points may be given — lineNew(p1, p2, color). Create points with chartPointNew(time, bar, price).

Returns an updatable line handle drawn between the two points; store it in a variable and change it later with lineSetXy1/lineSetColor/lineSetWidth.

bar1
number
First endpoint bar index (horizontal position). If na, the line is created first and positioned later with lineSetXy1.
price1
number
First endpoint price level (scalar or a series → its value at that bar).
bar2
number
Second endpoint bar index.
price2
number
Second endpoint price level.
color
color
Optional. Line color (default blue #2962ff).
style
string
Optional. Line style: solid/dashed/dotted (default solid).
width
number
Optional (7th argument in order, or by name). Line thickness, 1-4 (default 1; out-of-range is clamped) — same field as lineSetWidth.
extend
string
Optional (NAMED argument only, no form that can be given in order). Extend direction: none/left/right/both (default none) — same field as lineSetExtend.
xloc
string
Optional (NAMED argument only). x-location mode: bar_index (default, bar1/bar2 are bar indices) or bar_time (bar1/bar2 are millisecond Unix timestamps).

Note

Draws a free line between two (bar, price) pairs. Width defaults to 1 (change to 1–4 via lineSetWidth) and extension is off (turn on with lineSetExtend). Usually called inside a conditional block; keep the handle to update the same line instead of recreating it. Store the handle in a var variable and extend the second endpoint with lineSetXy2 instead of creating a new line each bar; that grows a single line.

When to use

For any drawing that connects two points — support/resistance, a trendline, a channel edge, or joining a swing high to a low. You can pass a chartPoint in place of a point pair (it is auto-expanded).

Limits

bar1/bar2 must be single numbers → passing a series directly in a vector run fails; call it bar by bar inside an if block. width is clamped to 1–4. At most 500 lines are kept on the chart; call it unconditionally every bar and new lines pile up while the oldest are dropped (FIFO).

Not for

Not for a continuous curve computed on every bar — use plot for that. For a fixed horizontal level, hline is lighter. To shade between two lines, use linefillNew.

Tip

Store the handle in a var variable and extend the second endpoint with lineSetXy2 instead of creating a new line each bar; that grows a single line.

Draws a free line between two (bar, price) pairs. Width defaults to 1 (change to 1–4 via lineSetWidth) and extension is off (turn on with lineSetExtend). Usually called inside a conditional block; keep the handle to update the same line instead of recreating it.

Store the handle in a var variable and extend the second endpoint with lineSetXy2 instead of creating a new line each bar; that grows a single line.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-20, low, barIndex, high, "#26a69a", "dashed")
  lineSetWidth(l, 2)
}

A dashed green line from the low 20 bars ago to the current high; width 2.

CODESCRIPT
if barstate.islast {
  p1 = chartPointNew(barIndex-10, time, low)
  p2 = chartPointNow(high)
  l = lineNew(p1, p2, "#2962ff")
}

A blue line between two chartPoints (point pairs are auto-expanded).

lineSetColor(line, color)

Changes the line color.

Returns the same line handle.

line
line
A line handle created by lineNew.
color
color
New line color (hex or a color constant).

Note

Changes the line color. Only a string (color) argument is applied; a number/na is a no-op.

When to use

To recolor a line by state (e.g. a support line that turns green/red by condition).

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetColor(l, iff(close > open, "#26a69a", "#ef5350"))
}

Green line when close is above open, red otherwise.

lineSetExtend(line, direction)

Extend the line: none/right/left/both.

Returns the same line handle.

line
line
A line handle created by lineNew.
direction
string
Extension direction: none / right / left / both.

Note

Extends the line beyond its endpoints. The value is lowercased; anything other than none/right/left/both is a no-op. Default is none.

When to use

To project a trend/support line into the future (right) to see upcoming touches.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetExtend(l, "right")
}

Extends the line to the right (into the future).

lineSetFirstPoint(line, point)

Sets the first endpoint from a chartPoint.

Returns the same line handle.

line
line
A line handle created by lineNew.
point
point
A chartPoint (drawing point carrying bar+price).

Note

Sets the first endpoint from a chartPoint: if the point's bar and price fields are present, bar1/price1 update (missing fields are skipped).

When to use

To attach points produced by chartPointNew/chartPointNow to a line (a point-based drawing flow).

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetFirstPoint(l, chartPointNew(barIndex-25, time, low))
}

Moves the first endpoint to a low point 25 bars ago.

lineSetSecondPoint(line, point)

Sets the second endpoint from a chartPoint.

Returns the same line handle.

line
line
A line handle created by lineNew.
point
point
A chartPoint (drawing point carrying bar+price).

Note

Sets the second endpoint from a chartPoint (bar2/price2).

When to use

To update the line's end in a point-based drawing flow.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetSecondPoint(l, chartPointNow(high))
}

Moves the second endpoint to a high point on the current bar.

lineSetStyle(line, style)

Changes the line style: solid / dashed / dotted, or arrowhead-tipped arrow_left / arrow_right / arrow_both.

Returns the same line handle.

line
line
A line handle created by lineNew.
style
string
Line style: solid / dashed / dotted, or arrow_left / arrow_right / arrow_both (adds an arrowhead at the matching end).

Note

Changes the line style. For arrow_* styles the arrowhead is always drawn solid (even if the line is dashed/dotted). A non-string value is a no-op.

When to use

To visually distinguish line kinds (e.g. a dashed line for a projected level, an arrowhead to show direction).

Changes the line style. A non-string value is a no-op.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetStyle(l, "dotted")
}

Turns the line into a dotted style.

lineSetWidth(line, width)

Line width (1-4).

Returns the same line handle.

line
line
A line handle created by lineNew.
width
number
Line width; clamped to the 1–4 range.

Note

Sets the width. The value is clamped to 1–4 (1 is thinnest). A non-numeric value is a no-op.

When to use

To emphasize an important level with a thick line.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetWidth(l, 3)
}

Sets the line to width 3.

lineSetX1(line, bar)

Changes the bar position of the line's first end. The price stays the same and only the horizontal position moves.

Returns the same line handle.

line
line
A line handle created by lineNew.
bar
number
New bar index of the first endpoint (rounded to an integer).

Note

Changes only the HORIZONTAL position (bar1) of the first endpoint; the price is untouched.

When to use

When you want to slide the start bar while keeping the price end fixed.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetX1(l, barIndex-40)
}

Moves the first endpoint 40 bars back, keeping its price.

lineSetX2(line, bar)

Changes the bar position of the line's second end. Called on each new bar to stretch a trend line up to the current bar.

Returns the same line handle.

line
line
A line handle created by lineNew.
bar
number
New bar index of the second endpoint.

Note

Changes only the second endpoint's bar index (bar2).

When to use

To slide where the line ends while keeping its price.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetX2(l, barIndex)
}

Moves the end to the current bar.

lineSetXloc(line, mod)

Location mode (bar_index/bar_time).

Returns the same line handle.

line
line
A line handle created by lineNew.
mod
string
Location mode: bar_index (bar order) or bar_time (timestamp).

Note

Sets the line's horizontal placement unit: bar_index places by bar order, bar_time by timestamp.

When to use

Use bar_time mode when you want the placement to hold across different timeframes.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetXloc(l, "bar_index")
}

Puts the line in bar-index location mode.

lineSetXy1(line, bar, price)

Changes the line's first endpoint.

Returns the same line handle (chainable).

line
line
A line handle created by lineNew.
bar
number
New bar index of the first endpoint.
price
number
New price level of the first endpoint (series → its value at that bar).

Note

Moves the FIRST endpoint (bar1, price1) together. If price is omitted, only the bar moves. Mutates the handle in place — no new line.

When to use

For lines whose one end you track live (e.g. keeping a dynamic trendline start fixed while updating its endpoint).

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetXy1(l, barIndex-30, close)
}

Moves the line's first endpoint 30 bars back and to the current close.

lineSetXy2(line, bar, price)

Changes the line's second endpoint.

Returns the same line handle.

line
line
A line handle created by lineNew.
bar
number
New bar index of the second endpoint.
price
number
New price level of the second endpoint.

Note

Moves the SECOND endpoint (bar2, price2) together. If price is omitted, only the bar updates.

When to use

To extend or update where the line ends as new bars arrive.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetXy2(l, barIndex, close)
}

Moves the line's end to the current bar and close.

lineSetY1(line, price)

Changes the price of the line's first end. To move a level line to a new price there is no need to delete and recreate it.

Returns the same line handle.

line
line
A line handle created by lineNew.
price
number
New price level of the first endpoint (series → its value at bar1).

Note

Changes only the VERTICAL position (price1) of the first endpoint. If you pass a series, its value at the line's current bar1 index is used.

When to use

To realign the line's start level while keeping its bar position.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetY1(l, close)
}

Moves the first endpoint to the current close level.

lineSetY2(line, price)

Changes the price of the line's second end. Used with `lineSetY1` to update the slope of the line.

Returns the same line handle.

line
line
A line handle created by lineNew.
price
number
New price level of the second endpoint.

Note

Changes only the second endpoint's price level (price2).

When to use

To realign the line's end level.

CODESCRIPT
if barstate.islast {
  l = lineNew(barIndex-15, low, barIndex, high)
  lineSetY2(l, high)
}

Moves the end to the current high level.

linefillDelete(fill)

Deletes the fill.

Returns nothing (na); the fill no longer appears on the next draw.

fill
linefill
A line-fill handle created by linefillNew.

Note

Marks the fill deleted; it is excluded from output at flush time. The underlying lines are not deleted.

When to use

To remove only the fill while keeping the lines.

CODESCRIPT
if barstate.islast {
  a = lineNew(barIndex-20, low, barIndex, low)
  b = lineNew(barIndex-20, high, barIndex, high)
  f = linefillNew(a, b, "#2962ff22")
  linefillDelete(f)
}

Deletes the fill, leaving the two lines.

linefillGetLine1(fill)

Returns the fill's first line.

Returns the handle of the fill's first line.

fill
linefill
A line-fill handle created by linefillNew.

Note

Read-only; returns the first line handle passed when creating the fill (you can then modify that line separately).

When to use

To reach one edge line of the fill and change its color/position.

CODESCRIPT
if barstate.islast {
  a = lineNew(barIndex-20, low, barIndex, low)
  b = lineNew(barIndex-20, high, barIndex, high)
  f = linefillNew(a, b, "#2962ff22")
  lineSetColor(linefillGetLine1(f), "#26a69a")
}

Colors the fill's first (lower) line green.

linefillGetLine2(fill)

Returns the fill's second line.

Returns the handle of the fill's second line.

fill
linefill
A line-fill handle created by linefillNew.

Note

Read-only; returns the second line handle passed when creating the fill.

When to use

To reach the fill's upper edge line.

CODESCRIPT
if barstate.islast {
  a = lineNew(barIndex-20, low, barIndex, low)
  b = lineNew(barIndex-20, high, barIndex, high)
  f = linefillNew(a, b, "#2962ff22")
  lineSetColor(linefillGetLine2(f), "#ef5350")
}

Colors the fill's second (upper) line red.

linefillNew(line1, line2, color?)

Fills the area between two lines. Used to highlight the inside of a channel or a band; a transparent colour keeps the chart visible. Both lines must already exist.

Returns a line-fill handle shading the area between the two lines.

line1
line
The first line handle (lineNew).
line2
line
The second line handle.
color
color
Optional. Fill color (default blue #2962ff, usually with alpha).

Note

Shades the area between two lines; both arguments must be line handles or it errors. You usually pass an alpha color (e.g. #2962ff22).

When to use

To shade a channel or band defined by two lines.

Limits

Arguments must be lines; another object type fails. At most 500 objects per kind are kept (FIFO).

CODESCRIPT
if barstate.islast {
  a = lineNew(barIndex-20, low, barIndex, low)
  b = lineNew(barIndex-20, high, barIndex, high)
  f = linefillNew(a, b, "#2962ff22")
}

A channel filling between the lower (low) and upper (high) lines in light blue.

linefillSetColor(fill, color)

Line-fill color.

Returns the same line-fill handle.

fill
linefill
A line-fill handle created by linefillNew.
color
color
New fill color.

Note

Changes the fill color. A non-string value is a no-op.

When to use

To recolor the channel fill by state.

CODESCRIPT
if barstate.islast {
  a = lineNew(barIndex-20, low, barIndex, low)
  b = lineNew(barIndex-20, high, barIndex, high)
  f = linefillNew(a, b)
  linefillSetColor(f, "#26a69a22")
}

Turns the channel fill light green.

polylineAll()

Returns an array of all currently existing (non-deleted) polyline handles. Result: Arr(len=0, [])

Returns an array of all currently existing (non-deleted) polyline handles (in creation order).

Note

Count with arraySize, access with arrayGet; usually to loop and delete/update polylines on barstate.islast. Deleted handles are excluded.

When to use

To bulk-clear/update all polylines on the chart (especially to delete old drawings on each re-run).

CODESCRIPT
polylineAll()

Returns every polyline the code has drawn as a single list.

polylineDelete(polyline)

Deletes the multi-line.

Returns nothing (na); the polyline no longer appears on the next draw.

polyline
polyline
A polyline handle created by polylineNew.

Note

Marks the polyline deleted; it is excluded from output at flush time.

When to use

To remove a pattern polyline that is no longer valid.

CODESCRIPT
if barstate.islast {
  bi = array.new_int()
  pr = array.new_float()
  array.push(bi, barIndex-10)
  array.push(pr, low)
  array.push(bi, barIndex)
  array.push(pr, high)
  pl = polylineNew(bi, pr)
  polylineDelete(pl)
}

Deletes the polyline right away.

polylineNew(bars, prices, color?, width?, curved?, closed?)

Multi-line connecting the points (arrays). curved=true → a curved line (spline through the points) instead of straight; closed=true → connects the last point back to the first (closed polygon). SECOND FORM: instead of bar/price arrays an array of chart POINTS may be given — polylineNew(points, color, width).

Returns a multi-segment (polyline) handle connecting the points in order.

bars
array
An array of bar indexes (array.new_int/array.new_float).
prices
array
An array of price levels; in the same order as the bar array.
color
color
Optional. Line color (default blue #2962ff).
width
number
Optional. Line width 1–4 (default 1).
curved
bool
Optional. true → connects the points with a curve (a spline through the points) instead of straight segments (default false).
closed
bool
Optional. true → connects the last point back to the first (a closed polygon) (default false).

Note

Connects points taken from two arrays (bar + price) in order; it uses as many points as the shorter array. If a price element is a series, its last value is used. width is clamped to 1–4. curved needs at least 3 points to bend; closed connects the last point back to the first (with curved the curve also closes). Both arguments must be arrays; otherwise it errors.

When to use

To draw a zigzag, a wave count or a multi-point pattern as a single drawing object.

Limits

Arrays should be equal length (the shorter one wins). At most 500 objects per kind are kept (FIFO).

Connects points taken from two arrays (bar + price) in order; it uses as many points as the shorter array. If a price element is a series, its last value is used. width is clamped to 1–4. Both arguments must be arrays; otherwise it errors.

CODESCRIPT
if barstate.islast {
  bi = array.new_int()
  pr = array.new_float()
  array.push(bi, barIndex-20)
  array.push(pr, low)
  array.push(bi, barIndex-10)
  array.push(pr, high)
  array.push(bi, barIndex)
  array.push(pr, close)
  pl = polylineNew(bi, pr, "#2962ff", 2)
}

A blue zigzag connecting three points (low→high→close).

polylineSetColor(polyline, color)

Multi-line color.

Returns the same polyline handle.

polyline
polyline
A polyline handle created by polylineNew.
color
color
New line color.

Note

Changes the polyline color. A non-string value is a no-op.

When to use

To recolor a pattern polyline by state.

CODESCRIPT
if barstate.islast {
  bi = array.new_int()
  pr = array.new_float()
  array.push(bi, barIndex-10)
  array.push(pr, low)
  array.push(bi, barIndex)
  array.push(pr, high)
  pl = polylineNew(bi, pr)
  polylineSetColor(pl, "#26a69a")
}

Colors the polyline green.

tableAll()

Returns an array of all currently existing (non-deleted) table handles. Result: Arr(len=0, [])

Returns an array of all currently existing (non-deleted) table handles (in creation order).

Note

Count with arraySize, access with arrayGet; usually to loop and delete/update tables on barstate.islast. Deleted handles are excluded.

When to use

To bulk-clear/update all tables on the chart (especially to delete old drawings on each re-run).

CODESCRIPT
tableAll()

Returns every table the code has drawn as a single list.

tableCell(table, column, row, text?, width?, height?, text_color?, text_halign?, text_valign?, text_size?, bgcolor?, tooltip?, text_font_family?, text_formatting?)

Writes text into a cell of the table. Columns and rows start at zero, and the column comes before the row. Text and background settings can be given here by position or by name (text_color = ...); the separate setters still work. Note: the older form that puts colours in slots 5 and 6 (tableCell(t, 0, 0, "Trend", "#ffffff", "#26a69a")) keeps working.

Returns the same table handle.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
text
string
Cell text (a number/series is converted to text; a series → its last value).
width
number
Optional. Cell width as a percentage of the indicator's space. Writing a colour into this slot still means text colour (the older form is kept).
height
number
Optional. Cell height as a percentage of the indicator's space. Writing a colour into this slot still means fill colour (the older form is kept).
text_color
color
Optional. Text color.
text_halign
string
Optional. Horizontal text alignment: left, center, right.
text_valign
string
Optional. Vertical text alignment: top, center, bottom.
text_size
number
Optional. Text size; a number or tiny/small/normal/large/huge.
bgcolor
color
Optional. Cell fill color.
tooltip
string
Optional. The note shown when the cell is hovered.
text_font_family
string
Optional. Font family: default or monospace.
text_formatting
string
Optional. Text formatting: none, bold, italic.

Note

Writes text into the (column, row) cell; text and fill settings can be given by position or by name (text_color = ...). If the text is a number/series it is auto-converted (a float is trimmed to 4 decimals, a series takes its last value). The older form that puts colours in slots 5 and 6 — tableCell(t, 0, 0, "Trend", "#ffffff", "#26a69a") — keeps working; a number in those slots means width/height.

When to use

To fill the cells of a panel opened with tableNew.

Limits

Column/row indexes are 0-based and must stay within the table's declared size.

Writes text into the (column, row) cell; optionally takes text and fill colors. If the text is a number/series it is auto-converted (a float is trimmed to 4 decimals, a series takes its last value).

CODESCRIPT
t = tableNew("topRight", 2, 1)
tableCell(t, 0, 0, "RSI", "#ffffff", "#26a69a")
tableCell(t, 1, 0, str.tostring(rsi(close,14)))

A green-filled 'RSI' header at the top right with the current RSI value beside it.

tableCellSetBgcolor(table, column, row, color)

Cell fill color.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
color
color
Cell fill color.

Note

Sets a single cell's fill (background) color. A non-string value is a no-op.

When to use

To color a specific value by state (e.g. positive → green cell).

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetBgcolor(t, 0, 0, "#26a69a")

Fills the cell green.

tableCellSetHeight(table, column, row, height)

Cell height (%).

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
height
number
Cell height (as a percentage of the chart height).

Note

Sets a single cell's height as a percentage (0 = automatic). A non-numeric value is a no-op.

When to use

To pin a row to a specific height.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableCellSetHeight(t, 0, 0, 8)

Sets the cell height to 8% of the chart height.

tableCellSetText(table, column, row, text)

Sets the cell text.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
text
string
New cell text (a number/series is converted to text).

Note

Changes an existing cell's text; the cell is created if absent. A number/series text is auto-converted.

When to use

To update a single cell without rebuilding the whole panel.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "...")
tableCellSetText(t, 0, 0, str.tostring(close))

Updates the cell text with the current close.

tableCellSetTextColor(table, column, row, color)

Sets the text colour of one cell in the table. Colouring the cells that report a state makes the panel fastest to read: green good, red bad, grey neutral.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
color
color
Cell text color.

Note

Sets a single cell's text color. A non-string value is a no-op.

When to use

To color a value by its sign.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTextColor(t, 0, 0, "#ef5350")

Colors the cell text red.

tableCellSetTextFontFamily(table, column, row, font)

Cell font family.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
font
string
Font family (e.g. monospace).

Note

Sets a single cell's font family. A non-string value is a no-op.

When to use

To align a numeric column with a monospace font.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTextFontFamily(t, 0, 0, "monospace")

Renders the cell in a monospace font.

tableCellSetTextFormatting(table, column, row, formatting)

Cell text formatting.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
formatting
string
Text formatting: bold / italic.

Note

Applies bold/italic formatting to a single cell. A non-string value is a no-op.

When to use

To render a header or key value in bold.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTextFormatting(t, 0, 0, "bold")

Renders the cell text in bold.

tableCellSetTextHalign(table, column, row, align)

Sets the horizontal alignment of the text in a cell: left, centre or right. Aligning numbers to the right lines up their digits and makes them easier to compare, while labels stay on the left.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
align
string
Horizontal alignment: left / center / right.

Note

Sets a single cell's horizontal text alignment. A non-string value is a no-op.

When to use

To right-align numeric values for a tidy column.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTextHalign(t, 0, 0, "right")

Right-aligns the cell text.

tableCellSetTextSize(table, column, row, size)

Cell text size.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
size
string
Text size: tiny/small/normal/large/huge or 7–40 pixels.

Note

Sets a single cell's text size. A name maps to its pixel equivalent; a number is clamped to 7–40.

When to use

To render a header or key value larger.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Title")
tableCellSetTextSize(t, 0, 0, "large")

Sets the cell text to 'large' size.

tableCellSetTextValign(table, column, row, align)

Cell vertical alignment.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
align
string
Vertical alignment: top / center / bottom.

Note

Sets a single cell's vertical text alignment. A non-string value is a no-op.

When to use

To pin cell text to the top/bottom.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTextValign(t, 0, 0, "top")

Top-aligns the cell text.

tableCellSetTooltip(table, column, row, text)

Cell tooltip.

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
text
string
Tooltip text.

Note

Adds a hover tooltip to a single cell. A non-string value is a no-op.

When to use

To provide detail that does not fit a compact cell via a tooltip.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Value")
tableCellSetTooltip(t, 0, 0, "RSI of the last 14 bars")

Adds an explanatory tooltip to the cell.

tableCellSetWidth(table, column, row, width)

Cell width (%).

Returns nothing (na); updates the cell in place.

table
table
A table handle created by tableNew.
column
number
Column index (0-based).
row
number
Row index (0-based).
width
number
Cell width (as a percentage of the chart width).

Note

Sets a single cell's width as a percentage (0 = automatic). A non-numeric value is a no-op.

When to use

To pin a column to a specific width.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableCellSetWidth(t, 0, 0, 10)

Sets the cell width to 10% of the chart width.

tableClear(table, start_column?, start_row?, end_column?, end_row?)

Clears table cells. With only the table, every cell is cleared; with column/row bounds, only that rectangle is cleared.

Returns nothing (na); the specified cells are emptied.

table
table
A table handle created by tableNew.
start_column
number
Optional. First column of the rectangle to clear (0-based). If omitted, the whole table is cleared.
start_row
number
Optional. First row of the rectangle to clear (0-based).
end_column
number
Optional. Last column. Defaults to startColumn.
end_row
number
Optional. Last row. Defaults to startRow.

Note

With only the table, every cell is cleared. With column/row bounds, only that rectangle is cleared; the table object and its position remain in both cases. Clears all cell contents of the table; the table object and its position remain and can be refilled.

When to use

To rebuild the panel from scratch on each update.

Clears all cell contents of the table; the table object and its position remain and can be refilled.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Old")
tableClear(t)
tableCell(t, 0, 0, "New")

Clears the cells and refills with a new value.

tableDelete(table)

Deletes the table.

Returns nothing (na); the table no longer appears on the next draw.

table
table
A table handle created by tableNew.

Note

Marks the table deleted; it is excluded from output at flush time.

When to use

To remove the panel entirely when a condition no longer holds.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
if rsi(close,14) < 30 {
  tableDelete(t)
}

Deletes the panel while RSI is below 30.

tableMergeCells(table, c1, r1, c2, r2)

Merges the cells in the given range into one. Used to stretch a heading across several columns.

Returns nothing (na); the given range is merged into a single cell.

table
table
A table handle created by tableNew.
c1
number
Start column of the merge range (0-based).
r1
number
Start row.
c2
number
End column.
r2
number
End row.

Note

Merges the cells in the (c1,r1)–(c2,r2) rectangular range; handy for header rows.

When to use

To span a header across multiple columns.

CODESCRIPT
t = tableNew("topRight", 2, 2)
tableCell(t, 0, 0, "Title")
tableMergeCells(t, 0, 0, 1, 0)

Merges the two top-row cells into a single header.

tableNew(position, column, row, bgcolor?, border_width?, border_color?, frame_width?, frame_color?)

Creates a table pinned to a corner of the chart; it does not scroll with price but stays in place. Convenient for showing summary information. The row and column counts are given up front and the cells are filled later with `tableCell`. ⚠ Rebuilding it on every bar is wasted work; putting it inside `if barstate.islast` is enough.

A table object; you fill its cells with tableCell(t, column, row, text).

position
string
Position: topRight/topLeft/bottomRight/bottomLeft/middleCenter etc.
column
number
Number of columns.
row
number
Number of rows.
bgcolor
color
Table background color.
border_width
number
Width of lines between cells (px).
border_color
color
Color of lines between cells.
frame_width
number
Outer frame thickness (px).
frame_color
color
Outer frame color.

Note

Create it with tableNew, write cells with tableCell. The position is fixed to the chart (not tied to a bar); it stays in place when the chart scrolls.

When to use

For a fixed summary or readout panel in a corner of the screen. If you need text tied to a bar, use label.

Limits

Cell indexes are 0-based and must stay within the declared size. The table does not scale with the chart's values; it is a fixed corner box.

Not for

Not for text tied to a specific bar and sitting at a price level — use label for that. To draw a line or shape over the chart, prefer plot or plotshape. The table is a fixed corner box; do not use it for anything that should move with price as you scroll and zoom.

BTCUSDT5mtableNew — corner summary panelSymbolBTCUSDTPrice62,522RSI(14)53.8SignalNeutral
CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "RSI: " + str.tostring(rsi(close,14)))

The current RSI value in a single cell at the top right.

CODESCRIPT
t = tableNew("topRight", 2, 2)
tableCell(t, 0, 0, "RSI")
tableCell(t, 1, 0, str.tostring(rsi(close,14)))
tableCell(t, 0, 1, "ATR")
tableCell(t, 1, 1, str.tostring(atr(14)))

A 2x2 table at the top right: RSI and ATR rows.

tableSetBg(table, color)

Sets the table's background colour. A slightly dark, mostly opaque background is enough to separate the panel from the chart instead of letting it float over it.

Returns the same table handle.

table
table
A table handle created by tableNew.
color
color
Table background (fill) color.

Note

Sets the table's overall background color. A non-string value is a no-op.

When to use

To give the whole panel a common background color.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableSetBg(t, "#1e222d")

Gives the table a dark background color.

tableSetBorderColor(table, color)

Sets the colour of the lines that separate the cells. It is kept apart from the outer frame: keeping the inner lines fainter separates the rows without tiring the eye.

Returns the same table handle.

table
table
A table handle created by tableNew.
color
color
Cell border color.

Note

Sets the color of the borders (grid) between cells. A non-string value is a no-op.

When to use

To make the panel grid visible.

CODESCRIPT
t = tableNew("topRight", 2, 2)
tableCell(t, 0, 0, "A")
tableSetBorderColor(t, "#787b86")

Makes the cell borders grey.

tableSetBorderWidth(table, width)

Sets the thickness of the lines between cells. Zero removes the inner lines and the panel reads as one block.

Returns the same table handle.

table
table
A table handle created by tableNew.
width
number
Cell border width (pixels, integer).

Note

Sets the thickness of the cell border lines (integer). A non-numeric value is a no-op.

When to use

To thicken the grid lines for emphasis.

CODESCRIPT
t = tableNew("topRight", 2, 2)
tableCell(t, 0, 0, "A")
tableSetBorderColor(t, "#787b86")
tableSetBorderWidth(t, 2)

Sets the cell borders to 2 pixels.

tableSetFrameColor(table, color)

Sets the colour of the table's outer frame. The frame separates the panel from the chart; a muted grey works in most themes.

Returns the same table handle.

table
table
A table handle created by tableNew.
color
color
Outer frame color.

Note

Sets the color of the table's OUTER frame (separate from the cell borders). A non-string value is a no-op.

When to use

To bound the panel with an outer frame.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableSetFrameColor(t, "#2962ff")

Gives the panel a blue outer frame.

tableSetFrameWidth(table, width)

Sets the thickness of the table's outer frame. Zero removes the frame entirely; one pixel is enough for most panels.

Returns the same table handle.

table
table
A table handle created by tableNew.
width
number
Outer frame width (pixels, integer).

Note

Sets the outer frame thickness (integer). A non-numeric value is a no-op.

When to use

To thicken the outer frame for a bolder panel.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableSetFrameColor(t, "#2962ff")
tableSetFrameWidth(t, 2)

Sets the outer frame to 2 pixels.

tableSetPosition(table, position)

Table position.

Returns the same table handle.

table
table
A table handle created by tableNew.
position
string
Position: topRight/topLeft/bottomRight/bottomLeft/middleCenter etc.

Note

Changes the table's corner/position on screen. A non-string value is a no-op.

When to use

To move the panel to a corner that does not cover price.

CODESCRIPT
t = tableNew("topRight", 1, 1)
tableCell(t, 0, 0, "Pane")
tableSetPosition(t, "bottomLeft")

Moves the panel to the bottom-left corner.