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.
1//@version=62indicator("Plot Deep Dive", overlay=true)34ema9 = ta.ema(close, 9)5sma50 = ta.sma(close, 50)67// Minimal plot8plot(ema9, "EMA 9")910// Full parameter control11plot(sma50, title="SMA 50",12 color=color.new(#5ce1e6, 0),13 linewidth=2,14 style=plot.style_line,15 display=display.all)1617// 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)2021// Histogram style for a separate pane indicator22// plot(ta.rsi(close, 14) - 50, "RSI Centered", color.white, 1, plot.style_histogram)| series | The data to plot: any series float. This is the only required parameter. |
| title | Display name in the chart legend and style settings. Always use descriptive names. |
| color | Can be a constant color or a series color (changes dynamically per bar). |
| linewidth | 1 (thin) to 4 (thick). Default 1. Use 2 for primary plots, 1 for secondary. |
| style | plot.style_line, circles, cross, histogram, columns, area, stepline, linebr, stepline_diamond |
| display | display.all (default), display.none (hidden but usable in fill()), display.pane, display.status_line, display.data_window |
| trackprice | true shows a horizontal dotted line at the current value. Useful for real-time levels. |
| offset | Shifts 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.
1//@version=62indicator("Signal Markers", overlay=true)34ema21 = ta.ema(close, 21)5rsi = ta.rsi(close, 14)6vol = ta.sma(volume, 20)78// Confluence buy signal: price crosses above EMA + RSI oversold + above-avg volume9buySignal = ta.crossover(close, ema21) and rsi < 40 and volume > vol10sellSignal = ta.crossunder(close, ema21) and rsi > 60 and volume > vol1112// Triangle markers below/above bars13plotshape(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)1718// Labels with text for high-conviction signals19strongBuy = buySignal and rsi < 2520plotshape(strongBuy, "Strong Buy", shape.labelup, location.belowbar,21 color.new(color.green, 10), text="STRONG",22 textcolor=color.white, size=size.normal)Classic directional signals: the most common markers for buy and sell.
Filled labels with optional text. Use for annotated signals.
Neutral or informational markers: pivots, reversals, pattern detections.
Bold directional arrows. Use sparingly for high-conviction signals.
Subtle point markers: good for data visualization without visual clutter.
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.
1//@version=62indicator("Char and Arrow Markers", overlay=true)34isHighVol = volume > ta.sma(volume, 20) * 2.556// Unicode character marker on high-volume bars7plotchar(isHighVol, "Volume Spike", "★",8 location.abovebar, color.yellow, size=size.tiny)910// plotarrow: arrow size proportional to momentum11momentum = 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.
1//@version=62indicator("Zones Demo")34rsi = ta.rsi(close, 14)5rsiPlot = plot(rsi, "RSI", color.white, 2)6midPlot = plot(50, "Midline", color.new(color.gray, 80), 1)78// Horizontal reference lines9h70 = hline(70, "Overbought", color.new(color.red, 60), hline.style_dashed)10h30 = hline(30, "Oversold", color.new(color.green, 60), hline.style_dashed)1112// Fill between hlines (the OB/OS zone)13fill(h70, h30, color.new(color.gray, 93), title="RSI Range")1415// 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.
1//@version=62indicator("Coloring Masterclass", overlay=true)34rsi = ta.rsi(close, 14)5[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)67// Background: subtle RSI zone coloring8bgcolor(rsi > 70 ? color.new(color.red, 88) :9 rsi < 30 ? color.new(color.green, 88) : na)1011// Candle coloring: MACD histogram momentum12barcolor(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. |
1//@version=62indicator("Gradient RSI Heatmap")34rsi = ta.rsi(close, 14)56// Smooth gradient: green (oversold) → yellow (neutral) → red (overbought)7rsiColor = color.from_gradient(rsi, 20, 80, color.green, color.red)89plot(rsi, "RSI", rsiColor, 3)10bgcolor(color.new(rsiColor, 88))1112hline(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.
1//@version=62indicator("Auto S/R Lines", overlay=true, max_lines_count=100, max_labels_count=100)34pivLen = input.int(10, "Pivot Lookback")56pivH = ta.pivothigh(high, pivLen, pivLen)7pivL = ta.pivotlow(low, pivLen, pivLen)89if 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)1718if 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.
1//@version=62indicator("Stats Dashboard", overlay=true)34if barstate.islast5 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))910 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)1415 rsi = ta.rsi(close, 14)16 atr = ta.atr(14)17 chg = (close - close[1]) / close[1] * 1001819 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.
1//@version=62indicator("Session Boxes", overlay=true, max_boxes_count=50)34isNewSession = ta.change(time("D")) != 05var float sessionHigh = na6var float sessionLow = na7var int sessionStart = na89if isNewSession10 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 := high16 sessionLow := low17 sessionStart := bar_index18else19 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.
1//@version=62indicator("Crypto Momentum Pro", overlay=true)34// Inputs5emaLen = 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")910// Calculations11ema = ta.ema(close, emaLen)12rsi = ta.rsi(close, rsiLen)13atr = ta.atr(atrLen)14trend = close > ema1516// EMA line with gradient color based on RSI17emaColor = color.from_gradient(rsi, 30, 70, color.red, color.green)18plot(ema, "Trend EMA", emaColor, 2)1920// Subtle trend background21bgcolor(trend ? color.new(color.green, 94) : color.new(color.red, 94))2223// Signal markers at confluence zones24buySignal = ta.crossover(close, ema) and rsi < 4525sellSignal = ta.crossunder(close, ema) and rsi > 5526plotshape(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)3031// ATR-based volatility bands32upper = ema + atr * 233lower = ema - atr * 234p1 = 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")3738// Dashboard table39if showTbl and barstate.islast40 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
Put this lesson to work
Free on Thrive, no account needed.