CODESCRIPT

Visual

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

alpha(color)

Opacity of the hex color (0-1; #rrggbbaa). Result: 0.5019607843

Returns the color's opacity as a number 0-1. If the color has no alpha channel (6-digit #rrggbb) or is invalid, it returns 1 (fully opaque).

color
color
The hex color whose opacity is read. An #rrggbbaa form carrying an alpha channel is expected.

Note

It is a color decomposer: it converts a hex color's alpha (opacity) byte to the 0-1 scale (e.g. 0x80 → 0.502). Where red/green/blue give channels, alpha gives opacity.

When to use

To numerically read how transparent a color is: to preserve/change opacity when rebuilding with rgb, or to make a decision against a threshold.

Not for

Not for the red/green/blue components — use red/green/blue. To produce a color use rgb.

CODESCRIPT
c = "#2962ff80"
plot(alpha(c), "Opacity")

The opacity of #2962ff80 (0x80 → ~0.502) is plotted as a flat line.

barcolor(color, offset?, display?)

Colors the candles. Single color or a color series via iff. offset: shifts the coloring N bars right(+)/left(-).

Returns nothing; colors the candle bodies with the given color.

color
color
A single hex color (all candles) or a bar-by-bar color series (usually via iff). A bar given na/non-color stays unpainted.
offset
number
Optional. Shifts the coloring N bars right (positive) / left (negative) (default 0).
display
string
Optional. If display.none is passed this coloring is not applied (candles stay unpainted); display.all or omitting it keeps it applied (default).

Note

The color can be a series; with iff each candle takes its own color by condition. barcolor colors INSTANTANEOUSLY — each bar's color depends only on that bar's condition. To color a region continuously until the signal changes, use colorBySignal.

When to use

To show a condition directly on price by coloring the candles: up/down, above/below a trend filter, a volume threshold breach. It carries the signal into the candle color without opening a separate panel.

Not for

Not for holding the color across the whole region between signals — that forward-fill is colorBySignal. To color by strategy position (long/short/flat) use colorByPosition. To shade the background (not the candle) use bgcolor.

CODESCRIPT
barcolor(iff(close > open, "#26a69a", "#ef5350"))

Up candles are colored green, down candles red.

CODESCRIPT
barcolor(iff(close > sma(close,50), "#26a69a", "#787b86"))

Candles are green while price is above SMA50, gray while below.

bgcolor(color, offset?, display?)

Colors the bar background (market-state highlight). offset: shifts the coloring N bars right(+)/left(-).

Returns nothing; colors the bars' background (the full vertical stripe).

color
color
A single hex color (all bars) or a bar-by-bar color series (usually produced with iff). Passing na/non-color for a bar leaves that bar unshaded.
offset
number
Optional. Shifts the shading N bars right (positive) / left (negative) (default 0).
display
string
Optional. If display.none is passed this coloring is not applied (background stays unshaded); display.all or omitting it keeps it applied (default).

Note

The color can be a series; with iff you give a different color per bar by condition (or na → no shading). bgcolor paints the entire vertical bar stripe — it is independent of price level. Passing na in the second iff branch shades only the bars that meet the condition — keeping the chart free of needless color.

When to use

To highlight market state and condition regions: overbought/oversold windows, trend direction, session hours, or bars where a filter is active. It shades the background without touching price.

Not for

Not for a single horizontal level (hline), not for shading BETWEEN two series (fill), not for coloring the candles themselves (barcolor). Prefer translucency; an opaque color hides the candles.

Tip

Passing na in the second iff branch shades only the bars that meet the condition — keeping the chart free of needless color.

The color can be a series; with iff you give a different color per bar by condition (or na → no shading). bgcolor paints the entire vertical bar stripe — it is independent of price level.

Passing na in the second iff branch shades only the bars that meet the condition — keeping the chart free of needless color.

CODESCRIPT
bgcolor(iff(close > open, "#26a69a22", "#ef535022"))

Up bars get a translucent green background, down bars a translucent red one.

CODESCRIPT
bgcolor(iff(rsi(close,14) > 70, "#ef535033", na))

Only RSI>70 (overbought) bars get a red background; other bars stay unshaded (na).

blue(color)

Blue channel of the hex color (0-255). Result: 154

Returns the color's blue channel as a number 0-255 (invalid color → 0).

color
color
The hex color (#rgb / #rrggbb / #rrggbbaa) whose blue channel is read.

Note

It is a color decomposer: it extracts the blue component from a hex color. Together with red/green/alpha it is used to take a color apart and rebuild it with rgb.

When to use

To process a color channel by channel: to change opacity and reassemble, to compute a gradient between two colors, or to adjust a shade conditionally.

Not for

Not for producing a color (rgb). To read opacity use alpha.

CODESCRIPT
base = "#2962ff"
channel = blue(base)
plot(channel, "Blue Channel")

The blue channel (255) of #2962ff is plotted as a flat line.

colorByPosition(long?, short?, flat?)

Colors candles by strategy position: long / short / flat.

Returns nothing; after the backtest it colors the candles by the strategy position state.

long
color
Optional. Candle color while in a long position (default #26a69a).
short
color
Optional. Candle color while in a short position (default #ef5350).
flat
color
Optional. Candle color while flat (no position) (default #787b86).

Note

It requires a strategy (a position must be opened with enterLong/enterShort). Colors are applied after the backtest runs, by looking at each bar's position: long>0 → long color, short<0 → short color, otherwise flat. The actual position state, not a condition, decides.

When to use

To see directly in the candle color when the strategy is in the market (long/short) and when it is flat. It is the fastest way to visually audit the positions the backtest held.

Not for

It does nothing without a strategy (positions) — to just color a condition use barcolor/colorBySignal. For signal-based region coloring (without opening positions) use colorBySignal.

CODESCRIPT
fast = sma(close, 5)
slow = sma(close, 20)
enterLong(crossover(fast, slow))
enterShort(crossunder(fast, slow))
colorByPosition("#26a69a", "#ef5350", "#787b86")

Candles are green while long, red while short, gray while flat.

colorBySignal(longSignal, shortSignal, longColor?, shortColor?, flatColor?)

Colors candles by signal state: long / short / flat.

Returns nothing; colors candle regions by forward-filling the signal state.

longSignal
bool
The signal that starts the green (long) region; the color turns green from the bar where it is true.
shortSignal
bool
The signal that starts the red (short) region; the color turns red from the bar where it is true.
longColor
color
Optional. Long region color (default #26a69a).
shortColor
color
Optional. Short region color (default #ef5350).
flatColor
color
Optional. Neutral region color before the first signal (default #787b86).

Note

It takes two signals and holds STATE: on longSignal the region turns green and stays so until shortSignal arrives; on shortSignal it turns red. Before the first signal it uses the flat color. Where barcolor(iff(...)) colors each bar instantaneously and looks speckled, this produces continuous green/red blocks.

When to use

To show a buy/sell signal pair as uninterrupted regions: it colors not just the signal bar but every bar after it in that direction. More readable than barcolor for seeing trend and market state blocks cleanly.

Not for

Not for instantaneous (signal-bar-only) coloring — that is barcolor. To color by strategy position (actual long/short) use colorByPosition; colorBySignal works from raw signals without opening positions.

CODESCRIPT
colorBySignal(crossover(close, sma(close,20)), crossunder(close, sma(close,20)))

The region turns green when price crosses above SMA20 and red when it crosses below; gray until the first signal.

CODESCRIPT
buy = crossover(close, sma(close,20))
sell = crossunder(close, sma(close,20))
colorBySignal(buy, sell, "#00c853", "#d50000", "#9e9e9e")

The same signals are colored as continuous blocks with custom green/red/gray tones.

fill(a, b, color?)

Fills the area between two things — a/b can be a plot series, a constant, or an hline(). E.g. between Bollinger bands or two horizontal levels: fill(hline(30), hline(70),...).

Returns nothing; shades the area between the a and b series with color.

a
series
One edge of the band: a plot series, a constant number, or an hline() (a horizontal level).
b
series
The other edge of the band: a plot series, a constant number, or an hline() (a horizontal level).
color
color
Optional. Fill color (default #2196f3). Use a hex with an alpha channel for translucency (e.g. #2196f322).

Note

Both edges may be series; a constant or an hline() becomes a fixed horizontal level on every bar. A fill between two hline()s (fill(hline(30), hline(70),...)) shades fixed regions like an overbought/oversold band. The fill covers the vertical gap between a and b; the area is shaded correctly even where the edges cross. You usually plot/hline both edges as well to make the band visible. Add alpha to the color (e.g. #2196f322 — the trailing 22 is opacity) so the candles under the fill stay visible.

When to use

To highlight the space between two lines: the inside of an envelope/channel, the gap between two moving averages, or the body of a band (upper/lower). It visually emphasizes the trend widening and narrowing.

Not for

Not for drawing a single line — use plot. If you want to color the bar background (the whole vertical stripe, independent of price) use bgcolor; fill only shades BETWEEN two series.

Tip

Add alpha to the color (e.g. #2196f322 — the trailing 22 is opacity) so the candles under the fill stay visible.

Both edges may be series; a constant number is broadcast to every bar. The fill covers the vertical gap between a and b; the area is shaded correctly even where the edges cross. You usually plot both edges as well to make the band visible.

Add alpha to the color (e.g. #2196f322 — the trailing 22 is opacity) so the candles under the fill stay visible.

CODESCRIPT
fast = ema(close, 12)
slow = ema(close, 26)
plot(fast)
plot(slow)
fill(fast, slow, "#2196f3")

The area between EMA12 and EMA26 is shaded blue; the band widens as the two averages spread apart.

CODESCRIPT
b = bb(close, 20, 2)
plot(b.upper)
plot(b.lower)
fill(b.upper, b.lower, "#2962ff22")

The body between the Bollinger upper and lower bands fills with translucent blue.

green(color)

Green channel of the hex color (0-255). Result: 166

Returns the color's green channel as a number 0-255 (invalid color → 0).

color
color
The hex color (#rgb / #rrggbb / #rrggbbaa) whose green channel is read.

Note

It is a color decomposer: it extracts the green component from a hex color. Together with red/blue/alpha it is used to take a color apart and rebuild it with rgb.

When to use

To process a color channel by channel: to change opacity and reassemble, to compute a gradient between two colors, or to adjust a shade conditionally.

Not for

Not for producing a color (rgb). To read opacity use alpha.

CODESCRIPT
base = "#26a69a"
channel = green(base)
plot(channel, "Green Channel")

The green channel (166) of #26a69a is plotted as a flat line.

hline(price, title?, color?, style?, width?, display?)

Horizontal fixed level line (e.g. overbought 70).

Returns nothing; draws a horizontal constant level on the price panel.

price
number
The fixed price level to draw the line at. If a series is given, its value on the last bar is taken and pinned there (the line does not move bar to bar).
title
string
Optional. Label for the level.
color
color
Optional. Line color (hex).
style
string
Optional. Line style: solid/dashed/dotted (default dashed). The dotted form `hline.style_dashed` may also be used (identical result).
width
number
Optional. Line thickness in pixels (default 1).
display
string
Optional. If display.none is passed this line is hidden (not drawn on the chart); display.all or omitting it keeps it visible (default).

Note

The level is a single constant number — it does not change bar to bar. If you pass an indicator series (e.g. sma(close,50)) only its last-bar value is used to draw a flat line at that height; for a moving line use plot. For multiple thresholds on the same chart call hline several times (e.g. 70 and 30); each becomes an independent level.

When to use

To mark fixed support/resistance, targets, stops, or threshold levels like 70/30. Ideal for showing overbought/oversold bands.

Not for

Not for drawing a value that moves bar to bar (a moving average, a band) — use plot for that. If you want to shade a background region instead of a price level, use bgcolor.

Tip

For multiple thresholds on the same chart call hline several times (e.g. 70 and 30); each becomes an independent level.

The level is a single constant number — it does not change bar to bar. If you pass an indicator series (e.g. sma(close,50)) only its last-bar value is used to draw a flat line at that height; for a moving line use plot.

For multiple thresholds on the same chart call hline several times (e.g. 70 and 30); each becomes an independent level.

CODESCRIPT
hline(70, "Overbought", "#ef5350")

Red dashed horizontal line at level 70, labeled `Aşırı Alım`.

CODESCRIPT
hline(30, "Oversold", "#26a69a", "dotted", 2)

Green dotted horizontal line at level 30, 2px thick.

location.abovebar / belowbar / top / bottom / absolute / price

Placement names for plotshape/plotchar (dot access). location.abovebar is identical to "abovebar".

CODESCRIPT
plotshape(close > open, style=shape.circle, location=location.belowbar)

Draws a circle BELOW every bar that closes above its open; without a location the shape sits at the bar's own level.

mark(condition, style?, location?, color?, text?, size?)

Draws a mark on bars where condition is true.

Returns nothing; stamps a mark on bars where the condition is true.

condition
bool
A mark is stamped on bars where this is true (≠0/na).
style
string
Optional. Mark shape (e.g. circle/triangleup/triangledown/arrowup/arrowdown/square/diamond; default circle).
location
string
Optional. Location: abovebar/belowbar/top/bottom (default abovebar).
color
color
Optional. Mark color (default #2962ff).
text
string
Optional. Short text next to the mark (e.g. AL/SAT).
size
string
Optional. Size of the marker icon (and its text): tiny/small/normal/large/huge or a number (pixels, 7-40). Default normal.

Note

condition is a series; one mark is drawn per true bar. It is a compact helper for quickly flagging signals — location and size are adjustable, but it lacks the finer controls (offset/textcolor) of plotshape.

When to use

To quickly flag buy/sell bars or bars where a condition fires. It is the first choice when you want signal points visible with minimal code.

Not for

Not for long/free text or a boxed label — use label. If you need to fine-tune the exact position (offset) or text color separately, prefer plotshape/plotchar. Do not tie it to a condition true on every bar; the marks pile up.

CODESCRIPT
mark(crossover(close, sma(close,20)), "triangleup", "belowbar", "#26a69a", "AL")

Green up-triangle with 'AL' text below the bar where price crosses above SMA20.

CODESCRIPT
mark(rsi(close,14) > 70, "circle", "abovebar", "#ef5350", "", "small")

Small red circle above the bar on RSI>70 bars.

plot(series, title?, color?, pane?, style?, linewidth?, linestyle?, offset?, display?, trackprice?, histbase?, axisLabel?)

Plots a series on the chart. style: line/stepline/histogram/columns/area/circles/cross (default line) — all 7 fully render on both the price pane and sub-panes (⚠ one limit: combined with a non-zero offset on the price pane it still draws as a line, with a warning). linewidth: 1-4. linestyle: solid/dashed/dotted. offset: shifts the line N bars right(+)/left(-) (visual only; the calculation series is unchanged). series must be numeric (passing text/string raises a clear error). `trackprice` draws a dotted horizontal line at the series last value. `histbase` sets the baseline for histogram/columns styles (0 when omitted). `axisLabel` toggles the price-axis badge (on by default).

Returns nothing; it draws the series onto the chart.

series
series
The series to draw on the chart. series must be numeric (passing text/string raises a clear error).
title
string
Optional. Label for the line.
color
color
Optional. Hex color (e.g. "#26a69a").
pane
string
Optional. The target pane. If omitted, it is chosen automatically based on the value range (the price pane if close to price, otherwise the shared lower pane). Pass a fixed string (e.g. "rsi") to group all plot() calls that use the same string into the same sub-pane.
style
string
Optional. Draw style: line/stepline/histogram/columns/area/circles/cross (default line). The dotted form `plot.style_line` may also be used (identical result). All 7 styles fully render in both the price pane (pane="price") and sub-panes. ⚠ ONE LIMIT: combined with a non-zero offset on the price pane (see below) the plot still draws as a line — a warning is shown in that case.
linewidth
number
Optional. Line thickness (1-4).
linestyle
string
Optional. Line dash pattern: solid/dashed/dotted.
offset
number
Optional. Shifts the line N bars to the right (positive) / left (negative) — visual only; the calculation series is unchanged (default 0). ⚠ On the price pane (pane="price"), a non-zero offset combined with style≠line still draws as a line (no such limit on sub-panes — offset+style work together there).
display
string
Optional. If display.none is passed this plot is hidden (not drawn on the chart); display.all or omitting it keeps it visible (default).
trackprice
bool
Optional. When true, draws a dotted line across the chart at the series' LAST value. Useful for seeing how close price is to that level. No line when omitted.
histbase
number
Optional. Baseline the bars grow from in histogram and columns styles. Defaults to 0; e.g. passing 50 for a 0-100 oscillator makes bars grow from the midline.
axisLabel
bool
Optional. Shows or hides the badge on the price axis carrying the series' last value. On by default; pass false to hide it.

Note

Colors are hex codes; see the Colors section for ready-made options.

When to use

Use plot for a continuous line. To mark only the signal bars, write plot(iff(signal, price, na),...) — na bars are skipped, leaving gaps between the drawn points. When you need a discrete shape or arrow, prefer plotshape/plotchar/plotarrow.

Limits

Drawing many separate lines clutters the chart and makes it harder to read. Plotting a series on a very different scale from price (say RSI) on the price panel can flatten the candles; such series read better in a separate lower panel.

Not for

If you only want a discrete mark on certain bars, plot is the wrong tool — reach for plotshape, plotchar or plotarrow instead. For a fixed summary in the corner use tableNew, and for free text tied to a bar use label. If you are computing a value you never intend to draw, do not call plot at all; keep the value in a variable.

BTCUSDT5m62,522-0.28%plot + crossover markSMA2062,29862,40862,51862,62862,737VOLUME62,522
CODESCRIPT
plot(sma(close,20), "SMA20", "#2962ff")

Blue SMA20 line on the price pane.

CODESCRIPT
plot(iff(crossover(close,sma(close,10)), low, na), "AL", "#26a69a")

A green dot at the low level only on cross-above bars; other bars empty (na).

CODESCRIPT
plot(volume, "Volume", style="histogram", histbase=0)
// a horizontal line at the last value, with the axis badge off:
plot(sma(close, 20), "SMA20", trackprice=true, axisLabel=false)

Draws volume as zero-based columns and the average with a horizontal line at its last value; the axis badge is off.

plotarrow(series, title?, colorup?, colordown?, offset?, minheight?, maxheight?, display?)

Draws arrows by series value: >0 up, <0 down, 0/na none. Height scales with |value| (minheight..maxheight px). colorup/colordown set arrow colors.

Returns nothing; it draws arrows according to the signed series.

series
series
Value: >0 draws an up arrow, <0 draws a down arrow, 0/na draws nothing.
title
string
Optional. Label.
colorup
color
Optional. Up arrow color (default green).
colordown
color
Optional. Down arrow color (default red).
offset
number
Optional. Bar shift.
minheight
number
Optional. Shortest arrow in pixels (default 5).
maxheight
number
Optional. Longest arrow in pixels (default 100).
display
string
Optional. If display.none is passed this plot is hidden (not drawn on the chart); display.all or omitting it keeps it visible (default).

Note

The arrow height is proportional to |value| (clipped to minheight..maxheight); it visualizes the magnitude.

When to use

To show not just direction but the strength or magnitude of a signal (momentum, a histogram). Use plotshape for a fixed-size mark.

Limits

Only the sign sets the direction (up/down); the absolute size of the value is reflected in the arrow's height. Bars with 0 or na are left empty.

Not for

Not for a fixed-size mark — use plotshape. For a plain on/off state the varying height of plotarrow adds nothing; plotshape or plotchar is clearer. Use label for free text and tableNew for a fixed summary.

ETHUSDT15m1,575-3.78%plotarrow — direction + magnitude1,5241,5581,5931,6271,662VOLUME1,575
CODESCRIPT
plotarrow(close - open)

Up arrow on bullish bars, down arrow on bearish bars; length proportional to body size.

CODESCRIPT
plotarrow(macd(close).hist)

Up/down arrows based on the MACD histogram sign.

plotbar(open, high, low, close, title?, color?, editable?, show_last?, display?, format?, precision?, force_overlay?)

Plots a custom OHLC bar series (no body — vertical high-low line plus left open/right close ticks, single color).

Returns nothing; draws one OHLC bar per bar on the price chart.

open
series
Open price.
high
series
High price.
low
series
Low price.
close
series
Close price.
title
string
Optional. Label for the series.
color
color
Optional. Hex color (e.g. "#26a69a"). Defaults to a single blue if omitted.
editable
bool
Optional, not yet implemented.
show_last
number
Optional. Draws only the last N bars.
display
string
Optional. Pass "none" to hide.
format
string
Optional, not yet implemented.
precision
number
Optional, not yet implemented.
force_overlay
bool
Optional, not yet implemented.

Note

Unlike plotcandle: there is NO body (filled rectangle) — just a vertical high-low line with a short tick on the left for open and on the right for close. The whole bar is a SINGLE color (no separate body/wick/border colors like plotcandle).

Not for

If you want a filled candle body, use plotcandle instead. For a single continuous line series, plot is enough.

CODESCRIPT
plotbar(open, high, low, close, color=close>=open?"#26a69a":"#ef5350")

Green OHLC bar when close is above open, red when below.

plotcandle(open, high, low, close, title?, color?, wickcolor?, editable?, show_last?, bordercolor?, display?, format?, precision?, force_overlay?)

Plots a custom candle series.

Returns nothing; it draws a custom candle series from the given OHLC.

open
series
Candle open series.
high
series
Candle high series.
low
series
Candle low series.
close
series
Candle close series.
title
string
Optional. Label.
color
color
Optional. Body color (can be conditional).
wickcolor
color
Optional. Wick color.
editable
bool
Optional. Currently has no effect — accepted but not applied (passing a non-default value prints a one-time warning).
show_last
number
Optional. Draws only the last N candles; earlier ones are hidden.
bordercolor
color
Optional. Border color.
display
string
Optional. "none" draws no candles at all; "all" (default) draws them. Any other value still draws but prints a warning.
format
string
Optional. Currently has no effect — accepted but not applied (passing a non-default value prints a one-time warning).
precision
number
Optional. Currently has no effect — accepted but not applied (passing a value prints a one-time warning).
force_overlay
bool
Optional. Currently has no effect — accepted but not applied (passing true prints a one-time warning).

Note

For drawing your own OHLC (e.g. Heikin-Ashi, rescaled) or conditionally colored candles. The color can be conditioned on a series.

When to use

For a derived or conditionally colored candle view (barcolor only tints one color, whereas plotcandle draws the whole OHLC body).

Limits

All four OHLC series are required; no candle is drawn on bars with na. It overlays the main price candles.

Not for

If coloring the candles a single color is enough, plotcandle is overkill — use barcolor. For one line use plot, and for a discrete mark plotshape fits better. You cannot draw a candle without all four OHLC series; do not call it when data is missing.

SOLUSDT1h73.73+2.65%plotcandle — custom candle series69.3670.7772.1973.6175.03VOLUME73.73
CODESCRIPT
plotcandle(open, high, low, close)

OHLC candles in the default single-blue color.

CODESCRIPT
plotcandle(open, high, low, close, color=close>=open?"#26a69a":"#ef5350", wickcolor="#787b86")

Green body on rise / red body on fall, gray wick.

plotchar(series, title?, char?, location?, color?, offset?, text?, textcolor?, size?, display?)

Draws a single CHARACTER (glyph) on bars where series is true. char: the mark (default ★). location: abovebar/belowbar/top/bottom/absolute.

Returns nothing; it stamps a character onto the bars where the condition holds.

series
bool
A character is drawn on bars where this is true.
title
string
Optional. Label.
char
string
Single character/glyph to display (default ★).
location
string
abovebar/belowbar/top/bottom/absolute. The dotted form `location.abovebar` may also be used (identical result).
color
color
Optional. Color.
offset
number
Optional. Bar shift.
text
string
Optional. Additional text.
textcolor
color
Optional. Text color.
size
string
Optional. Character (glyph) size: tiny/small/normal/large/huge or a number (pixels, 7-40). Default normal.
display
string
Optional. If display.none is passed this plot is hidden (not drawn on the chart); display.all or omitting it keeps it visible (default).

Note

Like plotshape, but instead of a fixed shape it draws the character/glyph you choose. The collision-avoidance rule in text works the same as plotshape.

When to use

When you need a symbol plotshape does not include (such as ▲ ✓ ✗ $). Use label for free multi-character text.

Limits

A single character or glyph; not suited to long text (use label). It gets just as crowded as plotshape when overused.

Not for

Not for long or multi-word text; it draws a single character or glyph, so use label for anything more than one letter. For a fixed summary panel prefer tableNew. If you need to show a value's magnitude, plotchar does not vary in size — switch to plotarrow.

BTCUSDT5m62,522-0.28%plotchar — RSI extremes62,29862,40862,51862,62862,737VOLUME62,522●●●●●
CODESCRIPT
plotchar(close > open, char="B", location="belowbar", color="#26a69a")

Green 'B' below green (bullish) bars.

CODESCRIPT
plotchar(crossunder(close, ema(close,20)), char="x", location="abovebar")

'x' above the bar on EMA20 cross-below bars.

plotshape(series, title?, style?, location?, color?, offset?, text?, textcolor?, size?, display?)

Draws a SHAPE on bars where series is true (≠0/na). style: arrowup/arrowdown/triangleup/triangledown/circle/square/diamond/cross/xcross/flag/labelup/labeldown. location: abovebar/belowbar/top/bottom/absolute. size: tiny/small/normal/large/huge (shape icon size, default normal).

Returns nothing; it stamps a shape onto the chart on the bars where the condition holds.

series
bool
A shape is drawn on bars where this is true (≠0/na).
title
string
Optional. Label for the shape.
style
string
Shape: arrowup/arrowdown/triangleup/triangledown/circle/square/diamond/cross/xcross/flag/labelup/labeldown (default circle). The dotted form `shape.circle` may also be used (identical result).
location
string
Location: abovebar/belowbar/top/bottom/absolute (default abovebar). The dotted form `location.abovebar` may also be used (identical result).
color
color
Optional. Shape color (hex).
offset
number
Optional. Bar shift.
text
string
Optional. Text next to the shape.
textcolor
color
Optional. Text color.
size
string
Optional. Size of the shape icon (and its adjacent text): tiny/small/normal/large/huge or a number (pixels, 7-40). Default normal.
display
string
Optional. If display.none is passed this plot is hidden (not drawn on the chart); display.all or omitting it keeps it visible (default).

Note

series is a boolean/series; a shape is drawn on every true bar. location positions the shape relative to the bar. Adding in text (at the END of the text for abovebar, at the START for belowbar) pushes the label away from the bar — use this to avoid overlapping another label on the same bar (e.g. the automatic buy/sell marker). If you need several marks on the same bar, use different location values (abovebar/belowbar) to keep them from overlapping.

When to use

For discrete buy/sell or condition marks. Use label for free text, plotchar for a single symbol or glyph, and plotarrow to show magnitude.

Limits

Only the supported shape names work; you cannot load a custom icon. If the condition is true too often the chart gets crowded — reserve the mark for infrequent conditions.

Not for

Not for showing free-form or long text — use label for that. If you need a symbol plotshape does not offer (▲ ✓ ✗ $), reach for plotchar, and to convey a signal's magnitude as height use plotarrow. Do not tie it to a condition that is true on every bar; the shapes pile up and the chart becomes unreadable.

Tip

If you need several marks on the same bar, use different location values (abovebar/belowbar) to keep them from overlapping.

BTCUSDT5m62,522-0.28%plotshape — buy / sell marks62,29862,40862,51862,62862,737VOLUME62,522

series is a boolean/series; a shape is drawn on every true bar. location positions the shape relative to the bar. Adding in text (at the END of the text for abovebar, at the START for belowbar) pushes the label away from the bar — use this to avoid overlapping another label on the same bar (e.g. the automatic buy/sell marker).

If you need several marks on the same bar, use different location values (abovebar/belowbar) to keep them from overlapping.

CODESCRIPT
plotshape(crossover(close, sma(close,10)), style="triangleup", location="belowbar", color="#26a69a")

Green up-triangle below the bar on SMA10 cross-above bars.

CODESCRIPT
plotshape(rsi(close,14) > 70, style="arrowdown", location="abovebar", color="#ef5350", size="small")

Small red down-arrow above the bar on RSI>70 bars.

red(color)

Red channel of the hex color (0-255). Result: 38

Returns the color's red channel as a number 0-255 (invalid color → 0).

color
color
The hex color (#rgb / #rrggbb / #rrggbbaa) whose red channel is read.

Note

It is a color decomposer: it extracts the red component from a hex color. Together with green/blue/alpha it is used to take a color apart and rebuild it with rgb.

When to use

To process a color channel by channel: to change its opacity and reassemble, to compute a transition (gradient) between two colors, or to adjust a shade conditionally.

Not for

Not for producing a color (that is rgb's job). To read a color's opacity use alpha.

CODESCRIPT
base = "#2962ff"
fade = rgb(red(base), green(base), blue(base), 0.2)
bgcolor(fade)

The channels of #2962ff are read and reassembled at 20% opacity; the background becomes faint blue (#2962ff33).

rgb(r, g, b, transparency?)

RGB (0-255) → '#rrggbbaa' (opacity 0-1). Result: #26a69a80

Returns a hex color string in #rrggbbaa form (opacity is mapped to a 0-255 alpha byte).

r
number
Red channel 0-255 (out-of-range values are clamped and rounded to integer).
g
number
Green channel 0-255.
b
number
Blue channel 0-255.
transparency
number
Optional. Opacity 0-1 (0=fully transparent, 1=fully opaque; default 1).

Note

It is a color builder: it assembles one hex color from three channels + opacity. opaklik is on a 0-1 scale and is rounded to a 0-255 alpha byte (e.g. 0.15 → 0x26). You can feed the result anywhere a color is expected — plot/barcolor/bgcolor/fill.

When to use

To build a color numerically instead of writing a fixed hex: to set opacity programmatically, to decompose with red/green/blue and reassemble, or to compute a color from a value.

Not for

Not needed for a fixed known color — just write the hex ("#26a69a"). If you only want to add opacity, color(hex, alpha) is shorter.

CODESCRIPT
bgcolor(rgb(38, 166, 154, 0.15))

A 15%-opacity green (#26a69a26) background applied to all bars.

CODESCRIPT
barcolor(rgb(239, 83, 80))

All candles colored with fully opaque red (#ef5350ff).

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

Shape names for plotshape (dot access). shape.circle is identical to "circle"; the dotted form is preferred for readability. (plotchar takes a character, not a shape, so it does not apply there.)

CODESCRIPT
plotshape(close > open, style=shape.triangleup)

Puts an up-pointing triangle on every bar that closes above its open; the shape type is picked from this list.

colorB(color)

Gives the blue channel of a colour as a number between 0 and 255. Used with `colorR` and `colorG` to rebuild a colour.

The blue channel of the color (0-255). Empty if the color cannot be parsed.

color
color
The color whose channel is read (#rgb, #rrggbb or #rrggbbaa).

Note

colorR/colorG/colorB split a color into its channels; rgb(r,g,b,opacity) rebuilds it. Typical use: reproduce the same hue at a different opacity.

When to use

When you want to keep the user-picked color but change only its transparency.

CODESCRIPT
k = colorB("#089981")

Takes the blue component of the given colour as a number between 0 and 255; it draws nothing and keeps the value in a variable.

colorFromHsb(hue, saturation, brightness, transparency?)

Builds a color from hue/saturation/brightness. hue 0-360 (wraps), saturation and brightness 0-1, opacity 0-1 (default 1) - same scale as rgb()/color().

hue
number
Hue 0-360 (wraps; 370 = 10). The named argument can also be given as `hue` (equivalent).
saturation
number
0-1 (0 = gray, 1 = fully saturated). The named argument can also be given as `saturation` (equivalent).
brightness
number
0-1 (0 = black, 1 = brightest). The named argument can also be given as `brightness` (equivalent).
transparency
number
Optional, 0-1 (default 1 = fully opaque). Not a 0-100 transparency scale. The named argument can also be given as `opacity` (equivalent).

Note

Our opacity scale is 0-1 (consistent with rgb()/color()). colorToInt/colorFromInt round-trip exactly; use them to store or compare colors numerically.

When to use

When generating colors programmatically (hue shifting) or storing them numerically.

CODESCRIPT
c = colorFromHsb(200, 0.8, 1)

Builds a colour from hue, saturation and brightness; these values produce a light blue.

colorFromInt(count)

Converts a 0xAARRGGBB integer back to a color - the inverse of colorToInt (the round trip is exact).

count
number
An integer in 0xAARRGGBB form.

Note

Our opacity scale is 0-1 (consistent with rgb()/color()). colorToInt/colorFromInt round-trip exactly; use them to store or compare colors numerically.

When to use

When generating colors programmatically (hue shifting) or storing them numerically.

CODESCRIPT
c = colorFromInt(4294901760)

Converts a colour stored as a number back into a colour; useful when colours arrive as numbers from elsewhere.

colorG(color)

Gives the green channel of a colour as a number between 0 and 255. Used with `colorR` and `colorB` to rebuild a colour.

The green channel of the color (0-255). Empty if the color cannot be parsed.

color
color
The color whose channel is read (#rgb, #rrggbb or #rrggbbaa).

Note

colorR/colorG/colorB split a color into its channels; rgb(r,g,b,opacity) rebuilds it. Typical use: reproduce the same hue at a different opacity.

When to use

When you want to keep the user-picked color but change only its transparency.

CODESCRIPT
k = colorG("#089981")

Takes the green component of the given colour as a number between 0 and 255.

colorNew(color, transparency)

Makes a color TRANSPARENT. `transparency` 0 = fully opaque, 100 = fully invisible. The most used helper for fills and zones: `box.new(..., bgcolor = colorNew("#2962ff", 85))` gives a blue box that does not hide the candles behind it.

A color with alpha baked in (`#rrggbbaa`).

color
string
The color to make transparent (e.g. `"#2962ff"`).
transparency
number
Transparency percent: 0 = fully opaque, 100 = fully invisible. Zone fills typically use 80-90.

Note

The most used helper for fills and zones. Without transparency the color stays opaque and hides the candles behind the box — the usual cause of 'I drew a zone but the candles vanished'.

CODESCRIPT
b = boxNew(bar_index-5, high, bar_index, low, bgcolor = colorNew("#2962ff", 85))

Draws a box over the last five bars in the chosen colour; the colour is given together with its transparency.

colorR(color)

Gives the red channel of a colour as a number between 0 and 255. Used together with `colorG` and `colorB` to take a colour apart and rebuild it with a different transparency. Returns empty when the colour cannot be read.

The red channel of the color (0-255). Empty if the color cannot be parsed.

color
color
The color whose channel is read (#rgb, #rrggbb or #rrggbbaa).

Note

colorR/colorG/colorB split a color into its channels; rgb(r,g,b,opacity) rebuilds it. Typical use: reproduce the same hue at a different opacity.

When to use

When you want to keep the user-picked color but change only its transparency.

CODESCRIPT
k = colorR("#089981")

Takes the red component of the given colour as a number between 0 and 255.

colorRgb(r, g, b, transparency?)

Builds a color from red/green/blue channels (0-255). Transparency is 0-100 (0 fully opaque, 100 invisible); defaults to 0. Note: rgb() uses a 0-1 opacity scale instead.

The color built from the channels.

r
number
Red channel 0-255.
g
number
Green channel 0-255.
b
number
Blue channel 0-255.
transparency
number
Optional. Transparency 0-100 (0 fully opaque, 100 invisible). Defaults to 0.

Note

The transparency scale is 0-100, whereas rgb() uses a 0-1 opacity scale - do not mix them. Use it with colorR/colorG/colorB to split a color and rebuild it at a different transparency.

When to use

When computing box/label fill transparency programmatically.

CODESCRIPT
c = colorRgb(8, 153, 129, 60)

Builds a colour from red, green, blue and transparency values; the larger the last number, the more transparent the colour.

colorT(color)

Returns a color's transparency percentage (0-100). Colors without alpha return 0 (opaque). Use it to read back the transparency set with `color.new`.

Transparency percent 0-100; 0 when the color has no alpha.

color
string
The color whose transparency is read.

Note

Reads back the transparency set with `color.new`.

CODESCRIPT
t = colorT(colorNew("#2962ff", 85))

Takes a colour's transparency as a number between 0 and 100; 0 is fully opaque and 100 fully invisible.

colorToInt(color)

Packs a color into a single integer: 0xAARRGGBB (alpha in the highest byte). Unrecognized color -> empty.

color
color
The color to pack.

Note

Our opacity scale is 0-1 (consistent with rgb()/color()). colorToInt/colorFromInt round-trip exactly; use them to store or compare colors numerically.

When to use

When generating colors programmatically (hue shifting) or storing them numerically.

CODESCRIPT
n = colorToInt("#ff0000ff")

Converts a colour into a single number; used when colours need to be stored or compared as numbers.