Skip to main content
Reference10 min read
Functions for rendering data on charts with customizable styling, colors, and visual effects.

Overview

FunctionDescription
plotLine()Draw continuous lines
plotBar()Render vertical bars
plotCandle()Display OHLC candlesticks
plotShape()Add markers and shapes
hline()Draw horizontal reference lines
plotText()Add text labels
plotTable()Display data tables
plotRange()Draw range/band areas
plotBgColor()Color background areas

plotLine()

Render data as continuous lines with customizable styling.

Signature

plotLine(value: any, width?: number, colors?: string[], colorIndex?: number, fill?: boolean, smooth?: boolean, label?: string[], desc?: string[]): void

Parameters

ParameterTypeDescription
valueanyData to plot
widthnumberLine width (default: 1)
colorsstring[]Array of colors
colorIndexnumberIndex to select color
fillbooleanFill area below line
smoothbooleanApply smoothing
labelstring[]Labels for legend
descstring[]Descriptions

Example

//@version=2

define(title="Moving Averages", position="onchart", axis=false);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

var sma20 = sma(source=ohlcvData.close, period=20);
var sma50 = sma(source=ohlcvData.close, period=50);

plotLine(value=sma20, width=2, colors=["blue"], label=["SMA 20"], desc=["20-period SMA"]);
plotLine(value=sma50, width=2, colors=["orange"], label=["SMA 50"], desc=["50-period SMA"]);
plotLine example

plotLine example showing two moving averages

plotBar()

Render data as vertical bars (histograms).

Signature

plotBar(value: any, width?: number, colors?: string[], colorIndex?: number, label?: string[], desc?: string[]): void

Parameters

ParameterTypeDescription
valueanyData to plot
widthnumberBar width (default: 1)
colorsstring[]Array of colors
colorIndexnumberIndex to select color
labelstring[]Labels for legend
descstring[]Descriptions

Example

//@version=2

define(title="Volume Bars", position="offchart", axis=true);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

var isGreen = ohlcvData.close > ohlcvData.open;
var colorIndex = isGreen ? 0 : 1;

plotBar(value=ohlcvData.volume, width=1, colors=["green", "red"], colorIndex=colorIndex, label=["Volume"], desc=["Trading Volume"]);
plotBar example

plotBar example showing colored volume bars

plotCandle()

Render OHLC data as candlestick charts.

Signature

plotCandle(value: TimeSeries, width?: number, colors?: string[], label?: string[], desc?: string[]): void

Parameters

ParameterTypeDescription
valueTimeSeriesOHLC data (requires Open, High, Low, Close)
widthnumberCandle width (default: 1)
colorsstring[]Colors for bullish/bearish
labelstring[]Labels
descstring[]Descriptions

Example

//@version=2

define(title="Candlestick Chart", position="offchart", axis=true);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

plotCandle(value=ohlcvData, width=1, colors=["#4caf50", "#f44336"], label=["Price"], desc=["OHLC Candlesticks"]);
plotCandle example

plotCandle example showing OHLC candlesticks

plotShape()

Add shapes and markers at specific points.

Signature

plotShape(value: any, shape?: string, width?: number, colors?: string[], fill?: boolean, label?: string[], desc?: string[]): void

Parameters

ParameterTypeDescription
valueanyY-position for shapes
shapestringShape type: “circle”, “triangle”, “square”, “diamond”
widthnumberShape size
colorsstring[]Shape colors
fillbooleanFill shape
labelstring[]Labels
descstring[]Descriptions

Example

//@version=2

define(title="Signal Markers", position="onchart", axis=false);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

var rsiValue = rsi(source=ohlcvData.close, period=14);

// Plot buy signals when RSI crosses below 30
var buySignal = rsiValue < 30 ? ohlcvData.low : na;
plotShape(value=buySignal, shape="triangle", width=2, colors=["green"], fill=true, label=["Buy Signal"], desc=["RSI Oversold"]);
plotShape example

plotShape example showing buy signal markers

hline()

Draw horizontal reference lines at fixed values.

Signature

hline(value: number, color?: string, width?: number, style?: string, label?: string): void

Parameters

ParameterTypeDescription
valuenumberY-value for the line
colorstringLine color
widthnumberLine width
stylestring”solid”, “dashed”, “dotted”
labelstringLabel text

Example

//@version=2

define(title="RSI with Levels", position="offchart", axis=true);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);
var rsiValue = rsi(source=ohlcvData.close, period=14);

plotLine(value=rsiValue, width=2, colors=["purple"], label=["RSI"], desc=["RSI Indicator"]);

hline(value=70, color="red", width=1, style="dashed", label="Overbought");
hline(value=50, color="gray", width=1, style="dotted", label="Middle");
hline(value=30, color="green", width=1, style="dashed", label="Oversold");
hline example

hline example showing RSI with reference levels

plotTable()

Display data in a table format on the chart.

Signature

plotTable(data: any[][], position?: string, colors?: object): void

Parameters

ParameterTypeDescription
dataany[][]2D array of table data
positionstringTable position: “top_left”, “top_right”, “bottom_left”, “bottom_right”
colorsobjectColor configuration

Example

//@version=2

define(title="Stats Table", position="onchart", axis=false);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

var rsiValue = rsi(source=ohlcvData.close, period=14);
var smaValue = sma(source=ohlcvData.close, period=20);

plotTable(data=[["Indicator", "Value"], ["RSI", rsiValue], ["SMA 20", smaValue]], position="top_right");
plotTable example

plotTable example showing indicator values

plotBgColor()

Color the chart background based on conditions.

Signature

plotBgColor(color: string, condition?: boolean): void

Parameters

ParameterTypeDescription
colorstringBackground color (use alpha for transparency)
conditionbooleanWhen to apply the color

Example

//@version=2

define(title="Trend Background", position="onchart", axis=false);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

var ema20 = ema(source=ohlcvData.close, period=20);
var isUptrend = ohlcvData.close > ema20;

plotBgColor(color=isUptrend ? "rgba(0,255,0,0.1)" : "rgba(255,0,0,0.1)");
plotLine(value=ema20, width=2, colors=["blue"], label=["EMA 20"], desc=["Trend Line"]);
plotBgColor example

plotBgColor example showing trend-based background coloring

Tips

Every plot function requires a label parameter. Missing labels will cause warnings.
Use color arrays with colorIndex for conditional coloring:
var colorIndex = condition ? 0 : 1;
plotLine(value=data, colors=["green", "red"], colorIndex=colorIndex, ...);
You can use multiple plot functions in a single indicator to create complex visualizations.
Avoid creating too many plot calls in loops. Each plot adds rendering overhead.