Sidechair

Pine Script variables

Browse the reference

163 built-in variables: prices, bar state, time and symbol info.

Open the Pine Editor

Top-level variables

aggressor_side
Which side started the latest trade on a tick chart: a buyer lifting the ask or a seller hitting the bid.
ask
The best price a seller is currently asking, available only on tick charts in real time.
bar_index
The number of the current bar, counting from 0 at the first bar loaded on the chart.
bid
The best price a buyer is currently bidding, available only on tick charts in real time.
close
The closing price of the current bar; on a bar that is still forming, the latest traded price.
dayofmonth
The day of the month of the current bar's open time, from 1 to 31.
dayofweek
The day of the week of the current bar's open time, from 1 for Sunday to 7 for Saturday.
high
The highest price traded during the current bar.
hl2
The midpoint of the bar's range: (high + low) / 2.
hlc3
The typical price: (high + low + close) / 3.
hlcc4
The close-weighted price: (high + low + close + close) / 4.
hour
The hour of the day of the current bar's open time, from 0 to 23, in the exchange time zone.
last_bar_index
The bar_index of the last bar on the chart, available on every bar of the run.
last_bar_time
The opening time of the last bar on the chart, in milliseconds since 1970-01-01 UTC.
low
The lowest price traded during the current bar.
minute
The minute of the hour of the current bar's open time, from 0 to 59.
month
The calendar month of the current bar's open time, from 1 for January to 12 for December.
na
The value that means no value; assigning it clears a variable and any calculation using it returns na.
ohlc4
The average of the four prices of the bar: (open + high + low + close) / 4.
open
The opening price of the current bar.
second
The second of the minute of the current bar's open time, from 0 to 59.
time
The opening time of the current bar as a UNIX timestamp in milliseconds.
time_close
The closing time of the current bar as a UNIX timestamp in milliseconds.
time_tradingday
The date of the trading session the current bar belongs to, as a UNIX timestamp at 00:00 UTC.
timenow
The current real-world time as a UNIX timestamp in milliseconds, read when the script runs.
volume
The traded volume of the current bar, in shares, contracts or coins depending on the symbol.
weekofyear
The week number of the year for the current bar's open time, starting at 1.
year
The calendar year of the current bar's open time, in the exchange time zone.

barstate.*

barstate.isconfirmed
True when the script is running on the final calculation of a bar, so the bar's values will not change again.
barstate.isfirst
True on the first bar of the chart, and false on every other bar. Use it to set up values once.
barstate.ishistory
True on every bar that closed before the script loaded, and false on bars that arrive live.
barstate.islast
True on the last bar of the chart, and on a live chart on every tick of the bar that is still forming.
barstate.islastconfirmedhistory
True on the last bar that was already closed when the script loaded, just before live bars begin.
barstate.isnew
True on the first calculation of a bar: every historical bar, and the first tick of a new live bar.
barstate.isrealtime
True on the bar that is forming now, while the market is trading, and false on every closed historical bar.

box.*

box.all
An array holding every box currently on the chart, from the oldest to the newest.

chart.*

chart.bg_color
The color of the chart's background, which follows the theme and canvas setting.
chart.fg_color
A color that reads against the chart background: dark on a light chart, light on a dark one.
chart.is_heikinashi
True when the chart shows Heikin Ashi candles, whose values are averaged from the real bars.
chart.is_kagi
True when the chart shows Kagi lines, which turn only when price reverses by a set amount.
chart.is_linebreak
True when the chart shows Line Break bars, where a reversal needs a close beyond the last three lines.
chart.is_pnf
True when the chart shows Point and Figure columns of Xs and Os, built from box size and reversal count.
chart.is_range
True when the chart shows Range bars, each closed once price has travelled a fixed range from the open.
chart.is_renko
True when the chart shows Renko bricks, which form when price moves a set amount, not when time passes.
chart.is_standard
True on bars, candles, hollow candles, line and area charts, where the script sees the real traded prices.
chart.left_visible_bar_time
The timestamp, in milliseconds, of the leftmost bar on screen right now.
chart.right_visible_bar_time
The timestamp, in milliseconds, of the rightmost bar on screen right now.

dividends.*

dividends.future_amount
The cash amount per share of the company's next announced dividend; na when none is announced.
dividends.future_ex_date
The next ex-dividend date as a UNIX timestamp in milliseconds; na when no dividend is announced.
dividends.future_pay_date
The date the next dividend is paid out, as a UNIX timestamp in milliseconds; na when none is announced.

earnings.*

earnings.future_eps
The analysts' estimate of earnings per share for the next report; na when there is no estimate.
earnings.future_period_end_time
The last day of the fiscal period the next earnings report covers, as a UNIX timestamp in milliseconds.
earnings.future_revenue
The analysts' estimate of revenue for the next report; na when there is no estimate.
earnings.future_time
The time of the next earnings report as a UNIX timestamp in milliseconds; na when none is scheduled.

label.*

label.all
A snapshot array of every label the script currently has on the chart.

line.*

line.all
Holds every line still on the chart as an array, oldest first, rebuilt on each read.

