Skip to content

Chart Rendering

After executing a Pine Script, call instance.chart() to obtain a Chart — the complete set of visual outputs produced by the script. This document describes the chart data model so you can render it in any frontend (Canvas, SVG, WebGL, native UI, etc.).

See Reading Outputs for the basic Rust API patterns for accessing charts and script info.

Overview

The Chart contains two categories of visuals:

CategoryAccessed viaDescription
Series graphschart.series_graphs()Per-bar data: one value per bar. Includes plot(), plotshape(), plotchar(), plotarrow(), plotcandle(), plotbar(), bgcolor(), fill().
Non-series graphschart.graphs()Point-in-time drawing objects created with *.new(). Includes label, line, box, table, polyline, hline, linefill.

Series graphs are indexed by bar (index 0 = first bar). Non-series graphs are standalone objects with explicit coordinates.


Accessing the Chart

rust
use openpine_vm::*;

// 1. Build an instance with bar data
let mut instance = Instance::builder(candlesticks, source, TimeFrame::days(1), "NASDAQ:AAPL")
    .build().await?;

// 2. Run the script against all bars
instance.run_to_end("NASDAQ:AAPL", TimeFrame::days(1)).await?;

// 3. Access the chart (borrow)
let chart = instance.chart();

// Or take ownership (consumes the instance)
let chart = instance.into_chart();

// 4. Access script configuration
let info = instance.script_info();

Key Chart Methods

MethodReturn TypeDescription
background_color()Option<Color>Chart-level background color
series_graphs()Iterator<(SeriesGraphId, &SeriesGraph)>All per-bar visual series
series_graph(id)Option<&SeriesGraph>Lookup a specific series graph by ID
graphs()Iterator<(GraphId, &Graph)>All drawing objects
graph(id)Option<&Graph>Lookup a specific drawing object by ID
series_len()usizeTotal number of bars
bar_colors()&BarColorsPer-bar candlestick color overrides
filled_orders_on_bar(i)&[FilledOrder]Filled orders on bar i (signal name, price, qty)

Chart Structure

Chart
 |-- background_color: Option<Color>
 |-- bar_colors: BarColors
 |-- filled_orders: { bar_index -> [FilledOrder] }
 |
 |-- series_graphs: { SeriesGraphId -> SeriesGraph }
 |     |-- Plot
 |     |-- PlotShape
 |     |-- PlotChar
 |     |-- PlotArrow
 |     |-- PlotBar
 |     |-- PlotCandle
 |     |-- BackgroundColors
 |     |-- Fill
 |
 |-- graphs: { GraphId -> Graph }
 |     |-- Hline
 |     |-- Label
 |     |-- Line
 |     |-- LineFill
 |     |-- Box
 |     |-- Polyline
 |     |-- Table

Script Configuration (ScriptInfo)

Access via instance.script_info(). This tells you how the script declared itself — it controls pane layout, z-order, and value formatting. Both indicator() and strategy() share the same rendering-relevant fields.

rust
let info = instance.script_info();

// Access rendering fields via script_type
let is_overlay = match &info.script_type {
    ScriptType::Indicator(ind) => ind.overlay,
    ScriptType::Strategy(strat) => strat.overlay,
    ScriptType::Library(lib) => lib.overlay,
};
FieldTypeDefaultDescription
titleStringDisplay name shown in chart legend and data window
short_titleOption<String>NoneAbbreviated name for compact display (status line, price scale)
overlayboolfalsetrue = draw on the main price chart pane; false = draw in a separate sub-pane
formatFormatInheritNumber formatting for values displayed on the price scale, tooltips, data window
precisionOption<u8>NoneDecimal places for values. None = use the symbol's default
scaleScaleTypeNonePrice scale placement: None (auto), Left, Right
explicit_plot_zorderboolfalsetrue = plots render in declaration order (first = bottom). false = default z-order
behind_chartboolfalsetrue = draw behind candlesticks instead of on top

overlay is the most important rendering decision:

  • true -> Draw all visuals on the main price chart pane, sharing the price Y-axis.
  • false -> Create a separate sub-pane below the chart with its own Y-axis.

overlay also sets the default value of force_overlay for every visual the script creates. When overlay = true, all visuals default to force_overlay = true (main pane). When overlay = false, they default to force_overlay = false (sub-pane). Pine users can override this per-visual by passing force_overlay explicitly.

format controls how numeric values are formatted on the sub-pane Y-axis and in crosshair/tooltip displays. Apply it to all sub-pane value labels:

  • Inherit / Price — format as a price (e.g. 150.25, 0.0042)
  • Percent — append a percent sign (e.g. 3.14%)
  • Volume — abbreviate large numbers (e.g. 1.5M, 200K)
  • MinTick — format using the symbol's minimum tick size (treat as Price if tick size is unavailable)

explicit_plot_zorder controls layering:

  • false (default) — the renderer decides the draw order
  • true — plots are drawn in the order they appear in series_graphs() (first = bottom layer)

Common Types

Color

A packed 32-bit RGBA value stored as u32 in 0xRRGGBBAA format.

MethodDescription
red() -> u8Red channel (0-255)
green() -> u8Green channel (0-255)
blue() -> u8Blue channel (0-255)
alpha() -> u8Alpha channel (0 = transparent, 255 = opaque)
transparency() -> u8Inverse of alpha (0 = opaque, 100 = transparent)
as_u32() -> u32Raw packed value

To convert to CSS: rgba(color.red(), color.green(), color.blue(), color.alpha() as f64 / 255.0).

