Skip to content

prelude

TIP

The prelude is loaded automatically into every script. Its types and functions are referenced directly by name — do not use a namespace prefix (e.g. write close, not prelude.close).

Types

box

Handle for a box drawing.


hline

Handle for a horizontal line created by hline().


hline_style

Style of a horizontal line (e.g. solid, dashed, dotted).


label

Handle for a label drawing.


line

Handle for a line drawing.


linefill

Handle for a linefill between two lines.


plot

Handle for a plot created by plot().


plot_display

Display options for plots (e.g. all, none, price_only).


plot_line_style

A named constant for use with the plot() function's linestyle parameter, which modifies the appearance of plotted lines.

If the style argument of the function call specifies a plot style that displays a line, using this constant as the linestyle argument specifies that the plotted line is solid.


plot_simple_display

Controls which price scale and chart the plot is displayed on.


plot_style

Named constants for the style of a plot (e.g. line, histogram, area).


polyline

Handle for a polyline drawing.


scale_type

Scale value for indicator() function.


sort_order

Determines the sort order of array operations (ascending or descending).


strategy_direction


table

Handle for a table drawing.


text_format

Format string for text (e.g. in labels).

Properties

bar_index

Type: series int

Index of the current bar.

Numbering is zero-based, so the first (oldest) bar on the chart has index 0. The value increases by 1 for each subsequent bar. Use bar_index[1] to reference the previous bar's index.


close

Type: series float

Closing price of the current bar.

On historical bars, this is the last traded price when the bar closed. On real-time bars, this is the current last traded price and will change until the bar closes.


dayofmonth

Type: int

Returns the day of month (1-31) of the current bar's opening time in the symbol's timezone.


dayofweek

Type: int

Returns the day of week of the current bar's opening time.


high

Type: series float

Highest price reached during the current bar.

On historical bars, this is the maximum traded price. On real-time bars, this value can increase as new highs are made.


hl2

Type: series float

The midpoint of high and low prices: (high + low) / 2.

Also known as the median price. Useful as a simple estimate of the bar's central price.


hlc3

Type: series float

The typical price: (high + low + close) / 3.

A common price proxy that weights the close equally with the high-low range. Often used in volume weighted calculations.


hlcc4

Type: series float

Weighted close price: (high + low + close + close) / 4.

Places extra weight on the closing price, giving it 50% of the total weight.


hour

Type: int

Returns the hour (0-23) of the current bar's opening time in the symbol's timezone.


last_bar_index

Type: series int

Index of the last (newest) bar on the chart.

Combined with bar_index, this can be used to determine the distance from the current bar to the chart's end, e.g., last_bar_index - bar_index gives bars remaining.


last_bar_time

Type: series int

Timestamp of the last bar on the chart, in UNIX format (milliseconds since 1970-01-01 00:00:00 UTC).

Useful for determining the chart's time range or for time-based calculations relative to the chart end.


low

Type: series float

Lowest price reached during the current bar.

On historical bars, this is the minimum traded price. On real-time bars, this value can decrease as new lows are made.


minute

Type: int

Returns the minute (0-59) of the current bar's opening time in the symbol's timezone.


month

Type: int

Returns the month (1-12) of the current bar's opening time in the symbol's timezone.


ohlc4

Type: series float

Average price: (open + high + low + close) / 4.

The arithmetic mean of all four OHLC prices, representing the bar's overall price activity.


open

Type: series float

Opening price of the current bar.

This is the first traded price when the bar opened. On real-time bars, this value is fixed once the bar opens.


second

Type: int

Returns the second (0-59) of the current bar's opening time in the symbol's timezone.


time

Type: series int

Opening time of the current bar in UNIX format (milliseconds since 1970-01-01 00:00:00 UTC).

On real-time bars, this is fixed when the bar opens. Use with time functions like year(), month(), hour() to extract components.


time_close

Type: series int

Closing time of the current bar in UNIX format (milliseconds since 1970-01-01 00:00:00 UTC).

This is when the bar will close based on the chart's timeframe.


timenow

Type: series int

Current real-world time in UNIX format (milliseconds since 1970-01-01 00:00:00 UTC).

Unlike time, which returns the bar's time, timenow returns the actual current time and updates continuously on real-time bars.


volume

Type: series float