linefill.*

linefill.all
Lists every shaded band currently on the chart, one linefill per pair of lines.

polyline.*

polyline.all
Lists every polyline the script keeps on the chart, bounded by max_polylines_count.

runtime.*

runtime.calculation.mode
Tells a script whether it is calculating for the chart or for an alert, as the string chart or alert.

session.*

session.isfirstbar
True on the first bar of a session, the one that opens a new trading day.
session.isfirstbar_regular
True on the first bar of the regular trading session, ignoring any pre-market bars before it.
session.islastbar
True on the last bar of a session, the one after which a new session starts.
session.islastbar_regular
True on the last bar of the regular trading session, ignoring any extended hours that follow.
session.ismarket
True when the bar falls in the regular trading session, as opposed to pre-market or post-market.
session.ispostmarket
True when the bar falls in the post-market session, after the regular close.
session.ispremarket
True when the bar falls in the pre-market session, before the regular open.

strategy.*

strategy.account_currency
The currency the strategy's money is counted in, such as USD.
strategy.avg_losing_trade
The average loss of the losing closed trades in the account currency.
strategy.avg_losing_trade_percent
The average percentage loss of the losing closed trades.
strategy.avg_trade
The average result of a closed trade in the account currency, winners and losers together.
strategy.avg_trade_percent
The average result of a closed trade as a percent of the trade's entry value.
strategy.avg_winning_trade
The average profit of the winning closed trades in the account currency.
strategy.avg_winning_trade_percent
The average percentage gain of the winning closed trades.
strategy.closedtrades
The number of trades the strategy has closed so far, counting from the start of the chart.
strategy.closedtrades.first_index
The index of the oldest closed trade still held in the trade list; the first valid trade_num for the closed-trade functions.
strategy.equity
The strategy's current equity: initial capital plus net profit plus open profit.
strategy.eventrades
The number of closed trades that finished with exactly zero profit.
strategy.grossloss
The sum of the losses of all losing closed trades, as a positive number.
strategy.grossloss_percent
The gross loss of all losing closed trades as a percent of the initial capital.
strategy.grossprofit
The sum of the profits of all winning closed trades.
strategy.grossprofit_percent
The gross profit of all winning closed trades as a percent of the initial capital.
strategy.initial_capital
The starting capital set by the initial_capital argument of strategy().
strategy.losstrades
The number of closed trades that lost money.
strategy.margin_liquidation_price
The price at which the current position would be liquidated by a margin call, or na.
strategy.max_contracts_held_all
The largest position size, long or short, that the strategy has held so far.
strategy.max_contracts_held_long
The largest long position size the strategy has held so far.
strategy.max_contracts_held_short
The largest short position size the strategy has held so far.
strategy.max_drawdown
The largest peak-to-trough fall in equity so far, in the account currency.
strategy.max_drawdown_percent
The largest peak-to-trough fall in equity so far, as a percent of the equity peak.
strategy.max_runup
The largest trough-to-peak rise in equity so far, in the account currency.
strategy.max_runup_percent
The largest trough-to-peak rise in equity so far, as a percent of the equity low.
strategy.netprofit
The total profit of all closed trades, after commission.
strategy.netprofit_percent
The total profit of all closed trades as a percent of the initial capital.
strategy.openprofit
The unrealised profit or loss of the open position at the current price.
strategy.openprofit_percent
The unrealised profit or loss of the open position as a percent of the initial capital.
strategy.opentrades
The number of trades currently open, counting each entry order that has not been closed as its own trade.
strategy.opentrades.capital_held
The account-currency capital tied up by the trades that are currently open.
strategy.position_avg_price
The average entry price of the open position, or na when the strategy is flat.
strategy.position_entry_name
The id of the entry order that opened the current position, or an empty string when flat.
strategy.position_size
The size of the current position: positive for long, negative for short, 0 when flat.
strategy.wintrades
The number of closed trades that made a profit.

syminfo.*

