The way scripts can obtain information about the chart and symbol they are currently running on is through a subset of Pine Script®’s built-in variables. The ones we cover here allow scripts to access information relating to:
The built-in variables for OHLCV values are:
Other values are available through:
On historical bars, the values of the above variables do not vary during the bar because only OHLCV information is available on them. When running on historical bars, scripts execute on the bar’s close, when all the bar’s information is known and cannot change during the script’s execution on the bar.
Realtime bars are another story altogether.
When indicators (or strategies using calc_on_every_tick = true
) run in realtime,
the values of the above variables (except open)
will vary between successive iterations of the script on the realtime bar,
because they represent their current value at one point in time during the progress of the realtime bar.
This may lead to one form of repainting.
See the page on Pine Script®’s execution model for more details.
The [] history-referencing operator
can be used to refer to past values of the built-in variables, e.g., close[1]
refers to the
value of close on the previous bar,
relative to the particular bar the script is executing on.
Built-in variables in the syminfo
namespace provide scripts with information on the symbol of the chart
the script is running on. This information changes every time a script user changes the chart’s symbol.
The script then re-executes on all the chart’s bars using the new values of the built-in variables:
session
parameter in
ticker.new().symbol
parameter.
It includes session, prefix and ticker information.This script will display the values of those built-in variables on the chart:
//@version=5
indicator("`syminfo.*` built-ins", "", true)
printTable(txtLeft, txtRight) =>
var table t = table.new(position.middle_right, 2, 1)
table.cell(t, 0, 0, txtLeft, bgcolor = color.yellow, text_halign = text.align_right)
table.cell(t, 1, 0, txtRight, bgcolor = color.yellow, text_halign = text.align_left)
nl = "\n"
left =
"syminfo.basecurrency: " + nl +
"syminfo.currency: " + nl +
"syminfo.description: " + nl +
"syminfo.mintick: " + nl +
"syminfo.pointvalue: " + nl +
"syminfo.prefix: " + nl +
"syminfo.root: " + nl +
"syminfo.session: " + nl +
"syminfo.ticker: " + nl +
"syminfo.tickerid: " + nl +
"syminfo.timezone: " + nl +
"syminfo.type: "
right =
syminfo.basecurrency + nl +
syminfo.currency + nl +
syminfo.description + nl +
str.tostring(syminfo.mintick) + nl +
str.tostring(syminfo.pointvalue) + nl +
syminfo.prefix + nl +
syminfo.root + nl +
syminfo.session + nl +
syminfo.ticker + nl +
syminfo.tickerid + nl +
syminfo.timezone + nl +
syminfo.type
printTable(left, right)
A script can obtain information on the type of timeframe used on the chart using these built-ins, which all return a “simple bool” result:
Two additional built-ins return more specific timeframe information:
60
because intraday timeframes are expressed in minutes.
A 30sec timeframe will return 30
(seconds), a daily chart will return 1
(day), a quarterly chart will return 3
(months),
and a yearly chart will return 12
(months). The value of this variable cannot be used as an argument to timeframe
parameters in
built-in functions, as they expect a string in timeframe specifications format.See the page on Timeframes for more information.
Session information is available in different forms:
session
parameter in
ticker.new().