Trading volume of the current bar.

Represents the total number of shares or contracts traded. May be na if volume data is unavailable for the symbol.


weekofyear

Type: int

Returns the week of year (1-53) of the current bar's opening time in the symbol's timezone.


year

Type: int

Returns the year of the current bar's opening time in the symbol's timezone.

Functions

alert

pine
alert(series string message, input string freq = alert.freq_once_per_bar)

Creates an alert with the given message and frequency.

Parameters

NameTypeDefaultDescription
messageseries string
freqinput stringalert.freq_once_per_bar

alertcondition

pine
alertcondition(series bool condition, const string title, const string message)

Creates an alert condition that can be used to trigger alerts based on a boolean condition.

Parameters

NameTypeDefaultDescription
conditionseries bool
titleconst string
messageconst string

barcolor

pine
barcolor(
    series color color,
    simple int offset = 0,
    input bool editable = true,
    input int show_last = na,
    const string title = na,
    input plot_simple_display display
  )

Sets the color of price bars on the chart.

Each bar can have its own color, allowing for dynamic coloring based on indicator conditions.

Parameters

NameTypeDefaultDescription
colorseries colorThe color to apply to the bar. Use na to keep the default color.
offsetsimple int0Shifts the coloring left (negative) or right (positive) by the specified number of bars.
editableinput booltrueIf true, the setting can be edited in the style dialog.
show_lastinput intnaIf set, only colors the last N bars.
titleconst stringnaTitle shown in the style dialog.
displayinput plot_simple_displayControls where the coloring is visible.

bgcolor

pine
bgcolor(
    series color color,
    simple int offset = 0,
    input bool editable = true,
    input int show_last = na,
    const string title = na,
    input plot_simple_display display = display.all,
    const bool force_overlay = na
  )

Fills the background of chart bars with a specified color.

Useful for highlighting specific conditions or time periods on the chart.

Parameters

NameTypeDefaultDescription
colorseries colorThe background color. Use na for transparent.
offsetsimple int0Shifts the background coloring left (negative) or right (positive) by the specified number of bars.
editableinput booltrueIf true, the setting can be edited in the style dialog.
show_lastinput intnaIf set, only fills the last N bars.
titleconst stringnaTitle shown in the style dialog.
displayinput plot_simple_displaydisplay.allControls where the background is visible.
force_overlayconst boolnaIf true, forces display on the main chart pane.

bool

Converts the x value to a bool value.

Parameters

NameTypeDefaultDescription
xint

Returns: boolfalse if x is na, false, or an int/float value equal to 0. true for all other values.

Converts a float to bool; returns false if na or zero, true otherwise.

Parameters

NameTypeDefaultDescription
xfloat

Returns: bool

Converts a bool to bool; returns false if na, otherwise the value.

Parameters

NameTypeDefaultDescription
xbool

Returns: bool

Converts a value of any type to bool; returns false if na, true otherwise.

Parameters

NameTypeDefaultDescription
xT

Returns: bool


box

pine
box(box x) → box

Casts na to box type.

Useful for initializing box variables that will be assigned later.

Parameters

NameTypeDefaultDescription
xbox

Returns: box


color

pine
color(color x) → color

Casts na to color

Parameters

NameTypeDefaultDescription
xcolor

Returns: color


dayofmonth

pine
dayofmonth(int timestamp, string timezone = syminfo.timezone) → int

Extracts the day of month (1-31) from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


dayofweek

pine
dayofweek(int timestamp, string timezone = syminfo.timezone) → int

Extracts the day of week from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int — 1 (Sunday) through 7 (Saturday).


fill

Fills the area between two horizontal lines with a solid color.

Useful for creating visual zones (e.g., overbought/oversold regions).

Parameters

NameTypeDefaultDescription
hline1hlineThe first horizontal line handle (from hline()).
hline2hlineThe second horizontal line handle (from hline()).
colorseries colorcolor.blueThe fill color.
titleconst stringnaTitle shown in the style dialog.
editableinput booltrueIf true, the fill can be edited in the style dialog.
fillgapsconst boolfalseIf true, fills gaps in the data.
displayinput plot_simple_displaydisplay.allControls where the fill is visible.

Fills the area between two plots with a solid color.

Useful for visualizing the difference or spread between two series.

Parameters

