Skip to main content

Drawing to the Chart

plot, fill, colors, bgcolor, barcolor, bars and candles, plotshape, plotchar, plotarrow, lines, labels, tables, and boxes.

The plot() Function: Deep Dive

plot() is the workhorse of PineScript visualization. It draws a continuous line (or other style) for any series value. Understanding its full parameter set gives you precise control over how your indicator looks on the chart.

pine-plot() with all parameters
1//@version=6
2indicator("Plot Deep Dive", overlay=true)
3
4ema9 = ta.ema(close, 9)
5sma50 = ta.sma(close, 50)
6
7// Minimal plot
8plot(ema9, "EMA 9")
9
10// Full parameter control
11plot(sma50, title="SMA 50",
12 color=color.new(#5ce1e6, 0),
13 linewidth=2,
14 style=plot.style_line,
15 display=display.all)
16
17// Conditional plot, only renders when condition is true (na = gap)
18plot(close > sma50 ? ema9 : na, "EMA Above SMA",
19 color.green, 3, plot.style_circles)
20
21// Histogram style for a separate pane indicator
22// plot(ta.rsi(close, 14) - 50, "RSI Centered", color.white, 1, plot.style_histogram)
seriesThe data to plot: any series float. This is the only required parameter.
titleDisplay name in the chart legend and style settings. Always use descriptive names.
colorCan be a constant color or a series color (changes dynamically per bar).
linewidth1 (thin) to 4 (thick). Default 1. Use 2 for primary plots, 1 for secondary.
styleplot.style_line, circles, cross, histogram, columns, area, stepline, linebr, stepline_diamond
displaydisplay.all (default), display.none (hidden but usable in fill()), display.pane, display.status_line, display.data_window
trackpricetrue shows a horizontal dotted line at the current value. Useful for real-time levels.
offsetShifts the plot left (negative) or right (positive) by N bars. Use for leading/lagging displays.

plotshape(): Signal Markers

plotshape() places shapes on the chart when a boolean condition is true. This is how you create buy/sell signals, divergence markers, pattern detections, and any point-in-time annotation. The first argument is the condition (true/false series), not a price value.

pine-plotshape() signal markers
1//@version=6
2indicator("Signal Markers", overlay=true)
3
4ema21 = ta.ema(close, 21)
5rsi = ta.rsi(close, 14)
6vol = ta.sma(volume, 20)
7
8// Confluence buy signal: price crosses above EMA + RSI oversold + above-avg volume
9buySignal = ta.crossover(close, ema21) and rsi < 40 and volume > vol
10sellSignal = ta.crossunder(close, ema21) and rsi > 60 and volume > vol
11
12// Triangle markers below/above bars
13plotshape(buySignal, "Buy", shape.triangleup, location.belowbar,
14 color.green, size=size.small)
15plotshape(sellSignal, "Sell", shape.triangledown, location.abovebar,
16 color.red, size=size.small)
17
18// Labels with text for high-conviction signals
19strongBuy = buySignal and rsi < 25
20plotshape(strongBuy, "Strong Buy", shape.labelup, location.belowbar,
21 color.new(color.green, 10), text="STRONG",
22 textcolor=color.white, size=size.normal)
shape.triangleup / triangledown

Classic directional signals: the most common markers for buy and sell.

shape.labelup / labeldown

Filled labels with optional text. Use for annotated signals.

shape.diamond

Neutral or informational markers: pivots, reversals, pattern detections.

shape.arrowup / arrowdown

Bold directional arrows. Use sparingly for high-conviction signals.

shape.circle / cross / xcross

Subtle point markers: good for data visualization without visual clutter.

shape.flag

Flag markers: useful for event annotations like earnings, halvings, or protocol upgrades.

plotchar() and plotarrow()

plotchar() renders a single Unicode character as a marker. plotarrow() draws arrows whose size is proportional to a series value: useful for showing momentum direction and magnitude.

pine-plotchar() and plotarrow()
1//@version=6
2indicator("Char and Arrow Markers", overlay=true)
3
4isHighVol = volume > ta.sma(volume, 20) * 2.5
5
6// Unicode character marker on high-volume bars
7plotchar(isHighVol, "Volume Spike", "★",
8 location.abovebar, color.yellow, size=size.tiny)
9
10// plotarrow: arrow size proportional to momentum
11momentum = ta.roc(close, 10)
12plotarrow(momentum, "Momentum",
13 colorup=color.new(color.green, 20),
14 colordown=color.new(color.red, 20),
15 maxheight=20, minheight=5)

hline() and fill(): Zones

hline() draws a horizontal line at a fixed price level. fill() fills the area between two plots or two hlines with a semi-transparent color. Together they create professional-looking zones on oscillators and overlay indicators.

pine-RSI with filled zones
1//@version=6
2indicator("Zones Demo")
3
4rsi = ta.rsi(close, 14)
5rsiPlot = plot(rsi, "RSI", color.white, 2)
6midPlot = plot(50, "Midline", color.new(color.gray, 80), 1)
7
8// Horizontal reference lines
9h70 = hline(70, "Overbought", color.new(color.red, 60), hline.style_dashed)
10h30 = hline(30, "Oversold", color.new(color.green, 60), hline.style_dashed)
11
12// Fill between hlines (the OB/OS zone)
13fill(h70, h30, color.new(color.gray, 93), title="RSI Range")
14
15// Fill between plots (RSI vs midline)
16fill(rsiPlot, midPlot,
17 color1=color.new(color.green, 80),
18 color2=color.new(color.red, 80),
19 title="RSI vs 50")

bgcolor() and barcolor()

bgcolor() colors the entire background of a bar's column. barcolor() changes the color of the candlestick body and wicks. Both accept a series color, meaning you can assign a different color on every bar based on any condition.

pine-Dynamic coloring
1//@version=6
2indicator("Coloring Masterclass", overlay=true)
3
4rsi = ta.rsi(close, 14)
5[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
6
7// Background: subtle RSI zone coloring
8bgcolor(rsi > 70 ? color.new(color.red, 88) :
9 rsi < 30 ? color.new(color.green, 88) : na)
10
11// Candle coloring: MACD histogram momentum
12barcolor(hist > 0 ? (hist > hist[1] ? color.green : color.lime) :
13 (hist < hist[1] ? color.red : color.orange))

Color Functions

PineScript provides three ways to create custom colors. Mastering these is the difference between amateur indicators with flat colors and professional tools with dynamic, informative coloring that communicates market state at a glance.

color.new(color, transp)Adjusts transparency of an existing color. transp ranges from 0 (opaque) to 100 (invisible). The most commonly used color function.
color.rgb(r, g, b, transp)Creates a color from red/green/blue components (0–255 each) plus optional transparency. Use for precise custom colors.
color.from_gradient(value, lo, hi, colorLo, colorHi)Maps a value within a range to a gradient between two colors. Extremely powerful for heatmap-style visualizations.
pine-Gradient coloring for heatmap-style RSI
1//@version=6
2indicator("Gradient RSI Heatmap")
3
4rsi = ta.rsi(close, 14)
5
6// Smooth gradient: green (oversold) → yellow (neutral) → red (overbought)
7rsiColor = color.from_gradient(rsi, 20, 80, color.green, color.red)
8
9plot(rsi, "RSI", rsiColor, 3)
10bgcolor(color.new(rsiColor, 88))
11
12hline(70, "OB", color.new(color.red, 70), hline.style_dashed)
13hline(30, "OS", color.new(color.green, 70), hline.style_dashed)

Lines and Labels: Dynamic Drawing

Beyond plots and shapes, PineScript provides drawing objects: line, label, and box: that you create, position, and optionally delete programmatically. These are objects that persist and can be modified after creation, making them ideal for dynamic support/resistance levels and trade zone annotations.

pine-Automatic support/resistance lines
1//@version=6
2indicator("Auto S/R Lines", overlay=true, max_lines_count=100, max_labels_count=100)
3
4pivLen = input.int(10, "Pivot Lookback")
5
6pivH = ta.pivothigh(high, pivLen, pivLen)
7pivL = ta.pivotlow(low, pivLen, pivLen)
8
9if not na(pivH)
10 line.new(bar_index - pivLen, pivH, bar_index, pivH,
11 color=color.new(color.red, 30), width=1,
12 style=line.style_dashed, extend=extend.right)
13 label.new(bar_index - pivLen, pivH,
14 "R " + str.tostring(pivH, "#.#"),
15 color=color.new(color.red, 80), textcolor=color.red,
16 style=label.style_label_down, size=size.tiny)
17
18if not na(pivL)
19 line.new(bar_index - pivLen, pivL, bar_index, pivL,
20 color=color.new(color.green, 30), width=1,
21 style=line.style_dashed, extend=extend.right)
22 label.new(bar_index - pivLen, pivL,
23 "S " + str.tostring(pivL, "#.#"),
24 color=color.new(color.green, 80), textcolor=color.green,
25 style=label.style_label_up, size=size.tiny)

Tables: Dashboard Panels

Tables create fixed-position information panels that stay anchored to a corner of the chart. They do not scroll with price. Tables are the foundation of dashboard-style indicators that display multiple metrics in an organized grid.

pine-Market stats dashboard table
1//@version=6
2indicator("Stats Dashboard", overlay=true)
3
4if barstate.islast
5 var t = table.new(position.top_right, 2, 6,
6 bgcolor=color.new(#1a1a2e, 10),
7 border_width=1,
8 border_color=color.new(color.gray, 70))
9
10 addRow(r, lbl, val, valCol) =>
11 table.cell(t, 0, r, lbl, text_color=color.gray, text_size=size.small)
12 table.cell(t, 1, r, val, text_color=valCol,
13 text_size=size.small, text_halign=text.align_right)
14
15 rsi = ta.rsi(close, 14)
16 atr = ta.atr(14)
17 chg = (close - close[1]) / close[1] * 100
18
19 table.cell(t, 0, 0, "Metric", text_color=color.gray, text_size=size.small)
20 table.cell(t, 1, 0, "Value", text_color=color.gray, text_size=size.small)
21 addRow(1, "Price", str.tostring(close, "#.##"), color.white)
22 addRow(2, "Change", str.tostring(chg, "#.##") + "%",
23 chg > 0 ? color.green : color.red)
24 addRow(3, "RSI", str.tostring(rsi, "#.#"),
25 rsi > 70 ? color.red : rsi < 30 ? color.green : color.white)
26 addRow(4, "ATR", str.tostring(atr, "#.##"), color.yellow)
27 addRow(5, "Volume", str.tostring(volume, "#,###"), color.white)

Boxes: Zone Highlighting

box.new() draws a rectangle between two price levels and two bar indices. Boxes are perfect for highlighting supply/demand zones, consolidation ranges, and session ranges.

pine-Session range boxes
1//@version=6
2indicator("Session Boxes", overlay=true, max_boxes_count=50)
3
4isNewSession = ta.change(time("D")) != 0
5var float sessionHigh = na
6var float sessionLow = na
7var int sessionStart = na
8
9if isNewSession
10 if not na(sessionStart)
11 box.new(sessionStart, sessionHigh, bar_index - 1, sessionLow,
12 bgcolor=color.new(color.blue, 92),
13 border_color=color.new(color.blue, 60),
14 border_width=1)
15 sessionHigh := high
16 sessionLow := low
17 sessionStart := bar_index
18else
19 sessionHigh := math.max(nz(sessionHigh), high)
20 sessionLow := math.min(nz(sessionLow, low), low)

Complete Build: Professional Crypto Momentum Indicator

Let's combine all the visualization techniques from this lesson into a single, production-grade indicator that uses plots, shapes, fills, gradient colors, labels, and a dashboard table.

pine-Professional Momentum Overlay (full script)
1//@version=6
2indicator("Crypto Momentum Pro", overlay=true)
3
4// Inputs
5emaLen = input.int(21, "EMA Length", group="Trend")
6rsiLen = input.int(14, "RSI Length", group="Momentum")
7atrLen = input.int(14, "ATR Length", group="Volatility")
8showTbl = input.bool(true, "Show Dashboard", group="Display")
9
10// Calculations
11ema = ta.ema(close, emaLen)
12rsi = ta.rsi(close, rsiLen)
13atr = ta.atr(atrLen)
14trend = close > ema
15
16// EMA line with gradient color based on RSI
17emaColor = color.from_gradient(rsi, 30, 70, color.red, color.green)
18plot(ema, "Trend EMA", emaColor, 2)
19
20// Subtle trend background
21bgcolor(trend ? color.new(color.green, 94) : color.new(color.red, 94))
22
23// Signal markers at confluence zones
24buySignal = ta.crossover(close, ema) and rsi < 45
25sellSignal = ta.crossunder(close, ema) and rsi > 55
26plotshape(buySignal, "Buy", shape.triangleup, location.belowbar,
27 color.green, size=size.small)
28plotshape(sellSignal, "Sell", shape.triangledown, location.abovebar,
29 color.red, size=size.small)
30
31// ATR-based volatility bands
32upper = ema + atr * 2
33lower = ema - atr * 2
34p1 = plot(upper, "Upper Band", color.new(color.gray, 70), 1)
35p2 = plot(lower, "Lower Band", color.new(color.gray, 70), 1)
36fill(p1, p2, color.new(color.gray, 95), title="ATR Channel")
37
38// Dashboard table
39if showTbl and barstate.islast
40 var t = table.new(position.top_right, 2, 4,
41 bgcolor=color.new(#0a0a0a, 10),
42 border_width=1, border_color=color.new(color.gray, 70))
43 table.cell(t, 0, 0, "Trend", text_color=color.gray, text_size=size.small)
44 table.cell(t, 1, 0, trend ? "▲ Bull" : "▼ Bear",
45 text_color=trend ? color.green : color.red, text_size=size.small)
46 table.cell(t, 0, 1, "RSI", text_color=color.gray, text_size=size.small)
47 table.cell(t, 1, 1, str.tostring(rsi, "#.#"),
48 text_color=rsi > 70 ? color.red : rsi < 30 ? color.green : color.white,
49 text_size=size.small)
50 table.cell(t, 0, 2, "ATR", text_color=color.gray, text_size=size.small)
51 table.cell(t, 1, 2, str.tostring(atr, "#.##"),
52 text_color=color.yellow, text_size=size.small)
53 table.cell(t, 0, 3, "Vol Ratio", text_color=color.gray, text_size=size.small)
54 volRatio = volume / ta.sma(volume, 20)
55 table.cell(t, 1, 3, str.tostring(volRatio, "#.#x"),
56 text_color=volRatio > 2 ? color.yellow : color.white,
57 text_size=size.small)

Visual design principle

Professional indicators follow “maximum information, minimum clutter.” Use 88–95% transparency for backgrounds. Reserve solid colors for primary plot lines. Only show signal markers when they are rare enough to be meaningful. If your chart is covered in markers, none of them are useful.

Put this lesson to work

Free on Thrive, no account needed.