Skip to content

Global ​

What does each bar give your script before you write a line? Its prices (open, high, low, close, volume), its place (bar_index) and its times (time, time_close), each read fresh on every bar. This page holds those values and the functions with no namespace: the na tests, the type casts and the date functions.

pine
//@version=6
indicator("Bar range, ignoring gaps")
rng = high - low
avg = ta.sma(rng, 20)
// nz turns the first 19 bars' na into 0
plot(nz(avg), "Average range")
plot(dayofweek == dayofweek.monday ? rng : na, "Monday's range", color.orange, style = plot.style_circles)

A date function reads the bar's own time when you give it none, in the exchange's timezone unless you name one: hour is the bar's hour on the exchange's clock, and hour(time, "UTC") the hour in UTC. See timezones.

ask ​

Pine v6No effect here
pine
float ask

The best ask price, which this engine reads as na on every bar: no feed here carries it.

bar_index ​

pine
series int bar_index

The bar's position in the run, counting from 0 on the first bar.

bid ​

Pine v6No effect here
pine
float bid

The best bid price, which this engine reads as na on every bar: no feed here carries it.

bool ​

pine
bool(x) → series bool

x as a bool: false for na, 0 and an infinity, true for any other number.

Parameter
x
series any

box ​

pine
box(x) → series box

x typed as a box, which gives na a type: box(na).

Parameter
x
series box

close ​

pine
series float close

The bar's closing price. On the forming bar it is the latest price.

color ​

pine
color(x) → series color

x as a colour: a colour stays itself, and a string such as "#FF0000" becomes one.

Parameter
x
series color/string

dayofmonth ​

pine
series int dayofmonth
dayofmonth(time, timezone) → series int

The day of the month, from 1 to 31.

Parameter
time
series int
timezone
series string

dayofweek ​

pine
series int dayofweek
dayofweek(time, timezone) → series int

The day of the week, from 1 for Sunday to 7 for Saturday. Compare it with the dayofweek.* constants.

Parameter
time
series int
timezone
series string

dayofyear ​

AmenoScript only
ameno
series int dayofyear
dayofyear(time, timezone) → series int

The day of the year, from 1 on January 1st.

Parameter
time
series int
timezone
series string

fixnan ​

pine
fixnan(source) → series color/int/float/bool

The source, or its last value that wasn't na where it is na.

An infinity is kept, not replaced.

Parameter
source
series color/int/float/bool

float ​

pine
float(x) → series float

x as a float. A na stays na.

Parameter
x
series int/float/bool

high ​

pine
series float high

The bar's highest price.

hl2 ​

pine
series float hl2

(high + low) / 2.

hlc3 ​

pine
series float hlc3

(high + low + close) / 3.

hlcc4 ​

pine
series float hlcc4

(high + low + close + close) / 4.

hour ​

pine
series int hour
hour(time, timezone) → series int

The hour, from 0 to 23.

Parameter
time
series int
timezone
series string

int ​

pine
int(x) → series int

x as an int, its fraction cut toward zero: int(2.7) is 2 and int(-2.7) is -2. A na stays na.

Parameter
x
series int/float

label ​

pine
label(x) → series label

x typed as a label, which gives na a type: label(na).

Parameter
x
series label

last_bar_index ​

pine
series int last_bar_index

The bar_index of the run's last bar.

In leak-safe AmenoScript, the run's last bar is the last closed one.

It looks ahead on history

On every bar it reads the last bar's index, which a bar in the past couldn't know. A decision on it repaints.

last_bar_time ​

pine
series int last_bar_time

The time of the run's last bar, in milliseconds.

In leak-safe AmenoScript, the run's last bar is the last closed one. Like last_bar_index, it reads the future on history.

line ​

pine
line(x) → series line

x typed as a line, which gives na a type: line(na).

Parameter
x
series line

linefill ​

pine
linefill(x) → series linefill

x typed as a linefill, which gives na a type: linefill(na).

Parameter
x
series linefill

low ​

pine
series float low

The bar's lowest price.

max_bars_back ​

Pine v6No effect here
pine
max_bars_back(var, num) → void

Accepted for compatibility, and does nothing: every series keeps its whole history here.

ParameterDescription
var
any series type
The series TradingView would size.
num
const int
How many bars TradingView would keep.

minute ​

pine
series int minute
minute(time, timezone) → series int

The minute, from 0 to 59.

Parameter
time
series int
timezone
series string

month ​

pine
series int month
month(time, timezone) → series int

The month, from 1 to 12. Compare it with the month.* constants.

Parameter
time
series int
timezone
series string

na ​

pine
any type na
na(x) → series bool

Whether x is na. An infinity and the empty string count as na too. Alone, na is the value that means "no value".

Parameter
x
any

nz ​