NameTypeDefaultDescription
plot1plotThe first plot handle (from plot()).
plot2plotThe second plot handle (from plot()).
colorseries colorcolor.blueThe fill color.
titleconst stringnaTitle shown in the style dialog.
editableinput booltrueIf true, the fill can be edited in the style dialog.
show_lastinput intnaIf set, only fills the last N bars.
fillgapsconst boolfalseIf true, fills gaps in the data.
displayinput plot_simple_displaydisplay.allControls where the fill is visible.

Fills the area between two plots with a vertical gradient.

The gradient transitions from top_color at top_value to bottom_color at bottom_value, creating a smooth color transition based on price levels.

Parameters

NameTypeDefaultDescription
plot1plotThe first plot handle (from plot()).
plot2plotThe second plot handle (from plot()).
top_valueseries floatThe price level where the top color is applied.
bottom_valueseries floatThe price level where the bottom color is applied.
top_colorseries colorcolor.blueThe color at the top of the gradient.
bottom_colorseries color#3a3c42The color at the bottom of the gradient.
titleconst stringnaTitle shown in the style dialog.
displayinput plot_simple_displaydisplay.allControls where the fill is visible.
fillgapsconst boolfalseIf true, fills gaps in the data.
editableinput booltrueIf true, the fill can be edited in the style dialog.

fixnan

pine
fixnan(series T value) → series T

Replaces na values with the last non-na value in the series.

Carries forward the most recent valid value, effectively "filling" gaps in the data. If no valid value has been seen yet, returns na. Useful for maintaining continuity in series that have occasional missing values.

Parameters

NameTypeDefaultDescription
valueseries TThe series value to process.

Returns: series T — The current value if it is not na, otherwise the most recent non-na value, or na if no valid value has been seen yet.


float

Casts na to float

Parameters

NameTypeDefaultDescription
xfloat

Returns: float

Converts an int to float.

Parameters

NameTypeDefaultDescription
xint

Returns: float


hline

pine
hline(
    input float price,
    const string title = na,
    input color color = color.blue,
    input hline_style linestyle = hline.style_dashed,
    input int linewidth = 1,
    input bool editable = true,
    input plot_simple_display display = display.all
  ) → hline

Draws a horizontal line at a fixed price level across the entire chart.

Unlike plot(), the price must be a constant or input value, not a series.

Parameters

NameTypeDefaultDescription
priceinput floatThe price level where the line is drawn.
titleconst stringnaTitle shown in the style dialog.
colorinput colorcolor.blueLine color.
linestyleinput hline_stylehline.style_dashedLine style: hline.style_solid, hline.style_dashed, hline.style_dotted.
linewidthinput int1Width of the line in pixels (1-4).
editableinput booltrueIf true, the line can be edited in the style dialog.
displayinput plot_simple_displaydisplay.allControls where the line is visible.

Returns: hline — An hline handle that can be used with fill().


hour

pine
hour(int timestamp, string timezone = syminfo.timezone) → int

Extracts the hour (0-23) from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


indicator

pine
indicator(
    const string title,
    const string shorttitle = na,
    const bool overlay = false,
    const string format = format.inherit,
    const int precision = na,
    const scale_type scale = na,
    const int max_bars_back = na,
    const string timeframe = na,
    const bool timeframe_gaps = true,
    const bool explicit_plot_zorder = false,
    const int max_lines_count = 50,
    const int max_labels_count = 50,
    const int max_boxes_count = 50,
    const int calc_bars_count = na,
    const int max_polylines_count = 50,
    const bool dynamic_requests = true,
    const bool behind_chart = true
  )

Designates the script as an indicator and sets indicator-related properties.

Parameters

