Plotting
Plot functions draw visual elements on the chart. They are used in indicators (and optionally in strategies with overlay: true).
plot(series, name, color?, opts?)
Draw a Series as a line on the chart.
- series
Series— data to plot - name
string— legend label (must be unique per script) - color
string— line color (default:'#2962ff') - opts
{ lineWidth?: number }— line width (default:1.5)
ts
plot(ta.sma(close, 20), 'SMA 20', '#2962ff')
plot(ta.ema(close, 50), 'EMA 50', '#ff6d00', { lineWidth: 2 })fill(series1, series2, color?)
Fill the area between two Series.
- series1
Series— upper boundary - series2
Series— lower boundary - color
string— fill color (default:'rgba(33,150,243,0.1)')
ts
const bb = ta.bollinger(close, 20, 2)
plot(bb.upper, 'Upper', '#f44336')
plot(bb.lower, 'Lower', '#4caf50')
fill(bb.upper, bb.lower, 'rgba(33,150,243,0.1)')hline(price, name?, color?)
Draw a horizontal line at a fixed price level.
- price
number— the price level - name
string— legend label (default:'') - color
string— line color (default:'#787b86')
ts
hline(70, 'Overbought', '#EF5350')
hline(30, 'Oversold', '#26A69A')bgcolor(color)
Set the background color for the current bar. Called inside the bar-by-bar loop, it highlights individual bars.
- color
string— CSS color (use alpha for transparency)
ts
const rsi = ta.rsi(close, 14)
if (rsi > 70) bgcolor('rgba(239,83,80,0.15)')
if (rsi < 30) bgcolor('rgba(38,166,154,0.15)')box(startTime, endTime, priceTop, priceBottom, colorOrOpts?)
Draw a rectangle between two time/price coordinates. Ideal for marking ranges, zones, and phases (supply/demand, session ranges, AMD accumulation, etc.).
- startTime / endTime
number— left/right edges as Unix-second timestamps. Use thetimeseries (e.g.time[20]for 20 bars ago,time[0]for the current bar). - priceTop / priceBottom
number— top and bottom price levels. - colorOrOpts
string | BoxOptions— either a fill-color string (shorthand) or an options object:
| Option | Type | Description |
|---|---|---|
color | string | Fill color (default: subtle translucent blue). Use 8-digit hex like '#2962FF22' for transparency. |
strokeColor | string | Border color. When set, the box is outlined. |
strokeWidth | number | Border width (default: 1). |
dash | number[] | Border dash pattern, e.g. [4, 3] (omit for solid). |
label | string | Text label drawn at the top of the box. |
labelColor | string | Label color (defaults to strokeColor, then color). |
ts
// Shorthand: a filled box across the last 20 bars
box(time[20], time[0], high[0], low[0], 'rgba(33,150,243,0.15)')
// Full: outlined, dashed, labeled zone
box(time[20], time[0], high[0], low[0], {
color: '#2962FF22',
strokeColor: '#2962FF',
dash: [4, 3],
label: 'Range',
labelColor: '#2962FF',
})Boxes draw on the price chart, so they appear only on overlay indicators (
overlay: true).