When serialized to JSON, Color appears as a plain integer (e.g., 4294901760 for red 0xFF0000FF).

Option<Color> with value None means "use the default color" or "invisible" depending on context.

Series<T>

A Series<T> is a sequential array of per-bar values, backed by a VecDeque<T>. Index 0 is the first bar, index len() - 1 is the last bar.

MethodDescription
get(index) -> Option<&T>Get value at bar index
len() -> usizeNumber of bars
is_empty() -> boolWhether the series is empty
last() -> Option<&T>Value at the last bar

Most series are typed as Series<Option<f64>> or Series<Option<Color>>. A None entry means na (not available / no value on that bar). When rendering, skip None entries — do not draw anything for that bar.

When serialized to JSON, a Series appears as a plain array: [null, 150.0, 153.2, null, ...].

PlotDisplay (Bitflags)

Controls where a visual element is shown. This is a bitmask — multiple flags can be combined.

FlagValueDescription
ALL0xFFFFShow everywhere (default)
NONE0x0Hidden — do not render anywhere
PANE0x2Show in the chart pane (the visual plot itself)
DATA_WINDOW0x1Show in the data window panel
PRICE_SCALE0x8Show value on the price scale axis
STATUS_LINE0x10Show value on the status/legend line

Rendering rule: Only render the visual on the chart pane if display contains the PANE flag (display & 0x2 != 0). If display is NONE (0x0), skip rendering entirely.


Series Graphs (Per-Bar Data)

Iterate with chart.series_graphs(). Each entry is a (SeriesGraphId, &SeriesGraph) pair. Use pattern matching to identify the type:

rust
for (id, sg) in chart.series_graphs() {
    match sg {
        SeriesGraph::Plot(plot) => { /* render plot */ }
        SeriesGraph::PlotShape(shape) => { /* render shapes */ }
        SeriesGraph::PlotChar(pchar) => { /* render characters */ }
        SeriesGraph::PlotArrow(arrow) => { /* render arrows */ }
        SeriesGraph::PlotCandle(candle) => { /* render candles */ }
        SeriesGraph::PlotBar(bar) => { /* render OHLC bars */ }
        SeriesGraph::BackgroundColors(bg) => { /* render bg colors */ }
        SeriesGraph::Fill(fill) => { /* render fill area */ }
    }
}

Or use accessor methods: sg.as_plot(), sg.as_plot_shape(), etc.


Plot

The most common series graph. Produced by the Pine plot() function.

Pine example:

pinescript
plot(close, "Close", color.blue, linewidth=2, style=plot.style_line)

Fields:

FieldTypeDescription
titleOption<String>Title of the plot. Displayed in the chart legend, data window, and used as the default tooltip label. None = no title.
seriesSeries<Option<f64>>Per-bar numeric values to plot. Each entry corresponds to one bar. None = na (no point on that bar — the plot gaps or breaks depending on style and join).
colorsSeries<Option<Color>>Per-bar color of the plot. Can change dynamically per bar (e.g., green when rising, red when falling). None = use the default color.
line_widthi32Width of the line or outline in pixels. Default: 1. Applies to all styles.
stylePlotStyleDetermines how the series data is visually rendered: as a continuous line, step line, area fill, histogram bars, columns, or point markers (circles, crosses, diamonds). See the PlotStyle enum for all options.
line_stylePlotLineStyleStroke pattern for line-based styles: Solid, Dashed, or Dotted. Only applies to Line, LineBr, StepLine, StepLineBr styles.
track_priceboolIf true, a horizontal dashed line extends from the last plotted value to the right edge of the chart, and the value is shown on the price scale. Useful for highlighting the current indicator value.
histbasef64The reference/baseline value for Histogram, Area, AreaBr, and Columns styles. These styles fill the area between the series value and histbase. Default: 0.0. For example, with histbase = 50.0, a histogram bar at value 80 draws upward from 50 to 80, and a bar at value 30 draws downward from 50 to 30.
offseti32Shifts the entire plot left or right by the given number of bars. Positive values shift right (into the future), negative values shift left (into the past). Default: 0. The renderer should draw the value at bar_index + offset instead of bar_index.
joinboolControls gap handling for Line, StepLine, and Area styles. If true, consecutive non-na points are connected even if there are na values between them (the gap is bridged). If false, the line breaks at na values. The *Br styles (LineBr, StepLineBr, AreaBr) always break at na regardless of this setting.
show_lastOption<usize>If set, only the last N bars of the plot are rendered. All earlier bars are hidden. Useful for limiting visual clutter. None = show all bars.
displayPlotDisplayBitflag controlling where the plot is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting (see ScriptInfo). Can be overridden per plot() call via the force_overlay parameter.

Rendering logic:

for bar_index in 0..chart.series_len():
    value = plot.series[bar_index]   // Option<f64>
    color = plot.colors[bar_index]   // Option<Color>

    if value is None:
        if style is Line/StepLine/Area and join is true:
            // skip but connect to next valid point
        else:
            // break the line / skip the bar
        continue

    actual_bar = bar_index + plot.offset
    y = value_to_pixel(value)
    x = bar_to_pixel(actual_bar)

    match plot.style:
        Line/LineBr     -> draw line segment to (x, y)
        StepLine/...    -> draw horizontal then vertical to (x, y)
        Area/AreaBr     -> fill between y and histbase
        Histogram       -> draw thin vertical bar from histbase to y
        Columns         -> draw wide vertical bar from histbase to y
        Circles         -> draw circle at (x, y)
        Cross           -> draw + at (x, y)
        Diamond         -> draw diamond at (x, y)

PlotShape