NameTypeDefaultDescription
titleconst stringThe title of the script. It is displayed on the chart when no shorttitle argument is used, and becomes the publication's default title when publishing the script.
shorttitleconst stringnaThe script's display name on charts. If specified, it will replace the title argument in most chart-related windows.
overlayconst boolfalseIf true, the script's visuals appear on the main chart pane if the user adds it to the chart directly, or in another script's pane if the user applies it to that script. If false, the script's visuals appear in a separate pane.
formatconst stringformat.inheritSpecifies the formatting of the script's displayed values. Possible values: format.inherit, format.price, format.volume, format.percent. Optional.
precisionconst intnaSpecifies the number of digits after the floating point of the script's displayed values. Must be a non-negative integer no greater than 16. If format is set to format.inherit and precision is specified, the format will instead be set to format.price. When the function's format parameter uses format.volume, the precision parameter will not affect the result, as the decimal precision rules defined by format.volume supersede other precision settings. Optional. The default is inherited from the precision of the chart's symbol.
scaleconst scale_typenaThe price scale used. Possible values: scale.right, scale.left, scale.none. The scale.none value can only be applied in combination with overlay = true. Optional. By default, the script uses the same scale as the chart. Uses the scale_type type.
max_bars_backconst intnaThe length of the historical buffer the script keeps for every variable and function, which determines how many past values can be referenced using the [] history-referencing operator.
timeframeconst stringnaAdds multi-timeframe functionality to simple scripts.
timeframe_gapsconst booltrueSpecifies how the indicator's values are displayed on chart bars when the timeframe is higher than the chart's. If true, a value only appears on a chart bar when the higher timeframe value becomes available, otherwise na is returned (thus a "gap" occurs). With false, what would otherwise be gaps are filled with the latest known value returned, avoiding na values. Optional. The default is true.
explicit_plot_zorderconst boolfalseSpecifies the order in which the script's plots, fills, and hlines are rendered. If true, plots are drawn in the order in which they appear in the script's code, each newer plot being drawn above the previous ones. This only applies to plot*() functions, fill(), and hline().
max_lines_countconst int50The number of last line drawings displayed. Possible values: 1-500. The count is approximate; more drawings than the specified count may be displayed.
max_labels_countconst int50The number of last label drawings displayed. Possible values: 1-500. The count is approximate; more drawings than the specified count may be displayed.
max_boxes_countconst int50The number of last box drawings displayed. Possible values: 1-500. The count is approximate; more drawings than the specified count may be displayed.
calc_bars_countconst intnaLimits the initial calculation of a script to the last number of bars specified. The default is na, in which case the script executes on all available bars.
max_polylines_countconst int50The number of last polyline drawings displayed. Possible values: 1-100. The count is approximate; more drawings than the specified count may be displayed.
dynamic_requestsconst booltrueSpecifies whether the script can dynamically call functions from the request.*() namespace. Dynamic request.*() calls are allowed within the local scopes of conditional structures (e.g., if), loops (e.g., for), and exported functions. Additionally, such calls allow "series" arguments for many of their parameters.
behind_chartconst booltrueControls whether all plots and drawings appear behind the chart display (if true) or in front of it (if false). This parameter only takes effect when the overlay parameter is true.

input

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst int
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input int

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst float
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input float

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst bool
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input bool

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst color
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input color

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst string
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input string

Add an input to the script settings.

Parameters

NameTypeDefaultDescription
defvalconst expression
titleconst stringna
tooltipconst stringna
inlineconst stringna
groupconst stringna
displayconst plot_displaydisplay.all
activeinput booltrue

Returns: input float


int

Casts na to int

Parameters

NameTypeDefaultDescription
xint

Returns: int

Converts a float to int (truncates toward zero via math.floor).

Parameters

NameTypeDefaultDescription
xfloat

Returns: int


label

pine
label(label x) → label

Casts na to label type.

Useful for initializing label variables that will be assigned later.

Parameters

NameTypeDefaultDescription
xlabel

Returns: label


library

pine
library(
    const string title,
    const bool overlay = false,
    const bool dynamic_requests = true
  )

Declaration statement identifying a script as a library.

Parameters

NameTypeDefaultDescription
titleconst stringThe title of the library and its identifier. It cannot contain spaces, special characters or begin with a digit. It is used as the publication's default title, and to uniquely identify the library in the import statement, when another script uses it. It is also used as the script's name on the chart.
overlayconst boolfalse
dynamic_requestsconst booltrue

line

pine
line(line x) → label

Casts na to line type.

Useful for initializing line variables that will be assigned later.

Parameters

NameTypeDefaultDescription
xline

Returns: label


linefill

pine
linefill(linefill x) → linefill

Casts na to linefill type.

Useful for initializing linefill variables that will be assigned later.

Parameters

NameTypeDefaultDescription
xlinefill

Returns: linefill


minute