syminfo.basecurrency
The base currency of a pair, such as EUR in EURUSD or BTC in BTCUSD.
syminfo.country
The two-letter country code of the issuer, such as US, as an ISO 3166-1 alpha-2 string.
syminfo.currency
The currency the symbol's prices are quoted in, as a code such as USD or EUR.
syminfo.current_contract
The ticker of the actual contract behind a continuous futures chart, such as ESZ2025; na elsewhere.
syminfo.description
The long name of the symbol, such as Apple Inc., for text a person reads.
syminfo.employees
The company's latest reported number of employees; na for symbols with no fundamentals.
syminfo.expiration_date
The expiry of a futures contract as a UNIX timestamp in milliseconds; na for symbols that do not expire.
syminfo.industry
The industry of the company inside its sector, such as Semiconductors; na for symbols without fundamentals.
syminfo.isin
The ISIN of the instrument, the twelve-character international security identifier.
syminfo.main_tickerid
The ticker id of the chart's own symbol, unchanged even when read inside a request.security expression.
syminfo.mincontract
The smallest tradable quantity of the symbol, such as 0.0001 for a coin or 1 for a share.
syminfo.minmove
The integer numerator of the tick size: mintick equals minmove divided by pricescale.
syminfo.mintick
The smallest price step the symbol can move, such as 0.01 for a stock quoted in cents.
syminfo.pointvalue
The money value of a one-point price move for one unit of the symbol, in the symbol's currency.
syminfo.prefix
The exchange prefix of the chart's symbol, the text before the colon in an id such as NASDAQ:AAPL.
syminfo.pricescale
The integer denominator of the tick size: 100 for two-decimal prices, 10000 for four.
syminfo.recommendations_buy
The number of analysts currently rating the company a buy.
syminfo.recommendations_buy_strong
The number of analysts currently rating the company a strong buy.
syminfo.recommendations_date
The time of the latest analyst recommendation update, as a UNIX timestamp in milliseconds.
syminfo.recommendations_hold
The number of analysts currently rating the company a hold, or neutral.
syminfo.recommendations_sell
The number of analysts currently rating the company a sell.
syminfo.recommendations_sell_strong
The number of analysts currently rating the company a strong sell.
syminfo.recommendations_total
The number of analysts behind the current set of buy, hold and sell recommendations.
syminfo.root
The root of a derivative's symbol, such as ES for the futures contract ESZ2025; the same as the ticker for other symbols.
syminfo.sector
The sector the company belongs to, such as Technology Services, as a string; na for non-stock symbols.
syminfo.session
The session type the chart uses for this symbol, either regular or extended hours.
syminfo.shareholders
The number of shareholders of record the company last reported; na where no data exists.
syminfo.shares_outstanding_float
The number of shares freely available to trade, excluding insider and restricted holdings.
syminfo.shares_outstanding_total
The total number of shares the company has issued, including those not available to trade.
syminfo.target_price_average
The mean of the analysts' price targets for the stock.
syminfo.target_price_date
The time of the latest analyst price-target update, as a UNIX timestamp in milliseconds.
syminfo.target_price_estimates
How many analyst price targets stand behind the target-price figures.
syminfo.target_price_high
The highest analyst price target for the stock.
syminfo.target_price_low
The lowest analyst price target for the stock.
syminfo.target_price_median
The middle value of the analysts' price targets, less sensitive to extreme targets than the mean.
syminfo.ticker
The symbol's name without the exchange prefix, such as AAPL or ES1!.
syminfo.tickerid
The full identifier of the chart's symbol, the string you pass to request.security to point at the same instrument.
syminfo.timezone
The IANA time zone of the symbol's exchange, such as America/New_York.
syminfo.type
The kind of instrument on the chart, as a string such as stock, futures, forex, crypto or index.
syminfo.volumetype
What the volume series counts for this symbol: base units, quote currency, ticks or nothing.

ta.*

ta.accdist
The accumulation/distribution line: a running total of each bar's close location within its range, multiplied by volume.
ta.iii
The intraday intensity index: a running total of (2 * close - high - low) / ((high - low) * volume).
ta.nvi
The negative volume index: starts at 1 and changes with price only on bars where volume fell from the previous bar.
ta.obv
On-balance volume: a running total that adds the bar's volume when the close rises and subtracts it when the close falls.
ta.pvi
The positive volume index: starts at 1 and changes with price only on bars where volume rose from the previous bar.
ta.pvt
The price-volume trend: a running total of volume multiplied by the percentage change in close.
ta.tr
The true range of the current bar: the largest of high - low, |high - previous close| and |low - previous close|.
ta.vwap
The session volume-weighted average price of hlc3, restarting at the start of every trading session.
ta.wad
Williams accumulation/distribution: a running total of how far each close moves beyond the true high or true low.
ta.wvad
Williams variable accumulation/distribution: the bar's close-to-open move as a share of its range, times volume.

table.*

table.all
Holds every table the script has made, so a loop can reach tables whose variables are out of scope.

timeframe.*

timeframe.isdaily
True when the chart's timeframe is measured in days, such as one day or three days.
timeframe.isdwm
True when the chart's timeframe is a day or longer: daily, weekly or monthly.
timeframe.isintraday
True when the chart's timeframe is shorter than one day: seconds, ticks or minutes.
timeframe.isminutes
True when the chart's timeframe is measured in minutes or hours, such as 1, 15 or 240.
timeframe.ismonthly
True when the chart's timeframe is measured in months, such as one month or three months.
timeframe.isseconds
True when the chart's timeframe is measured in seconds, such as 1S or 30S.
timeframe.isticks
True when the chart's timeframe is measured in ticks, with one bar per fixed number of trades.
timeframe.isweekly
True when the chart's timeframe is measured in weeks, such as one week or two weeks.
timeframe.main_period
The timeframe of the chart itself as a string, unchanged inside a request.security call that uses another timeframe.
timeframe.multiplier
The number in the chart's timeframe: 5 on a five-minute chart, 240 on a four-hour chart, 1 on a daily chart.
timeframe.period
The chart's timeframe as a string, such as "5" for five minutes or "60" for one hour.