Renders shape glyphs on the chart. Produced by the Pine plotshape() function.

Pine example:

pinescript
plotshape(close > open, style=shape.triangleup, location=location.belowbar, color=color.green)

Fields:

FieldTypeDescription
titleStringTitle of the plot, displayed in the chart legend and data window.
series(private)Per-bar values determining whether a shape is drawn. Access via bool_value(i) (returns Some(true) if the shape should appear on bar i) or float_value(i) (the raw numeric value). When location is Absolute, the float value is used as the Y coordinate.
styleShapeThe type of shape glyph to draw (e.g., triangle, arrow, circle, cross, diamond, flag, label, square, x-cross).
locationLocationControls the vertical placement of the shape. AboveBar / BelowBar place the shape at a fixed offset above/below the bar's high/low. Top / Bottom anchor the shape to the top/bottom of the pane. Absolute uses the series float value as the exact Y price coordinate.
colorsSeries<Option<Color>>Per-bar color of the shape. Can be a constant or change dynamically per bar (e.g., green for bullish signals, red for bearish).
offseti32Shifts shapes left (negative) or right (positive) by the given number of bars. Default: 0.
textOption<String>Optional text displayed alongside the shape. Supports multiline text via \n. Rendered near the shape position.
text_colorsSeries<Option<Color>>Per-bar color of the text. Independent of the shape color.
sizeSizeControls the visual size of the shape on the chart: Auto, Tiny, Small, Normal, Large, Huge.
show_lastOption<usize>If set, only draw shapes on the last N bars (counting backwards from the most recent bar).
displayPlotDisplayBitflag controlling visibility. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Access methods:

  • bool_value(bar_index) -> Option<bool> — returns true if the value is non-zero (shape should be drawn), false if zero, None if na.
  • float_value(bar_index) -> Option<f64> — returns the raw float value.

Rendering logic:

for bar_index in 0..chart.series_len():
    show = plotshape.bool_value(bar_index)    // Option<bool>
    if show is None or show == false:
        continue

    x = bar_to_pixel(bar_index + offset)
    y = match location:
        AboveBar  -> bar_high_pixel - margin
        BelowBar  -> bar_low_pixel + margin
        Absolute  -> value_to_pixel(plotshape.float_value(bar_index))
        Top       -> pane_top
        Bottom    -> pane_bottom

    draw_shape(style, x, y, size, colors[bar_index])
    if text is not None:
        draw_text(text, x, y, text_colors[bar_index])

PlotChar

Similar to PlotShape but renders a single character. Produced by the Pine plotchar() function.

Pine example:

pinescript
plotchar(crossover, char='*', location=location.abovebar, color=color.yellow)

Fields:

FieldTypeDescription
titleStringTitle of the plot, displayed in the chart legend and data window.
series(private)Per-bar values. Access via bool_value(i) / float_value(i). Same behavior as PlotShape: when location is Absolute, the float value determines Y position; otherwise, boolean determines whether the character appears.
charcharAny single Unicode character to use as the visual marker (e.g., '*', '✓', '❄').
locationLocationVertical positioning. Same as PlotShape: AboveBar, BelowBar, Top, Bottom, or Absolute.
colorsSeries<Option<Color>>Per-bar color of the character.
offseti32Shifts characters left or right by the given number of bars. Default: 0.
textOption<String>Optional additional text displayed near the character. Supports \n for multiline.
text_colorsSeries<Option<Color>>Per-bar color of the additional text.
sizeSizeSize of the character on the chart: Auto, Tiny, Small, Normal, Large, Huge.
show_lastOption<usize>If set, only draw on the last N bars.
displayPlotDisplayBitflag controlling visibility. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Rendering is identical to PlotShape, except you draw the char character instead of a shape glyph.


PlotArrow

Renders directional arrows. Produced by the Pine plotarrow() function. The arrow direction is determined by the sign of the value.

Pine example:

pinescript
plotarrow(close - open, colorup=color.green, colordown=color.red)

Fields:

FieldTypeDescription
titleStringTitle of the plot, displayed in the chart legend and data window.
seriesSeries<Option<f64>>Per-bar numeric values that determine arrow direction and relative height. Positive values draw an up arrow above the bar; negative values draw a down arrow below the bar. None (na) = no arrow is drawn on that bar. The absolute value determines the arrow's height relative to other arrows in the series — larger absolute values produce taller arrows.
up_colorsSeries<Option<Color>>Per-bar color for upward arrows (drawn when the series value is positive). Can change dynamically per bar. None = use the default color.
down_colorsSeries<Option<Color>>Per-bar color for downward arrows (drawn when the series value is negative). Can change dynamically per bar. None = use the default color.
offseti32Shifts arrows left (negative) or right (positive) by the given number of bars. Default: 0. The renderer should draw the arrow at bar_index + offset instead of bar_index.
min_heightusizeMinimum possible arrow height in pixels. The smallest absolute value in the series maps to this height. Default: 5.
max_heightusizeMaximum possible arrow height in pixels. The largest absolute value in the series maps to this height. Default: 100. Arrow heights are linearly interpolated between min_height and max_height based on the ratio of the bar's absolute value to the maximum absolute value across the entire series.
show_lastOption<usize>If set, only draw arrows on the last N bars (counting backwards from the most recent bar). All earlier bars are hidden. None = show all bars.
displayPlotDisplayBitflag controlling where the arrow data is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Rendering logic:

for bar_index in 0..chart.series_len():
    value = series[bar_index]
    if value is None:
        continue

    x = bar_to_pixel(bar_index + offset)

    if value > 0:
        // Up arrow: draw above the bar
        color = up_colors[bar_index]
        height = scale(abs(value), min_height, max_height)
        draw_up_arrow(x, bar_high - margin, height, color)
    else:
        // Down arrow: draw below the bar
        color = down_colors[bar_index]
        height = scale(abs(value), min_height, max_height)
        draw_down_arrow(x, bar_low + margin, height, color)

The arrow height scales proportionally between min_height and max_height based on the absolute value relative to the maximum absolute value in the series.


PlotCandle

Renders OHLC candles. Produced by the Pine plotcandle() function. Used to draw custom candlestick overlays (e.g., Heikin Ashi).

Pine example:

pinescript
plotcandle(haOpen, haHigh, haLow, haClose, title="Heikin Ashi", color=haClose >= haOpen ? color.green : color.red)

Fields:

FieldTypeDescription
titleStringTitle of the plot, displayed in the chart legend and data window.
seriesSeries<Option<Bar>>Per-bar OHLC data (open, high, low, close). Each entry is a Bar struct. None = no candle is drawn on that bar. If any of the four OHLC values is NaN, the bar should not be drawn. The maximum of the four values is used as the high, and the minimum as the low, regardless of which field they come from.
colorsSeries<Option<Color>>Per-bar color for the candle body (the rectangle between open and close). Can change dynamically per bar — typically green/bullish when close >= open, red/bearish otherwise. None = use the default color.
wick_colorsSeries<Option<Color>>Per-bar color for the candle wicks (the thin vertical lines extending from the body to the high and low). None = use the default wick color (often the same as the body or border color).
border_colorsSeries<Option<Color>>Per-bar color for the candle body outline/border. Drawn as a stroke around the body rectangle. None = use the default border color.
show_lastOption<usize>If set, only draw candles on the last N bars (counting backwards from the most recent bar). All earlier bars are hidden. None = show all bars.
displayPlotDisplayBitflag controlling where the candle data is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Bar struct (OHLC data):

FieldTypeDescription
openf64Open price
highf64High price
lowf64Low price
closef64Close price

Rendering:

For each bar with a non-None OHLC value:

  1. Draw the wick (vertical line from low to high) using wick_colors.
  2. Draw the body (rectangle from open to close) filled with colors.
  3. Draw the body border using border_colors.
  4. If close >= open the candle is bullish; otherwise bearish. Colors are already set per-bar by the script.

PlotBar

Renders OHLC bars (thin lines, not candles). Produced by the Pine plotbar() function.

Fields:

FieldTypeDescription
titleStringTitle of the plot, displayed in the chart legend and data window.
seriesSeries<Option<Bar>>Per-bar OHLC data (open, high, low, close). Each entry is a Bar struct. None = no OHLC bar is drawn on that bar. If any of the four values is NaN, the bar should not be drawn. The maximum of the four values is used as the high, and the minimum as the low.
colorsSeries<Option<Color>>Per-bar color applied to the entire OHLC bar (the vertical line, open tick, and close tick are all drawn in this color). Can change dynamically per bar. None = use the default color.
show_lastOption<usize>If set, only draw OHLC bars on the last N bars (counting backwards from the most recent bar). All earlier bars are hidden. None = show all bars.
displayPlotDisplayBitflag controlling where the bar data is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Rendering:

For each bar: draw a vertical line from low to high, a left tick at open, and a right tick at close. All use the same color from colors[bar_index].


BackgroundColor (bgcolor)

Fills the chart background with per-bar colors. Produced by the Pine bgcolor() function.

Pine example:

pinescript
bgcolor(close > open ? color.new(color.green, 90) : color.new(color.red, 90))

Fields:

FieldTypeDescription
colorsSeries<Option<Color>>Per-bar background color. Each entry fills the entire vertical strip for that bar (from the top of the pane to the bottom) with the specified color. Typically uses semi-transparent colors (high alpha/transparency) to tint the background without obscuring the chart data. None = transparent / no fill on that bar.
offseti32Shifts the background color series left (negative) or right (positive) by the given number of bars. Default: 0. The renderer should apply the color at bar_index + offset instead of bar_index.
titleOption<String>Title displayed in the chart legend and data window. None = no title.
show_lastOption<usize>If set, only apply background color to the last N bars (counting backwards from the most recent bar). All earlier bars are left unfilled. None = apply to all bars.
displayPlotDisplayBitflag controlling where the bgcolor data is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Rendering:

For each bar: if colors[bar_index] is not None, fill the vertical strip for that bar (from pane top to pane bottom) with the specified color. These are typically semi-transparent.


Fill

Fills the area between two anchors (two plots or two hlines). Produced by the Pine fill() function.

Pine example:

pinescript
p1 = plot(sma(close, 10))
p2 = plot(sma(close, 20))
fill(p1, p2, color=color.new(color.blue, 80))

Fields:

FieldTypeDescription
fromFillAnchorFirst boundary of the filled area. References either a Plot series graph (by SeriesGraphId) or an Hline graph (by GraphId). Both anchors must be the same type — you cannot mix a Plot and an Hline.
toFillAnchorSecond boundary of the filled area. Same anchor type as from. The fill is drawn between the Y values of from and to on each bar.
colorsSeries<Option<FillColor>>Per-bar fill color or gradient. Each entry can be Solid(Color) for a uniform fill, or Gradient(Gradient) for a vertical gradient that interpolates between two colors based on Y position. None = no fill on that bar. Can change dynamically per bar.
titleOption<String>Title displayed in the chart legend and data window. None = no title.
show_lastOption<usize>If set, only fill the last N bars (counting backwards from the most recent bar). All earlier bars are left unfilled. None = fill all bars.
fillgapsboolControls behavior when one of the anchors has an na (missing) value on a bar. If true, the last known value of the missing anchor is used, so the fill continues across the gap. If false, the fill is interrupted on bars where either anchor is na.
displayPlotDisplayBitflag controlling where the fill data is visible: on the chart pane, data window, price scale, status line, or all/none. Only render on the chart if the PANE flag is set. See PlotDisplay.