pine
minute(int timestamp, string timezone = syminfo.timezone) → int

Extracts the minute (0-59) from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


month

pine
month(int timestamp, string timezone = syminfo.timezone) → int

Extracts the month (1-12) from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


na

pine
na(any value) → bool

Tests if value is na (not available).

Essential for handling gaps in data, missing values in series, or uninitialized variables.

Parameters

NameTypeDefaultDescription
valueanyThe value to test. Can be any type.

Returns: booltrue if the value is undefined or missing, false otherwise.


nz

Replaces na values with a specified replacement.

If source is not na, returns source unchanged. If source is na, returns replacement. Essential for ensuring calculations don't propagate na values.

Parameters

NameTypeDefaultDescription
sourceTThe value to check.
replacementTThe value to return if source is na.

Returns: T

Replaces na integer values with a replacement (default 0).

Useful when you need a numeric fallback for missing integer data.

Parameters

NameTypeDefaultDescription
sourceintThe integer value to check.
replacementint0The value to return if source is na. Defaults to 0.

Returns: int

Replaces na float values with a replacement (default 0.0).

Useful when you need a numeric fallback for missing price or calculation data.

Parameters

NameTypeDefaultDescription
sourcefloatThe float value to check.
replacementfloat0The value to return if source is na. Defaults to 0.0.

Returns: float

Replaces na color values with a replacement (default black).

Useful when you need a visible fallback color for conditional coloring.

Parameters

NameTypeDefaultDescription
sourcecolorThe color value to check.
replacementcolor#000000The value to return if source is na. Defaults to #000000.

Returns: color


plot

pine
plot(
    series float series,
    const string title = na,
    series color color = color.blue,
    input int linewidth = 1,
    input plot_style style = plot.style_line,
    input bool trackprice = false,
    input float histbase = 0,
    simple int offset = 0,
    input bool join = false,
    input bool editable = true,
    input int show_last = na,
    input plot_display display = display.all,
    input string format = na,
    input int precision = na,
    const bool force_overlay = na,
    input plot_line_style linestyle = plot.linestyle_solid
  ) → plot

Plots a series of data on the chart as a visual representation.

Supports various styles including line, histogram, area, columns, and more.

Parameters

NameTypeDefaultDescription
seriesseries floatThe series of values to plot.
titleconst stringnaTitle of the plot, shown in the style dialog and as a data window tooltip.
colorseries colorcolor.blueColor of the plotted element.
linewidthinput int1Width of the plotted line, in pixels (1-4).
styleinput plot_styleplot.style_linePlot style: plot.style_line, plot.style_histogram, plot.style_area, plot.style_columns, etc.
trackpriceinput boolfalseIf true, a horizontal price line is shown at the last value.
histbaseinput float0The base value for histogram/columns style. Bars extend from this level to the series value.
offsetsimple int0Shifts the plot left (negative) or right (positive) by the specified number of bars.
joininput boolfalseIf true, connects gaps in the series with a line.
editableinput booltrueIf true, the plot style can be edited in the style dialog.
show_lastinput intnaIf set, only the last N bars are displayed.
displayinput plot_displaydisplay.allControls where the plot is displayed. Use display.all, display.none, display.pane, display.price_scale, etc.
formatinput stringnaOverrides the default number format for this plot in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces the plot to display on the main chart pane.
linestyleinput plot_line_styleplot.linestyle_solidLine style: plot.linestyle_solid, plot.linestyle_dashed, plot.linestyle_dotted.

Returns: plot — A plot handle that can be used with fill() to fill areas between plots.


plotarrow

pine
plotarrow(
    series float series,
    const string title = na,
    series color colorup = color.blue,
    series color colordown = color.black,
    simple int offset = 0,
    input int minheight = 5,
    input int maxheight = 100,
    input bool editable = true,
    input int show_last = na,
    input plot_display display = display.all,
    input string format = na,
    input int precision = na,
    const bool force_overlay = na
  )

Plots up and down arrows on the chart based on the sign of the series.

An up arrow is drawn when the value is positive, a down arrow when negative. The arrow height is proportional to the absolute value, scaled between minheight and maxheight. Useful for visualizing momentum or direction changes.

Parameters

