Appearance
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 askThe best ask price, which this engine reads as na on every bar: no feed here carries it.
bar_index
pine
series int bar_indexThe bar's position in the run, counting from 0 on the first bar.
bid
Pine v6No effect here
pine
float bidThe best bid price, which this engine reads as na on every bar: no feed here carries it.
bool
pine
bool(x) → series boolx as a bool: false for na, 0 and an infinity, true for any other number.
| Parameter |
|---|
xseries any |
box
pine
box(x) → series boxx typed as a box, which gives na a type: box(na).
| Parameter |
|---|
xseries box |
close
pine
series float closeThe bar's closing price. On the forming bar it is the latest price.
color
pine
color(x) → series colorx as a colour: a colour stays itself, and a string such as "#FF0000" becomes one.
| Parameter |
|---|
xseries color/string |
dayofmonth
pine
series int dayofmonth
dayofmonth(time, timezone) → series intThe day of the month, from 1 to 31.
| Parameter |
|---|
timeseries int |
timezoneseries string |
dayofweek
pine
series int dayofweek
dayofweek(time, timezone) → series intThe day of the week, from 1 for Sunday to 7 for Saturday. Compare it with the dayofweek.* constants.
| Parameter |
|---|
timeseries int |
timezoneseries string |
dayofyear
AmenoScript only
ameno
series int dayofyear
dayofyear(time, timezone) → series intThe day of the year, from 1 on January 1st.
| Parameter |
|---|
timeseries int |
timezoneseries string |
fixnan
pine
fixnan(source) → series color/int/float/boolThe source, or its last value that wasn't na where it is na.
An infinity is kept, not replaced.
| Parameter |
|---|
sourceseries color/int/float/bool |
float
pine
float(x) → series floatx as a float. A na stays na.
| Parameter |
|---|
xseries int/float/bool |
high
pine
series float highThe 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 intThe hour, from 0 to 23.
| Parameter |
|---|
timeseries int |
timezoneseries string |
int
pine
int(x) → series intx as an int, its fraction cut toward zero: int(2.7) is 2 and int(-2.7) is -2. A na stays na.
| Parameter |
|---|
xseries int/float |
label
pine
label(x) → series labelx typed as a label, which gives na a type: label(na).
| Parameter |
|---|
xseries label |
last_bar_index
pine
series int last_bar_indexThe 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_timeThe 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 linex typed as a line, which gives na a type: line(na).
| Parameter |
|---|
xseries line |
linefill
pine
linefill(x) → series linefillx typed as a linefill, which gives na a type: linefill(na).
| Parameter |
|---|
xseries linefill |
low
pine
series float lowThe bar's lowest price.
max_bars_back
Pine v6No effect here
pine
max_bars_back(var, num) → voidAccepted for compatibility, and does nothing: every series keeps its whole history here.
| Parameter | Description |
|---|---|
varany series type | The series TradingView would size. |
numconst int | How many bars TradingView would keep. |
minute
pine
series int minute
minute(time, timezone) → series intThe minute, from 0 to 59.
| Parameter |
|---|
timeseries int |
timezoneseries string |
month
pine
series int month
month(time, timezone) → series intThe month, from 1 to 12. Compare it with the month.* constants.
| Parameter |
|---|
timeseries int |
timezoneseries string |
na
pine
any type na
na(x) → series boolWhether x is na. An infinity and the empty string count as na too. Alone, na is the value that means "no value".
| Parameter |
|---|
xany |
nz
pine
nz(source, replacement) → series bool/color/float/intsource, or replacement where source is na or an infinity.
| Parameter | Default | Description |
|---|---|---|
sourcebool/color/float/int | The value to test. | |
replacementbool/color/float/int | 0 | What to use instead. |
ohlc4
pine
series float ohlc4(open + high + low + close) / 4.
open
pine
series float openThe bar's opening price.
second
pine
series int second
second(time, timezone) → series intThe second, from 0 to 59.
| Parameter |
|---|
timeseries int |
timezoneseries string |
string
pine
string(x) → series stringx as a string. A na stays na.
| Parameter |
|---|
xseries any |
table
pine
table(x) → series tablex typed as a table, which gives na a type: table(na).
| Parameter |
|---|
xseries 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 intThe 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.
| Parameter | Default | Description |
|---|---|---|
timeframeseries string | The period to read, such as "1D". An empty string is the chart's own. | |
sessionseries string | A session such as "0930-1600", or "regular" or "extended". Outside it, the call reads na. | |
bars_backseries int | 0 | How many bars back to read. A negative count reads ahead. |
timeframe_bars_backseries int | 0 | How many periods of timeframe back to read. |
timezoneseries 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 intThe 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.
| Parameter | Default | Description |
|---|---|---|
timeframeseries string | The period to read. An empty string is the chart's own. | |
sessionseries string | A session. Outside it, the call reads na. | |
bars_backseries int | 0 | How many bars back to read. |
timeframe_bars_backseries int | 0 | How many periods of timeframe back to read. |
timezoneseries string | The timezone the session is read in. |
time_tradingday
pine
series int time_tradingdayThe 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 timenowThe 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 intA 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.
| Parameter | Default | Description |
|---|---|---|
yearseries int | The year. | |
monthseries int | The month, from 1 to 12. | |
dayseries int | The day of the month. | |
hourseries int | 0 | The hour, from 0 to 23. |
minuteseries int | 0 | The minute. |
secondseries int | 0 | The second. |
timezoneseries string | An IANA name such as "America/New_York", or an offset such as "UTC+2". | |
dateStringconst string | A date, with or without a time and a timezone. |
volume
pine
series float volumeThe bar's volume. A series with no volume reads 0.
weekofyear
pine
series int weekofyear
weekofyear(time, timezone) → series intThe ISO week of the year, from 1 to 53. Week 1 holds the year's first Thursday.
| Parameter |
|---|
timeseries int |
timezoneseries string |
year
pine
series int year
year(time, timezone) → series intThe year.
| Parameter |
|---|
timeseries int |
timezoneseries string |