Gradient struct (used by FillColor::Gradient):

FieldTypeDescription
top_valuef64The Y-axis price value at which color1 applies at full intensity. Points at or above this value are rendered entirely in color1.
bottom_valuef64The Y-axis price value at which color2 applies at full intensity. Points at or below this value are rendered entirely in color2.
color1ColorColor applied at top_value. The gradient linearly interpolates from color1 to color2 between the two values.
color2ColorColor applied at bottom_value.

Rendering logic:

// Resolve anchor Y values
for bar_index in 0..chart.series_len():
    y1 = resolve_anchor(fill.from, bar_index)   // f64 or None
    y2 = resolve_anchor(fill.to, bar_index)      // f64 or None

    if y1 is None or y2 is None:
        if fillgaps: use last known values
        else: skip this bar

    fill_color = fill.colors[bar_index]
    if fill_color is None:
        continue

    match fill_color:
        Solid(color) -> fill_rect(x, min(y1,y2), bar_width, abs(y1-y2), color)
        Gradient(g)  -> fill_gradient(x, y1, y2, g.color1, g.color2, g.top_value, g.bottom_value)

To resolve an anchor:

  • FillAnchor::Plot(id) -> chart.series_graph(id)?.as_plot()?.series[bar_index]
  • FillAnchor::Hline(id) -> chart.graph(id)?.as_hline()?.value (constant for all bars)

Non-Series Graphs (Drawing Objects)

Iterate with chart.graphs(). Each entry is a (GraphId, &Graph) pair. These are point-in-time objects — they are not indexed by bar. They have explicit coordinates.

rust
for (id, graph) in chart.graphs() {
    match graph {
        Graph::Hline(h) => { /* render horizontal line */ }
        Graph::Label(l) => { /* render label */ }
        Graph::Line(l)  => { /* render line */ }
        Graph::LineFill(lf) => { /* render line fill */ }
        Graph::Box(b)   => { /* render box */ }
        Graph::Polyline(p) => { /* render polyline */ }
        Graph::Table(t) => { /* render table */ }
    }
}

Or use accessor methods: graph.as_hline(), graph.as_label(), etc.


Hline

A horizontal line at a fixed price level. Produced by the Pine hline() function.

Pine example:

pinescript
hline(70, "Overbought", color=color.red, linestyle=hline.style_dashed)

Fields:

FieldTypeDescription
valuef64The fixed Y-axis value at which the horizontal line is drawn. The line extends across the entire pane width at this value. Must be a constant (not per-bar).
colorOption<Color>Color of the horizontal line. Must be a constant. None = use the default color.
titleOption<String>Title displayed in the chart legend and data window. None = no title.
line_styleHlineStyleStroke pattern for the horizontal line: Solid, Dashed, or Dotted. See HlineStyle.
line_widthi32Width of the horizontal line in pixels. Default: 1.
displayPlotDisplayBitflag controlling where the hline is visible. Note: hlines use a simplified display that only supports display.none and display.all. See PlotDisplay.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting — hline has no Pine-level force_overlay parameter.

Rendering: Determine the target pane and its value range from force_overlay (same logic as other visuals). Draw a horizontal line across the full width of that pane at the pixel Y corresponding to value.


Label

A positioned text annotation with an optional background shape. Produced by label.new() in Pine Script.

Pine example:

pinescript
label.new(bar_index, high, "Buy Signal", style=label.style_label_down, color=color.green)

Fields:

FieldTypeDescription
xi64X coordinate of the label's anchor point. Interpretation depends on xloc: when XLocation::Index, this is a 0-based bar index; when XLocation::Time, this is a Unix timestamp in milliseconds.
yf64Y coordinate of the label's anchor point (price value). When yloc is AboveBar or BelowBar, this value is ignored and the label is positioned relative to the bar's high/low at the given X.
textStringText content displayed inside the label. Supports multiline text via \n.
xlocXLocationX-axis coordinate system. Index = bar index (default), Time = Unix timestamp in milliseconds. Determines how x is interpreted.
ylocYLocationY-axis positioning mode. Price (default) = use y as the exact price coordinate. AboveBar = position above the bar's high at the given X. BelowBar = position below the bar's low at the given X.
colorOption<Color>Background fill color of the label shape. The visual shape is determined by style. None = transparent background.
styleLabelStyleControls the visual shape of the label background: directional bubbles (up, down, left, right), arrows, geometric shapes (circle, diamond, square, triangle), or text-only (None). See LabelStyle.
text_colorOption<Color>Color of the text inside the label. None = use the default text color.
sizeu32Font size of the text in points.
text_alignHorizontalAlignHorizontal alignment of the text within the label area: Left, Center, or Right. Only meaningful for multiline text or labels wider than their text.
tooltipOption<String>Text shown in a tooltip popup when the user hovers over the label. None = no tooltip. Supports multiline text via \n.
text_font_familyFontFamilyFont family for the label text: Default (proportional) or Monospace.
text_formattingTextFormattingText style: None (regular), Bold, or Italic.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Line

A line segment between two points. Produced by line.new() in Pine Script.

