Objects
118 entries. What each one takes, what it returns, and a working example.
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).
boxAll()Returns every box the code has drawn as a single list; used to count or clear them all at once.
Clones the box.
Returns a NEW box handle copying all properties of the source box.
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.
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.
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.
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.
if barstate.islast { b = boxNew(barIndex-10, high, barIndex, low) if close > high { boxDelete(b) } }
Deletes the box if close breaks above the high.
Bottom edge price.
Returns the bottom edge price (price2).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetBottom(b), "x") }
Plots the bottom edge price.
Left edge bar.
Returns the left edge bar index (bar1).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetLeft(b), "x") }
Plots the left edge bar index.
Right edge bar.
Returns the right edge bar index (bar2).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetRight(b), "x") }
Plots the right edge bar index.
Top edge price.
Returns the top edge price (price1).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetTop(b), "x") }
Plots the top edge price.
First-corner bar index.
Returns the first corner's bar index (same value as boxGetLeft).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetX1(b), "x") }
Plots the first corner's bar index.
Second-corner bar index.
Returns the second corner's bar index (same value as boxGetRight).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetX2(b), "x") }
Plots the second corner's bar index.
First-corner price.
Returns the first corner's price (same value as boxGetTop).
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) plot(boxGetY1(b), "x") }
Plots the first corner's price.
Second-corner price.
Returns the second corner's price (same value as boxGetBottom).
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.
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.
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.
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'.
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.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetBgColor(b, "#ef535022") }
Shades the box with a light red fill.
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.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetBorderColor(b, "#ffffff") }
Colors the box border white.
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.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetBorderStyle(b, "dashed") }
Makes the box border dashed.
Border width.
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetBorderWidth(b, 2) }
Sets the box border to 2 pixels.
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.
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.
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.
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.
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.
Changes the box color.
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetColor(b, "#26a69a") }
Colors the box outline green.
Box extension (none/left/right/both).
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetExtend(b, "right") }
Extends the box to the right.
Left edge bar.
Returns the same box handle.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetText(b, "Supply Zone") }
Writes 'Supply Zone' inside the box.
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.
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).
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.
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.
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.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetText(b, "Important") boxSetTextFormatting(b, "bold") }
Renders the text in bold.
Horizontal text alignment (left/center/right).
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetText(b, "Zone") boxSetTextHalign(b, "left") }
Left-aligns the text.
Text size.
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetText(b, "Zone") boxSetTextSize(b, "large") }
Sets the text to 'large' size.
Vertical text alignment (top/center/bottom).
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetText(b, "Zone") boxSetTextValign(b, "top") }
Top-aligns the text.
Text wrapping (none/auto).
Returns the same box handle.
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.
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.
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.
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.
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.
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.
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.
Location mode.
Returns the same box handle.
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.
if barstate.islast { b = boxNew(barIndex-15, high, barIndex, low) boxSetXloc(b, "bar_index") }
Puts the box in bar-index location mode.
Changes the box's first corner.
Returns the same box handle.
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.
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.
Changes the box's second corner.
Returns the same box handle.
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.
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).
Copy of a drawing point.
Returns an independent copy of the given drawing point.
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.
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).
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.
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).
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.
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.
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.
if barstate.islast { p1 = chartPointNew(barIndex-10, time, low) p2 = chartPointNow(high) l = lineNew(p1, p2, "#26a69a") }
Draws a green line between two chartPoints.
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.
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).
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.
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).
labelAll()Returns every label the code has drawn as a single list.
Clones the label.
Returns a NEW label handle copying all properties of the source label.
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.
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.
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.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) if close < open { labelDelete(e) } }
Deletes the label on a down bar.
Returns the label text.
Returns the label's text (string); an empty string if the handle is invalid.
Note
Read-only; does not mutate the label.
When to use
To read a label's text and reuse it in another drawing.
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.
Label bar index.
Returns the label's horizontal position: time (ms) if xloc is bar_time, otherwise the bar index.
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.
if barstate.islast { e = labelNew(close, "X", barIndex) plot(labelGetX(e), "x") }
Plots the label's bar index.
Label price.
Returns the label's price level; na if unset.
Note
Read-only; does not mutate the label.
When to use
To use a label's price level in another computation.
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.
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.
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.
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.
Changes the label color.
Returns the same label handle.
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.
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.
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.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetPoint(e, chartPointNow(high)) }
Moves the label to a high point on the current bar.
Label font size (tiny/small/normal/large or a number).
Returns the same label handle.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetSize(e, "large") }
Sets the label to 'large' size.
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.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetStyle(e, "label_up") }
Turns the label into an upward-pointing style.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetTextcolor(e, "#000000") }
Colors the text black.
Tooltip shown on hover.
Returns the same label handle.
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.
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.
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.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetX(e, barIndex-5) }
Moves the label 5 bars back.
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.
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.
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.
Changes both the bar and the price position of a label in one call.
Returns the same label handle.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetXy(e, barIndex, high) }
Moves the label to the current bar and high level.
Price position.
Returns the same label handle.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetY(e, high) }
Moves the label to the current high level.
Vertical location mode (price/abovebar/belowbar).
Returns the same label handle.
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.
if barstate.islast { e = labelNew(close, "Note", barIndex) labelSetYloc(e, "abovebar") }
Pins the label above the bar.
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).
lineAll()Returns every line the code has drawn as a single list.
Clones the line (returns a new handle).
Returns a NEW line handle copying all properties of the source line.
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.
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.
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.
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).
if barstate.islast { l = lineNew(barIndex-10, low, barIndex, high) if close < low { lineDelete(l) } }
Deletes the line if close drops below the low.
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.
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.
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.
First-endpoint bar index.
Returns the first endpoint's bar index (as a float).
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) plot(lineGetX1(l), "x") }
Plots the first endpoint's bar index.
Second-endpoint bar index.
Returns the second endpoint's bar index.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) plot(lineGetX2(l), "x") }
Plots the second endpoint's bar index.
First-endpoint price.
Returns the first endpoint's price level.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) plot(lineGetY1(l), "x") }
Plots the first endpoint's price.
Second-endpoint price.
Returns the second endpoint's price level.
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.
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.
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.
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.
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).
Changes the line color.
Returns the same line handle.
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).
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.
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.
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.
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).
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.
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.
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.
Changes the line style: solid / dashed / dotted, or arrowhead-tipped arrow_left / arrow_right / arrow_both.
Returns the same line handle.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetStyle(l, "dotted") }
Turns the line into a dotted style.
Line width (1-4).
Returns the same line handle.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetWidth(l, 3) }
Sets the line to width 3.
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.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetX1(l, barIndex-40) }
Moves the first endpoint 40 bars back, keeping its price.
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.
Note
Changes only the second endpoint's bar index (bar2).
When to use
To slide where the line ends while keeping its price.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetX2(l, barIndex) }
Moves the end to the current bar.
Location mode (bar_index/bar_time).
Returns the same line handle.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetXloc(l, "bar_index") }
Puts the line in bar-index location mode.
Changes the line's first endpoint.
Returns the same line handle (chainable).
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).
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.
Changes the line's second endpoint.
Returns the same line handle.
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.
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.
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.
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.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetY1(l, close) }
Moves the first endpoint to the current close level.
Changes the price of the line's second end. Used with `lineSetY1` to update the slope of the line.
Returns the same line handle.
Note
Changes only the second endpoint's price level (price2).
When to use
To realign the line's end level.
if barstate.islast { l = lineNew(barIndex-15, low, barIndex, high) lineSetY2(l, high) }
Moves the end to the current high level.
Deletes the fill.
Returns nothing (na); the fill no longer appears on the next draw.
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.
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.
Returns the fill's first line.
Returns the handle of the fill's first line.
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.
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.
Returns the fill's second line.
Returns the handle of the fill's second line.
Note
Read-only; returns the second line handle passed when creating the fill.
When to use
To reach the fill's upper edge line.
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.
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).
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.
Line-fill color.
Returns the same line-fill handle.
Note
Changes the fill color. A non-string value is a no-op.
When to use
To recolor the channel fill by state.
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.
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).
polylineAll()Returns every polyline the code has drawn as a single list.
Deletes the multi-line.
Returns nothing (na); the polyline no longer appears on the next draw.
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.
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.
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.
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.
Note
Changes the polyline color. A non-string value is a no-op.
When to use
To recolor a pattern polyline by state.
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.
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).
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.
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).
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Deletes the table.
Returns nothing (na); the table no longer appears on the next draw.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
t = tableNew("topRight", 1, 1) tableCell(t, 0, 0, "Pane") tableSetPosition(t, "bottomLeft")
Moves the panel to the bottom-left corner.