Skip to content

Spline

Kind: module

Namespace: spline

Outputs values to the chart. Supports lines, histograms, areas, and other visual styles. For bar background fill only, see bgColor.

Each spline maintains one value per bar. A new value is added when a new bar starts and replaced when the current bar updates.

spline()

Kind: func

Outputs a value to the chart as a line or other visual element.

Syntax

spline(value) → void
spline(value, {title, style, offset, color, overlay}) → void

Arguments

NameTypeDescription
valuenumber, seriesValue or series to plot

Options

Static (ignored after the first call):

NameTypeDefaultDescription
title?stringnullDisplay name in the legend
style?constspline.STYLE_LINEVisual style (see Styles)
offset?int0Horizontal offset in bars (positive = right)
overlay?booleanfalseIf true, draws on the main price chart instead of a separate pane

Dynamic (can change per bar):

NameTypeDefaultDescription
color?colornullLine color

Returns

void

Caveats

  • Must be called inside onTick(), not in the init section
  • Must be at the top level of onTick(), not inside conditionals or loops. This ensures the call count and order remain constant across ticks

Pitfall

javascript
function onTick() {
    if (bar.isConfirmed()) {
        spline(close);  // ❌ inside conditional
    }
}

Example

javascript
const length = input.double("length", 20);

function onTick() {
    const sma = ta.sma(close, length);

    // Basic output
    spline(sma, {title: "SMA"});

    // Static type + dynamic color
    spline(close, {
        title: "Trend",
        style: spline.STYLE_STEPLINE,
        color: close > sma ? color.GREEN : color.RED,
        overlay: true
    });

    // Histogram type
    spline(volume, {title: "Volume", style: spline.STYLE_HISTOGRAM});
}

Styles

Visual style constants for spline() output. Use with the style option.

Styles are grouped by family: for each line-like base (LINE, STEPLINE, LINE_BREAK), the solid stroke comes first, then the dashed variant, then the variant with point markers. Other chart types follow, then AREA_BREAK and STEPLINE_BREAK.


spline.STYLE_LINE

Kind: constant

Value: LINE

Standard line connecting all data points.


spline.STYLE_LINE_DASHED

Kind: constant

Value: LINE_DASHED

Same as STYLE_LINE, but the stroke is dashed instead of solid.


spline.STYLE_LINE_POINTS

Kind: constant

Value: LINE_POINTS

Same as STYLE_LINE, but each data point is drawn with a visible marker.


spline.STYLE_STEPLINE

Kind: constant

Value: STEPLINE

Step line (horizontal then vertical).


spline.STYLE_STEPLINE_DASHED

Kind: constant

Value: STEPLINE_DASHED

Same as STYLE_STEPLINE, but the stroke is dashed instead of solid.


spline.STYLE_STEPLINE_POINTS

Kind: constant

Value: STEPLINE_POINTS

Same as STYLE_STEPLINE, but each data point is drawn with a visible marker.


spline.STYLE_HISTOGRAM

Kind: constant

Value: HISTOGRAM

Vertical bars from zero to value.


spline.STYLE_CROSS

Kind: constant

Value: CROSS

Cross markers at each data point.


spline.STYLE_AREA

Kind: constant

Value: AREA

Filled area from zero to line.


spline.STYLE_COLUMNS

Kind: constant

Value: COLUMNS

Column bars at each data point.


spline.STYLE_CIRCLES

Kind: constant

Value: CIRCLES

Circle markers at each data point.


spline.STYLE_LINE_BREAK

Kind: constant

Value: LINE_BREAK

Line with gaps on NaN values.


spline.STYLE_LINE_BREAK_DASHED

Kind: constant

Value: LINE_BREAK_DASHED

Like STYLE_LINE_BREAK: line with gaps on NaN values, but the stroke is dashed instead of solid.


spline.STYLE_LINE_BREAK_POINTS

Kind: constant

Value: LINE_BREAK_POINTS

Like STYLE_LINE_BREAK: line with gaps on NaN values, but each data point is drawn with a visible marker.


spline.STYLE_AREA_BREAK

Kind: constant

Value: AREA_BREAK

Area with gaps on NaN values.


spline.STYLE_STEPLINE_BREAK

Kind: constant

Value: STEPLINE_BREAK

Step line with gaps on NaN values.