Pine example:

pinescript
line.new(bar_index[10], high[10], bar_index, high, color=color.blue, width=2)

Fields:

FieldTypeDescription
x1i64X coordinate of the line's start point. Interpretation depends on xloc: bar index or Unix timestamp in milliseconds.
y1f64Y coordinate (price) of the line's start point.
x2i64X coordinate of the line's end point. Same coordinate system as x1.
y2f64Y coordinate (price) of the line's end point.
xlocXLocationX-axis coordinate system. Index = bar index (default), Time = Unix timestamp in milliseconds. Applies to both x1 and x2.
extendExtendControls whether the line extends beyond its defined endpoints. None (default) = draw only between (x1,y1) and (x2,y2). Left = extend infinitely to the left past (x1,y1). Right = extend infinitely to the right past (x2,y2). Both = extend in both directions. The extension follows the slope of the line.
colorOption<Color>Stroke color of the line. None = use the default color.
styleLineStyleStroke pattern: Solid, Dashed, Dotted, or arrow styles (ArrowLeft, ArrowRight, ArrowBoth) that add arrowheads at the endpoints. See LineStyle.
widthi32Width of the line stroke in pixels. Default: 1.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

LineFill

Fills the area between two Line objects. Produced by linefill.new() in Pine Script.

Fields:

FieldTypeDescription
line1GraphIdID of the first Line drawing object. Resolve via chart.graph(line1) to get the line's endpoints. Both lines must exist and be valid for the fill to render.
line2GraphIdID of the second Line drawing object. Resolve via chart.graph(line2). The fill is drawn in the region between the two lines.
colorOption<Color>Fill color for the region between the two lines. Typically semi-transparent. None = transparent (no fill rendered).

Rendering: Resolve both lines by their GraphId, then fill the polygon/region formed between them. The filled area is bounded by the two line segments (or their extensions if extend is set on either line). If either line is deleted or missing, the fill should not render.


Box

An axis-aligned rectangle with optional text. Produced by box.new() in Pine Script.

Pine example:

pinescript
box.new(bar_index - 10, high, bar_index, low, bgcolor=color.new(color.blue, 80))

Fields:

FieldTypeDescription
lefti64X coordinate of the left edge. Interpretation depends on xloc: bar index or Unix timestamp in milliseconds.
topf64Y coordinate of the top edge (higher price value).
righti64X coordinate of the right edge. Same coordinate system as left.
bottomf64Y coordinate of the bottom edge (lower price value).
border_colorOption<Color>Stroke color of the box border. None = no border drawn.
border_widthi32Width of the box border in pixels. Default: 1. Set to 0 for no border.
border_styleLineStyleStroke pattern for the box border: Solid, Dashed, or Dotted. Arrow styles are not typically used for boxes. See LineStyle.
extendExtendControls whether the box extends beyond its left/right edges. None (default) = draw only between left and right. Left = extend the left edge to the beginning of the chart. Right = extend the right edge to the end of the chart. Both = extend in both directions. The top and bottom Y values are preserved.
xlocXLocationX-axis coordinate system for left and right. Index = bar index (default), Time = Unix timestamp in milliseconds.
background_colorOption<Color>Interior fill color of the box. Typically semi-transparent. None = transparent (no fill).
textStringText displayed inside the box, positioned according to text_halign and text_valign. Empty string = no text. Supports multiline text via \n.
text_sizeu32Font size of the text in points.
text_colorOption<Color>Color of the text inside the box. None = use the default text color.
text_halignHorizontalAlignHorizontal alignment of the text within the box: Left, Center (default), or Right.
text_valignVerticalAlignVertical alignment of the text within the box: Top, Middle (default), or Bottom.
text_wrapTextWrapText wrapping behavior: Auto = wrap text to fit within the box width, None = no wrapping (text may overflow).
text_font_familyFontFamilyFont family for the text: Default (proportional) or Monospace.
text_formattingTextFormattingText style: None (regular), Bold, or Italic.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Polyline

A connected series of line segments (optionally closed and/or curved). Produced by polyline.new() in Pine Script.

Fields:

FieldTypeDescription
pointsVec<(i64, f64)>Ordered list of (x, y) vertices that define the polyline path. X values are bar indices, Y values are price levels. Points are connected in order. An empty list means nothing is drawn.
curvedboolControls the interpolation between points. true = render as a smooth curve through the points (using cubic spline or Bezier interpolation). false = connect points with straight line segments.
closedboolControls whether the path forms a closed shape. true = connect the last point back to the first point, forming a polygon. false = leave the path open (first and last points are not connected).
line_colorOption<Color>Stroke color of the polyline path. None = no stroke drawn.
fill_colorOption<Color>Interior fill color. Only meaningful when closed is true — fills the interior of the closed polygon. When closed is false, this is ignored. None = no fill. Typically semi-transparent.
line_styleLineStyleStroke pattern for the polyline: Solid, Dashed, or Dotted. See LineStyle.
line_widthi32Width of the polyline stroke in pixels. Default: 1.
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Rendering:

  1. Convert all (x, y) points to pixel coordinates.
  2. If curved: use cubic spline or Bezier interpolation.
  3. If closed: connect the last point to the first.
  4. Stroke the path with line_color, line_style, line_width.
  5. If fill_color is set and closed: fill the interior.

Table

A cell grid anchored to a fixed position on the chart. Produced by table.new() in Pine Script.

Pine example:

pinescript
var t = table.new(position.top_right, 2, 3)
table.cell(t, 0, 0, "Header", text_color=color.white, bgcolor=color.blue)