pine
nz(source, replacement) → series bool/color/float/int

source, or replacement where source is na or an infinity.

ParameterDefaultDescription
source
bool/color/float/int
The value to test.
replacement
bool/color/float/int
0What to use instead.

ohlc4 ​

pine
series float ohlc4

(open + high + low + close) / 4.

open ​

pine
series float open

The bar's opening price.

second ​

pine
series int second
second(time, timezone) → series int

The second, from 0 to 59.

Parameter
time
series int
timezone
series string

string ​

pine
string(x) → series string

x as a string. A na stays na.

Parameter
x
series any

table ​

pine
table(x) → series table

x typed as a table, which gives na a type: table(na).

Parameter
x
series table

time ​

pine
series int time
time(timeframe, session, bars_back, timeframe_bars_back, timezone) → series int
time(timeframe, session, timezone, bars_back, timeframe_bars_back) → series int
time(timeframe, bars_back, timeframe_bars_back) → series int

The bar's opening time, in milliseconds since 1970 UTC. As a function, the opening time of the period of timeframe that holds the bar, or na when the bar is outside session.

bars_back reads a bar further back, and a negative one a bar ahead on the symbol's schedule, up to 500. timeframe_bars_back steps by whole periods of timeframe instead. The timezone can come third, after the session, as on TradingView, and with no session the second and third arguments are bars_back and timeframe_bars_back. A session that doesn't parse stops the script. See bar times and sessions.

ParameterDefaultDescription
timeframe
series string
The period to read, such as "1D". An empty string is the chart's own.
session
series string
A session such as "0930-1600", or "regular" or "extended". Outside it, the call reads na.
bars_back
series int
0How many bars back to read. A negative count reads ahead.
timeframe_bars_back
series int
0How many periods of timeframe back to read.
timezone
series string
The timezone the session is read in. The exchange's if left out.
pine
//@version=6
indicator("In the New York session", overlay = true)
inSession = not na(time(timeframe.period, "0930-1600", "America/New_York")) // timezone third, as on TradingView
bgcolor(inSession ? color.new(color.blue, 90) : na)

time_close ​

pine
series int time_close
time_close(timeframe, session, bars_back, timeframe_bars_back, timezone) → series int
time_close(timeframe, session, timezone, bars_back, timeframe_bars_back) → series int
time_close(timeframe, bars_back, timeframe_bars_back) → series int

The bar's closing time, in milliseconds, on the symbol's own schedule: a stock's daily bar closes at its session's end, not at midnight. As a function, the closing time of the period of timeframe that holds the bar.

It takes the same arguments as time. On the forming bar it is the time the bar will close. See bar times.

ParameterDefaultDescription
timeframe
series string
The period to read. An empty string is the chart's own.
session
series string
A session. Outside it, the call reads na.
bars_back
series int
0How many bars back to read.
timeframe_bars_back
series int
0How many periods of timeframe back to read.
timezone
series string
The timezone the session is read in.

time_tradingday ​

pine
series int time_tradingday

The trading day the bar belongs to, as 00:00 UTC of that date, in milliseconds.

The day is the date on the exchange's clock when the bar closes. A daily bar of a session that opens the evening before belongs to the day it closes on; an hourly bar of that evening belongs to the evening's own date, which TradingView may count as the next day.

timenow ​

pine
series int timenow

The current time, in milliseconds. It is the same on every bar of a run, and moves on the next run.

It changes between runs

A decision on timenow can come out differently each time the script runs.

timestamp ​

pine
timestamp(year, month, day, hour, minute, second) → series int
timestamp(timezone, year, month, day, hour, minute, second) → series int
timestamp(dateString) → series int

A time in milliseconds, from a date and time or a date string.

timestamp(year, month, day, hour, minute, second) reads the date in the exchange's timezone, and with a timezone first, in that one. A date string such as "2024-03-01" or "2024-03-01T09:30:00+01:00" without a timezone is read as UTC. A string that isn't a date stops the script.

ParameterDefaultDescription
year
series int
The year.
month
series int
The month, from 1 to 12.
day
series int
The day of the month.
hour
series int
0The hour, from 0 to 23.
minute
series int
0The minute.
second
series int
0The second.
timezone
series string
An IANA name such as "America/New_York", or an offset such as "UTC+2".
dateString
const string
A date, with or without a time and a timezone.

volume ​

pine
series float volume

The bar's volume. A series with no volume reads 0.

weekofyear ​

pine
series int weekofyear
weekofyear(time, timezone) → series int

The ISO week of the year, from 1 to 53. Week 1 holds the year's first Thursday.

Parameter
time
series int
timezone
series string

year ​

pine
series int year
year(time, timezone) → series int

The year.

Parameter
time
series int
timezone
series string

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.