NameTypeDefaultDescription
seriesseries floatThe data series. Positive values draw up arrows, negative draw down arrows. na or zero values draw nothing.
titleconst stringnaTitle shown in the style dialog and data window.
colorupseries colorcolor.blueColor of up arrows.
colordownseries colorcolor.blackColor of down arrows.
offsetsimple int0Shifts arrows left (negative) or right (positive) by the specified bars.
minheightinput int5Minimum arrow height in pixels.
maxheightinput int100Maximum arrow height in pixels.
editableinput booltrueIf true, the plot can be edited in the style dialog.
show_lastinput intnaIf set, only shows arrows on the last N bars.
displayinput plot_displaydisplay.allControls where arrows are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

plotbar

pine
plotbar(
    series float open,
    series float high,
    series float low,
    series float close,
    const string title = na,
    series color color = color.blue,
    input bool editable = true,
    input int show_last = na,
    input plot_display display = display.all,
    input string format = na,
    input int precision = na,
    const bool force_overlay = na
  )

Plots OHLC bars on the chart.

Each bar shows open, high, low, and close prices as a traditional bar chart element. Useful for overlaying custom OHLC data or displaying transformed price data.

Parameters

NameTypeDefaultDescription
openseries floatThe open price for each bar.
highseries floatThe high price for each bar.
lowseries floatThe low price for each bar.
closeseries floatThe close price for each bar.
titleconst stringnaTitle shown in the style dialog and data window.
colorseries colorcolor.blueBar color.
editableinput booltrueIf true, the plot can be edited in the style dialog.
show_lastinput intnaIf set, only shows the last N bars.
displayinput plot_displaydisplay.allControls where bars are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

plotcandle

pine
plotcandle(
    series float open,
    series float high,
    series float low,
    series float close,
    const string title = na,
    series color color = color.blue,
    series color wickcolor = color.blue,
    input bool editable = true,
    input int show_last = na,
    series color bordercolor = color.black,
    input plot_display display = display.all,
    input string format = na,
    input int precision = na,
    const bool force_overlay = na
  )

Plots candlesticks on the chart.

Each candle shows open, high, low, and close prices with a body and wicks. Useful for overlaying custom candlestick data (e.g., Heikin-Ashi) or displaying transformed price series.

Parameters

NameTypeDefaultDescription
openseries floatThe open price for each candle.
highseries floatThe high price for each candle.
lowseries floatThe low price for each candle.
closeseries floatThe close price for each candle.
titleconst stringnaTitle shown in the style dialog and data window.
colorseries colorcolor.blueCandle body color.
wickcolorseries colorcolor.blueCandle wick color.
editableinput booltrueIf true, the plot can be edited in the style dialog.
show_lastinput intnaIf set, only shows the last N candles.
bordercolorseries colorcolor.blackCandle body border color.
displayinput plot_displaydisplay.allControls where candles are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

plotchar

Plots a character at each bar where the series has a non-na value.

The character is positioned relative to the bar based on location. Useful for marking specific events or conditions on the chart.

Parameters

NameTypeDefaultDescription
seriesseries floatThe data series. A character is drawn when the value is not na.
titleconst stringnaTitle shown in the style dialog and data window.
charinput string"⭐"The character to display (Unicode supported).
locationinput stringlocation.abovebarVertical position: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute.
colorseries colorcolor.blueCharacter color.
offsetsimple int0Shifts the character left (negative) or right (positive) by bars.
textconst stringnaOptional text displayed near the character.
textcolorseries colorcolor.blueColor of the optional text.
editableinput booltrueIf true, the plot can be edited in the style dialog.
sizeconst stringsize.autoCharacter size: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
show_lastinput intnaIf set, only shows characters on the last N bars.
displayinput plot_displaydisplay.allControls where characters are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

Plots a character at each bar where the bool series is true.

A character is drawn when the value is true.

Parameters

NameTypeDefaultDescription
seriesseries boolThe boolean series. A character is drawn when true.
titleconst stringnaTitle shown in the style dialog and data window.
charinput string"⭐"The character to display (Unicode supported).
locationinput stringlocation.abovebarVertical position: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute.
colorseries colorcolor.blueCharacter color.
offsetsimple int0Shifts the character left (negative) or right (positive) by bars.
textconst stringnaOptional text displayed near the character.
textcolorseries colorcolor.blueColor of the optional text.
editableinput booltrueIf true, the plot can be edited in the style dialog.
sizeconst stringsize.autoCharacter size: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
show_lastinput intnaIf set, only shows characters on the last N bars.
displayinput plot_displaydisplay.allControls where characters are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