Fields:

FieldTypeDescription
positionPositionAnchor position on the chart where the table is placed. The table is rendered as a floating overlay at one of 9 positions (e.g., TopRight, BottomCenter, MiddleLeft). The table does not scroll with the chart — it stays fixed at the specified position. See Position.
background_colorOption<Color>Background color of the entire table. Applied behind all cells. None = transparent.
frame_colorOption<Color>Color of the outer frame (border around the entire table). None = no outer frame.
frame_widthi32Width of the outer frame in pixels. Default: 0 (no frame).
border_colorOption<Color>Default border color for the grid lines between cells. None = no cell borders.
border_widthi32Default width of the cell borders in pixels. Default: 0 (no cell borders).
force_overlayboolIf true, draw on the main price pane. If false, draw in the sub-pane. Defaults to the script's overlay setting.

Methods:

MethodReturn TypeDescription
num_columns()usizeNumber of columns
num_rows()usizeNumber of rows
cell(row, col)&TableCellAccess a cell (panics if out of bounds)
cell_opt(row, col)Option<&TableCell>Access a cell (returns None if out of bounds)

TableCell fields:

FieldTypeDescription
textStringText content displayed inside the cell. Supports multiline text via \n. Empty string = no text.
widthf32Cell width as a percentage of the chart's available width. 0.0 = auto-size based on content. Values are percentages (e.g., 25.0 = 25% of the chart width).
heightf32Cell height as a percentage of the chart's available height. 0.0 = auto-size based on content.
text_colorOption<Color>Color of the text inside the cell. None = use the default text color.
text_halignHorizontalAlignHorizontal alignment of the text within the cell: Left, Center (default), or Right.
text_valignVerticalAlignVertical alignment of the text within the cell: Top, Middle (default), or Bottom.
text_sizeu32Font size of the text in points.
background_colorOption<Color>Background color of this individual cell. Overrides the table-level background_color. None = inherit from the table.
tooltipOption<String>Text shown in a tooltip popup when the user hovers over the cell. None = no tooltip.
text_font_familyFontFamilyFont family for the cell text: Default (proportional) or Monospace.
text_formattingTextFormattingText style: None (regular), Bold, or Italic.
colspanusizeNumber of columns this cell spans. Default: 1. A value greater than 1 merges this cell with adjacent cells to the right.
rowspanusizeNumber of rows this cell spans. Default: 1. A value greater than 1 merges this cell with adjacent cells below.

Bar Colors

Access via chart.bar_colors(). This controls per-bar color overrides for the main candlestick/bar chart. Produced by the Pine barcolor() function.

Pine example:

pinescript
barcolor(close > open ? color.green : color.red)

Fields:

FieldTypeDescription
colorsSeries<Option<Color>>Per-bar color override for the main candlestick/bar chart. When set, the entire candle or bar (body, wick, border) is drawn in this color, overriding the default bullish/bearish coloring. None = no override on that bar (use the chart's default coloring).
offseti32Shifts the color series left (negative) or right (positive) by the given number of bars. Default: 0. The renderer should apply the color override at bar_index + offset instead of bar_index.
show_lastOption<usize>If set, only apply the color override to the last N bars (counting backwards from the most recent bar). All earlier bars use the default coloring. None = apply to all bars.
titleOption<String>Title displayed in the chart legend and data window. None = no title.
displayPlotDisplayBitflag controlling where the barcolor data is visible: on the chart pane, data window, price scale, status line, or all/none. Only apply the color override if the PANE flag is set. See PlotDisplay.

Rendering: When drawing the main OHLC candles/bars, check bar_colors.colors[bar_index]. If it is Some(color), use that color instead of the default bullish/bearish coloring.


Filled Orders (Strategy)

For strategy scripts, chart.filled_orders_on_bar(bar_index) returns the list of filled orders on a given bar. Each entry is a FilledOrder (signal/order id, price, signed quantity).

FilledOrder fields:

FieldTypeDescription
order_idStringSignal name (entry/exit id) from strategy.entry(), strategy.exit(), or strategy.order(). Shown next to the fill on the chart (TradingView-style).
pricef64The price at which the order was filled. Used as the Y coordinate when rendering the fill marker on the chart.
quantityf64The quantity (number of contracts/shares) filled in this execution. Positive = buy, negative = sell. Use the sign to determine the marker direction (e.g., up arrow for buys, down arrow for sells).

Renderers should draw each fill with its signal name (order_id) and signed quantity: buys above the bar, sells below; multiple fills on the same bar stacked. Sum quantity from the list if a total per bar is needed.


Enum Reference

ScriptInfo Enums

Format — number formatting for sub-pane Y-axis labels and crosshair/tooltip values:

VariantDescriptionExample output
InheritUse the chart's default formatting (default)150.25
PriceFormat as a price150.25
VolumeFormat with volume abbreviations1.5M, 200K
PercentFormat as a percentage3.14%
MinTickFormat using the symbol's minimum tick size(treat as Price if tick unavailable)

Apply format to all sub-pane axis labels and tooltip values. The main price axis (candlestick pane) always uses price formatting regardless of this field.

ScaleType — price scale placement:

VariantDescription
NoneAuto / no dedicated scale (default)
LeftShow on the left scale
RightShow on the right scale

Plot Enums

PlotStyle — rendering style for Plot:

VariantDescription
LineConnect points with straight line segments (default)
LineBrLike Line, but breaks at na values
StepLineStep/staircase line (horizontal then vertical)
StepLineBrLike StepLine, but breaks at na values
AreaFilled area between the line and histbase
AreaBrLike Area, but breaks at na values
HistogramThin vertical bars from histbase to value
ColumnsWide vertical bars from histbase to value
CirclesCircle marker at each point
CrossCross (+) marker at each point
DiamondDiamond marker at each point

PlotLineStyle — stroke pattern for line-based plots:

VariantDescription
SolidSolid stroke (default)
DashedDashed stroke
DottedDotted stroke

HlineStyle — stroke pattern for horizontal lines:

VariantDescription
SolidSolid stroke
DashedDashed stroke
DottedDotted stroke

Shape / Marker Enums

Shape — glyph type for PlotShape:

VariantVisual
XCrossX mark (default)
Cross+ mark
CircleCircle
SquareSquare
DiamondDiamond
TriangleUpUpward triangle
TriangleDownDownward triangle
ArrowUpUpward arrow
ArrowDownDownward arrow
FlagFlag
LabelUpLabel pointing up
LabelDownLabel pointing down

Location — vertical positioning for PlotShape / PlotChar:

VariantDescription
AboveBarFixed offset above the bar's high (default)
BelowBarFixed offset below the bar's low
AbsoluteUse the series value as the Y coordinate
TopAt the top of the pane
BottomAt the bottom of the pane

Size — size for shapes and characters:

VariantDescription
AutoAutomatic sizing (default)
TinyExtra small
SmallSmall
NormalStandard size
LargeLarge
HugeExtra large

Drawing Enums

LineStyle — stroke style for Line, Box border, Polyline:

VariantDescription
SolidSolid stroke (default)
DashedDashed stroke
DottedDotted stroke
ArrowLeftLine with a left-pointing arrowhead
ArrowRightLine with a right-pointing arrowhead
ArrowBothLine with arrowheads on both ends

Extend — line/box extension mode:

VariantDescription
NoneNo extension (default)
LeftExtend infinitely to the left
RightExtend infinitely to the right
BothExtend infinitely in both directions

LabelStyle — shape style for Label:

VariantDescription
NoneText only, no background shape
LabelDownDownward-pointing label bubble (default)
LabelUpUpward-pointing label bubble
LabelLeftLeft-pointing label bubble
LabelRightRight-pointing label bubble
LabelCenterCentered label bubble
LabelLowerLeftLower-left label bubble
LabelLowerRightLower-right label bubble
LabelUpperLeftUpper-left label bubble
LabelUpperRightUpper-right label bubble
ArrowDownDownward arrow
ArrowUpUpward arrow
CircleCircle shape
CrossCross (+) shape
DiamondDiamond shape
SquareSquare shape
FlagFlag shape
TriangleDownDownward triangle
TriangleUpUpward triangle
XCrossX-cross shape
TextOutlineText with outline, no fill

Coordinate Enums

XLocation — X-axis coordinate system:

VariantDescription
IndexX values are bar indices (0-based integers)
TimeX values are Unix timestamps in milliseconds

YLocation — Y-axis positioning (labels only):

VariantDescription
PriceY is a price value on the Y-axis (default)
AboveBarPosition above the bar at the given X
BelowBarPosition below the bar at the given X

Position Enum

Table anchor position on the chart:

VariantDescription
TopLeftTop-left corner
TopCenterTop center
TopRightTop-right corner
MiddleLeftMiddle left
MiddleCenterCenter of the chart
MiddleRightMiddle right
BottomLeftBottom-left corner
BottomCenterBottom center
BottomRightBottom-right corner

Text Enums

EnumVariantsDescription
HorizontalAlignLeft, Center, RightHorizontal text alignment
VerticalAlignTop, Middle, BottomVertical text alignment
FontFamilyDefault, MonospaceFont selection
TextFormattingNone, Bold, ItalicText style
TextWrapAuto, NoneText wrapping behavior

Fill Enums

FillAnchor — boundary reference for Fill:

VariantDescription
Plot(SeriesGraphId)References a Plot series graph
Hline(GraphId)References an Hline graph

FillColor — fill color type:

VariantDescription
Solid(Color)Uniform fill color
Gradient(Gradient)Vertical gradient between two values

Rendering Order

The recommended draw order (back to front):

  1. Chart background — clear with the theme background color.
  2. Grid lines — price and time axis gridlines.
  3. Background colors — iterate series_graphs, draw BackgroundColor strips.
  4. Fills — iterate series_graphs, draw Fill areas between anchors.
  5. Main candlesticks / bars — the input OHLC data (apply bar_colors overrides). If behind_chart is false, draw the script visuals on top; otherwise draw them behind.
  6. Hlines — iterate graphs, draw horizontal lines.
  7. Plot series — iterate series_graphs, draw Plot (lines, areas, histograms, markers).
  8. Extended series — iterate series_graphs, draw PlotCandle, PlotBar, PlotArrow, PlotChar, PlotShape.
  9. Drawing objects — iterate graphs, draw Line, Box, Polyline, LineFill.
  10. Labels — iterate graphs, draw Label (text + shape).
  11. Tables — iterate graphs, draw Table at their anchored positions.
  12. Axes — price scale, time scale, volume scale.
  13. Order fills — for strategies, draw fill markers from filled_orders.
  14. Crosshair / interaction overlay — mouse tracking, tooltips.

If explicit_plot_zorder is true, draw series graphs strictly in their iteration order (which is the declaration order in the script). Earlier = bottom layer.

If force_overlay is true on any visual, render it on the main price pane regardless of whether the script is an overlay.

When show_last is set, only render the last N entries. When offset is set, shift the visual by that many bars.

Next Steps

Released under the MIT License.