plot() - Pine Script Function
plot()
Section titled “plot()”Overview
Section titled “Overview”plot() is Pine Script’s primary drawing primitive. It renders one series of values in the script’s pane using styles ranging from simple lines to histograms, columns, or areas. The function returns a plot handle you can reference later (e.g., when calling fill()).
Every script can draw a limited number of plots (default 64). Reuse existing handles or disable unnecessary plots (e.g., with the display argument) to stay under the limit.
Syntax
Section titled “Syntax”plot(series, title, color, linewidth, style, trackprice, histbase, offset, join, editable, show_last, display, format, precision, force_overlay, linestyle) → plotParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
series | series int/float | Values to draw. Must be a series expression. |
title | const string (optional) | Label shown in the legend and style dialogs. Defaults to "plot". |
color | series color (optional) | Line or column color. Accepts static or dynamic colors. |
linewidth | input int (optional) | Stroke width in pixels (1–5). |
style | input plot.style (optional) | Render mode (e.g., plot.style_line, plot.style_histogram, plot.style_area). Defaults to plot.style_line. |
trackprice | const bool (optional) | Draws a price marker at the latest value when true. |
histbase | series int/float (optional) | Baseline for histogram/area styles. Defaults to 0. |
offset | simple int (optional) | Shifts the plot left/right by bars (positive values look forward). |
display | input plot_display (optional) | Controls where the plot appears (pane, data window, price scale, etc.). |
format | input format (optional) | Overrides the script’s default number formatting. |
precision | input int (optional) | Digits after the decimal (0–16). Ignored for format.volume. |
Other parameters (join, editable, show_last, force_overlay, linestyle) are optional quality-of-life toggles. See the official reference for full details.
Returns
Section titled “Returns”plot — Handle representing the drawn series.
Remarks
Section titled “Remarks”- Passing
nahides the plot on that bar. Useplot(series, ..., display=display.none)to keep the handle without rendering. - Change colors dynamically by supplying ternary expressions or palette arrays to the
colorparameter. - When combining multiple plots, capture their handles (
var pFast = plot(...)) so you can reference them once per bar without redrawing.
Example
Section titled “Example”//@version=5indicator("plot() styles demo", overlay=false, max_lines_count=1)
fast = ta.ema(close, 21)slow = ta.ema(close, 55)
plot(close, "Close histogram", style=plot.style_histogram, color=color.new(color.gray, 70), linewidth=2)
fastPlot = plot(fast, "Fast EMA", color=color.teal, linewidth=2)slowPlot = plot(slow, "Slow EMA", color=color.orange, linewidth=2)
fill(fastPlot, slowPlot, title="EMA spread fill", color=fast > slow ? color.new(color.green, 85) : color.new(color.red, 85))