plotshape

Plots a shape at each bar where the series has a non-na value.

Various shape styles are available (arrows, circles, crosses, etc.). The shape is positioned relative to the bar based on location.

Parameters

NameTypeDefaultDescription
seriesseries floatThe data series. A shape is drawn when the value is not na.
titleconst stringnaTitle shown in the style dialog and data window.
styleinput stringshape.xcrossShape style: shape.xcross, shape.cross, shape.triangleup, shape.triangledown, shape.flag, shape.circle, shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown, shape.square, shape.diamond.
locationinput stringlocation.abovebarVertical position: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute.
colorseries colorcolor.blueShape color.
offsetsimple int0Shifts the shape left (negative) or right (positive) by bars.
textconst stringnaOptional text displayed near the shape.
textcolorseries colorcolor.blueColor of the optional text.
editableinput booltrueIf true, the plot can be edited in the style dialog.
sizeconst stringsize.autoShape size: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
show_lastinput intnaIf set, only shows shapes on the last N bars.
displayinput plot_displaydisplay.allControls where shapes are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

Plots a shape at each bar where the bool series is true.

A shape is drawn when the value is true.

Parameters

NameTypeDefaultDescription
seriesseries boolThe boolean series. A shape is drawn when true.
titleconst stringnaTitle shown in the style dialog and data window.
styleinput stringshape.xcrossShape style: shape.xcross, shape.cross, shape.triangleup, shape.triangledown, shape.flag, shape.circle, shape.arrowup, shape.arrowdown, shape.labelup, shape.labeldown, shape.square, shape.diamond.
locationinput stringlocation.abovebarVertical position: location.abovebar, location.belowbar, location.top, location.bottom, location.absolute.
colorseries colorcolor.blueShape color.
offsetsimple int0Shifts the shape left (negative) or right (positive) by bars.
textconst stringnaOptional text displayed near the shape.
textcolorseries colorcolor.blueColor of the optional text.
editableinput booltrueIf true, the plot can be edited in the style dialog.
sizeconst stringsize.autoShape size: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
show_lastinput intnaIf set, only shows shapes on the last N bars.
displayinput plot_displaydisplay.allControls where shapes are displayed.
formatinput stringnaOverrides the default number format in the data window.
precisioninput intnaNumber of decimal places for display.
force_overlayconst boolnaIf true, forces display on the main chart pane.

second

pine
second(int timestamp, string timezone = syminfo.timezone) → int

Extracts the second (0-59) from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


strategy

pine
strategy(
    const string title,
    const string shorttitle = na,
    const bool overlay = false,
    const string format = format.inherit,
    const int precision = na,
    const scale_type scale = na,
    const int pyramiding = 0,
    const bool calc_on_order_fills = false,
    const bool calc_on_every_tick = false,
    const int max_bars_back = na,
    const int backtest_fill_limits_assumption = 0,
    const string default_qty_type = strategy.fixed,
    const float default_qty_value = 1,
    const float initial_capital = 1000000,
    simple string currency = syminfo.currency,
    const int slippage = 0,
    const string commission_type = strategy.commission.percent,
    const float commission_value = 0,
    const bool process_orders_on_close = false,
    const string close_entries_rule = "FIFO",
    const float margin_long = 100,
    const float margin_short = 100,
    const bool explicit_plot_zorder = false,
    const int max_lines_count = 50,
    const int max_labels_count = 50,
    const int max_boxes_count = 50,
    const int calc_bars_count = na,
    const float risk_free_rate = 2,
    const bool use_bar_magnifier = false,
    const bool fill_orders_on_standard_ohlc = false,
    const int max_polylines_count = 50,
    const bool dynamic_requests = true,
    const bool behind_chart = true
  )

Designates the script as a strategy and sets strategy-related properties.

Parameters

