CODESCRIPT

Drawing

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

box(bar1, price1, bar2, price2, color?, text?)

Draws a rectangle region.

Does not return a value; adds a rectangular region with the given corners.

bar1
number
The bar index of the left edge.
price1
number
The price of the top edge.
bar2
number
The bar index of the right edge.
price2
number
The price of the bottom edge.
color
color
Optional. The border color (default blue).
text
string
Optional. A label to write inside the box.

Note

The price arguments may be series. For highlighting a supply/demand zone, a consolidation range or an event window.

Limits

bar1 and bar2 must each be a single NUMBER → drawing in bulk with a series (barIndex) raises an error; call it inside an if block, where the bar value collapses to a scalar. The price arguments may be series. Many boxes slow the chart down (there is a count limit).

CODESCRIPT
box(0, highest(high, 50), 50, lowest(low, 50), "#2962ff", "zone")
plot(close)

Frames the high-low range of the first 50 bars with a box labelled "bolge".

infoTable(...rows)

Shows an info/score table in a corner.

Does not return a value; adds a text panel in the top-right corner with the rows.

...satırlar
any
The rows to write into the panel (usually built with text).

Note

Each argument becomes a row. Build rows with text to embed live values. There is one panel per call site: even when the code calls it on every bar, a single panel is drawn and it shows the values from the last bar.

Each argument becomes a row. Build rows with text to embed live values; usually called once on the last bar.

CODESCRIPT
if barstate.islast {
  infoTable(text("Close: {0}", close), text("RSI: {0}", rsi(close, 14)))
}
plot(close)

On the last bar shows close and RSI values in a two-row panel.

label(price, text, bar?, color?, style?, size?)

Places a text box at a given price and bar position on the chart. Without a bar it lands on the last one. ⚠ The bar value must be a single number: instead of calling it on every bar, call it inside an `if` only where it is needed. Many labels slow the chart down and there is a count limit.

Returns nothing; it draws a text label box onto the chart.

price
number
Vertical position of the label (price).
text
string
Label text (per-bar scalar).
bar
number
Optional. Bar index (default current bar).
color
color
Optional. Background color.
style
string
Optional. labelup/labeldown etc.
size
string
Optional. Size.

Note

Usually called inside a conditional block: if condition { label(...) }. This way the bar index becomes a scalar and dynamic text (str.tostring) can be used. Use in text to split the label across multiple lines, which also shifts it to avoid overlapping another marker. Call the label inside a conditional block (if cond { ... }) so the bar index resolves to a single value and the text can show the current reading.

When to use

To show free text or a dynamic value (a price, a number). Use plotshape for a fixed shape and tableNew for a fixed-position panel.

Limits

The bar value must be a single number → passing a series (bar_index) directly in a vector run fails; call it bar by bar inside an if block. Many labels hurt performance (there is a count limit).

Not for

Not for a fixed shape repeated on every bar — plotshape/plotchar are lighter for that. For a summary that stays pinned in a corner and does not scroll, use tableNew. Do not create a label on a great many bars; you will hit the count limit and slow the chart down.

Tip

Call the label inside a conditional block (if cond {... }) so the bar index resolves to a single value and the text can show the current reading.

BTCUSDT5m62,522-0.28%label — a tag on the peak bar62,29862,40862,51862,62862,737VOLUME62,522PEAK 62,700

Usually called inside a conditional block: if condition { label(...) }. This way the bar index becomes a scalar and dynamic text (str.tostring) can be used. Use in text to split the label across multiple lines, which also shifts it to avoid overlapping another marker.

Call the label inside a conditional block (if cond { ... }) so the bar index resolves to a single value and the text can show the current reading.

CODESCRIPT
if crossover(close, sma(close,10)) {
  label(low, "AL", barIndex, color="#26a69a", style="labelup")
}

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

CODESCRIPT
if barstate.islast {
  label(close, "Last: " + str.tostring(close), last_bar_index)
}

A dynamic label showing the closing price on the last bar.

trendline(bar1, price1, bar2, price2, color?, style?)

Trend line between two points (bar-offset: 0=last, negative=past).

Does not return a value; adds a straight line between the two points.

bar1
number
The bar index of the first point.
price1
number
The price of the first point.
bar2
number
The bar index of the second point.
price2
number
The price of the second point.
color
color
Optional. The line color (default blue).
style
string
Optional. "solid", "dashed" or "dotted".

Note

The price arguments may be series; then the value at the relevant bar is used. For placing trend, support/resistance or channel lines by hand.

Limits

bar1 and bar2 must each be a single NUMBER → drawing in bulk with a series (barIndex) raises an error; call it inside an if block, where the bar value collapses to a scalar. The price arguments may be series; the value at that bar is used. Many lines slow the chart down (there is a count limit).

CODESCRIPT
trendline(0, low, 50, high)
plot(close)

Draws a line from the first bar's low to bar 50's high.

CODESCRIPT
trendline(0, lowest(low, 50), 50, highest(high, 50), "#26a69a", "dashed")
plot(close)

Connects the low and high of the first 50 bars with a green dashed line.