Skip to content

Plotting

Navi Stream provides two plotting statements for rendering chart elements: plot and hline.

Both plot and hline can only be used at the top-level scope. They cannot be used inside functions.

plot

plot draws a data series on the chart. It takes one required positional argument (the value to plot) and several optional named arguments.

Syntax

nv
plot(<value>, title: <string>, color: <color>, style: <plotstyle>, key: <string>, hidden: <bool>, format_number: <bool>);

Arguments

ArgumentTypeRequiredDefaultDescription
valuenumberYesThe numeric value to plot.
titlestringNoThe display name of the series in the legend.
colorcolorNoThe color of the series. Can be a color literal (e.g. #red, #ff8d1e) or a variable.
styleplotstyleNoplotstyle.lineThe drawing style of the series.
keystringNoA unique identifier for the series, used for programmatic reference.
hiddenboolNofalseIf true, the series is hidden by default.
format_numberboolNofalseIf true, the value will be formatted with number formatting (e.g. thousand separators).

Plot Styles

The plotstyle enum provides the following styles:

ValueDescription
plotstyle.lineDraws a line chart (default).
plotstyle.histogramDraws a histogram (bar) chart.
plotstyle.circlesDraws individual circle markers.
plotstyle.stickDraws vertical stick lines.

Examples

Basic line plot:

nv
plot(close, title: "Close", color: #blue);

Multiple series with different colors:

nv
plot(ma(close, 5), title: "MA5", color: #ffbb53, key: "MA1");
plot(ma(close, 10), title: "MA10", color: #4781ff, key: "MA2");
plot(ma(close, 20), title: "MA20", color: #fc6ebc, key: "MA3");

Dynamic color with a variable:

nv
let colors = close >= open ? #up : #down;
plot(volume, title: "Volume", color: colors, style: plotstyle.histogram);

Using different plot styles:

nv
plot(volume, title: "VOL", color: #blue, style: plotstyle.histogram, format_number: true);
plot(macd, title: "MACD", color: #yellow, style: plotstyle.stick);
plot(sline, title: "SAR", color: #red, style: plotstyle.circles);

Hidden series:

nv
plot(ma(close, 120), title: "MA120", color: #d858ff, key: "MA6", hidden: true);

hline

hline draws a horizontal line at a fixed value on the chart. It is typically used to mark reference levels such as overbought/oversold thresholds.

Syntax

nv
hline(<value>, color: <color>, style: <linestyle>, width: <number>, show_label: <bool>);

Arguments

ArgumentTypeRequiredDefaultDescription
valuenumberYesThe y-axis value at which to draw the horizontal line.
colorcolorNoThe color of the line.
stylelinestyleNolinestyle.solidThe line drawing style.
widthnumberNoThe width of the line.
show_labelboolNofalseIf true, displays the value label on the line.

Line Styles

The linestyle enum provides the following styles:

ValueDescription
linestyle.solidDraws a solid line (default).
linestyle.dashDraws a dashed line.

Examples

Simple horizontal line:

nv
hline(50, color: #494138, style: linestyle.dash, width: 1, show_label: true);

Marking overbought and oversold levels:

nv
hline(30, color: #494138, style: linestyle.dash, width: 1, show_label: true);
hline(50, color: #494138, style: linestyle.dash, width: 1, show_label: true);
hline(70, color: #494138, style: linestyle.dash, width: 1, show_label: true);

Using solid line style:

nv
hline(100, color: #red, style: linestyle.solid, width: 2);