NameTypeDefaultDescription
titleconst string
shorttitleconst stringna
overlayconst boolfalse
formatconst stringformat.inherit
precisionconst intna
scaleconst scale_typena
pyramidingconst int0
calc_on_order_fillsconst boolfalse
calc_on_every_tickconst boolfalse
max_bars_backconst intna
backtest_fill_limits_assumptionconst int0
default_qty_typeconst stringstrategy.fixed
default_qty_valueconst float1
initial_capitalconst float1000000
currencysimple stringsyminfo.currency
slippageconst int0
commission_typeconst stringstrategy.commission.percent
commission_valueconst float0
process_orders_on_closeconst boolfalse
close_entries_ruleconst string"FIFO"
margin_longconst float100
margin_shortconst float100
explicit_plot_zorderconst boolfalse
max_lines_countconst int50
max_labels_countconst int50
max_boxes_countconst int50
calc_bars_countconst intna
risk_free_rateconst float2
use_bar_magnifierconst boolfalse
fill_orders_on_standard_ohlcconst boolfalse
max_polylines_countconst int50
dynamic_requestsconst booltrue
behind_chartconst booltrue

string

pine
string(string x) → string

Casts na to string

Parameters

NameTypeDefaultDescription
xstring

Returns: string


time

pine
time(
    series string timeframe,
    series string session = na,
    series string timezone = syminfo.timezone
  ) → series int

Returns the bar's opening time for a specific timeframe and session.

Useful for multi-timeframe analysis or session-aware calculations.

Parameters

NameTypeDefaultDescription
timeframeseries stringThe timeframe string (e.g., "D", "60", "W").
sessionseries stringnaOptional session specification (e.g., "0930-1600"). If na, no session filter is applied.
timezoneseries stringsyminfo.timezoneTimezone for session interpretation. Defaults to symbol's timezone.

Returns: series int — UNIX timestamp in milliseconds, or na if the bar falls outside the specified session.


time_close

pine
time_close(
    series string timeframe,
    series string session = na,
    series string timezone = syminfo.timezone
  ) → series int

Returns the bar's closing time for a specific timeframe and session.

Parameters

NameTypeDefaultDescription
timeframeseries stringThe timeframe string (e.g., "D", "60", "W").
sessionseries stringnaOptional session specification. If na, no session filter is applied.
timezoneseries stringsyminfo.timezoneTimezone for session interpretation. Defaults to symbol's timezone.

Returns: series int — UNIX timestamp in milliseconds, or na if the bar falls outside the specified session.


timestamp

Parses a date/time string and returns the corresponding UNIX timestamp in milliseconds.

The string must be in ISO 8601 format (e.g., "2024-01-15" or "2024-01-15T09:30:00Z") or IETF RFC 2822 format.

Parameters

NameTypeDefaultDescription
date_stringstringThe date/time string to parse.

Returns: int

Creates a UNIX timestamp from date/time components using the chart's timezone.

Parameters

NameTypeDefaultDescription
yearintThe year (e.g., 2024).
monthintThe month (1-12).
dayintThe day of month (1-31).
hourint0The hour (0-23). Defaults to 0.
minuteint0The minute (0-59). Defaults to 0.
secondint0The second (0-59). Defaults to 0.

Returns: int — Milliseconds since 1970-01-01 00:00:00 UTC.

Creates a UNIX timestamp from date/time components in a specified timezone.

Parameters

NameTypeDefaultDescription
timezonestringsyminfo.timezoneThe timezone (e.g., "America/New_York", "UTC", "GMT+8").
yearintThe year (e.g., 2024).
monthintThe month (1-12).
dayintThe day of month (1-31).
hourint0The hour (0-23). Defaults to 0.
minuteint0The minute (0-59). Defaults to 0.
secondint0The second (0-59). Defaults to 0.

Returns: int — Milliseconds since 1970-01-01 00:00:00 UTC.


weekofyear

pine
weekofyear(int timestamp, string timezone = syminfo.timezone) → int

Extracts the week of year (1-53) from a UNIX timestamp in the specified timezone.

Week 1 is the week containing January 4th (ISO 8601).

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int


year

pine
year(int timestamp, string timezone = syminfo.timezone) → int

Extracts the year from a UNIX timestamp in the specified timezone.

Parameters

NameTypeDefaultDescription
timestampintThe UNIX timestamp in milliseconds.
timezonestringsyminfo.timezoneThe timezone for interpretation. Defaults to symbol's timezone.

Returns: int

Released under the MIT License.