Skip to content

Facts and known time ​

How do you read an earnings report or an inflation print on the bar it was published, not on the date it describes? Use the dated requests: request.dividends, request.splits, request.earnings, request.economic and request.financial. Each value arrives on the first bar that closes after it became public, so a backtest never holds a number before the market had it.

pine
//@version=6
indicator("US inflation, as released")
// Each figure appears on the first bar that closes after its release
float yoy = request.economic("US", "IRYY")
float claims = request.economic("US", "IJC")
plot(yoy, "Inflation, year on year")
plot(claims / 1000, "Initial jobless claims, thousands")

These calls are Pine Script v6's own, so they work in either dialect. What differs from TradingView is the data and, for two kinds, the date a value lands on, as each section says.

How a dated value is read ​

Every dated request reads one daily series, and each row carries the time it was published. A chart bar reads the newest row published by its close.

  • gaps = barmerge.gaps_on reads the value only on the bar it arrives, and na on every other bar. With the default, gaps_off, the last value repeats until the next.
  • lookahead = barmerge.lookahead_on puts each value on its own date instead, which can be before it was public. A Pine run warns; a leak-safe run refuses it.
  • currency isn't converted: values stay as published, and the run warns if you ask for another currency.
  • A ticker with no data reads na. ignore_invalid_symbol = true keeps the run quiet about it.

Dividends and splits ​

request.dividends(ticker, field) reads dividends.gross, the amount per share. dividends.net reads the gross amount too, with a warning, since the source gives no other. request.splits(ticker, field) reads splits.numerator or splits.denominator.

Each lands on the bar after its ex-date, as on TradingView.

Earnings ​

request.earnings(ticker, field) reads earnings.actual, the reported earnings per share, or earnings.estimate. earnings.standardized reads the reported figure, with a warning. A report published after the close lands on the next session, as on TradingView.

Economic data ​

request.economic(country_code, field) takes TradingView's two-letter country codes and field codes:

CountryFields
USMost of TradingView's, among them GDP, CPI and CCPI (core CPI), IRYY and IRMM (inflation, year on year and month on month), PPI, PCEPI (the PCE price index), UR (the unemployment rate), NFP (non-farm payrolls), IJC (initial jobless claims), M2, INTR (the policy rate), HST (housing starts), RSMM (retail sales, month on month) and CCI (consumer confidence).
EU, GB, JP, CA, AU, CH, NZ, SE, NO, CN, IN, BR, MX, KR, ZA, TRINTR, the policy rate.
GB, JP, DE, FR, IT, ES, CA, AU, KR, SE, NOUR, the unemployment rate.
EU, DE, FR, IT, ESHICP, the harmonised index of consumer prices, and its inflation rates IRYY, IRMM, HIRYY and HIRMM.

A field with no source here reads na.

A release lands on its release day, not its month

TradingView shows a monthly figure from the first session after its month, at today's revised value. Here each value lands when it was published, at the value it had then. So a CPI line here sits about two weeks to the right of TradingView's, and a backtest can't trade on a number before its release.

A value whose release date isn't known is read at a lag that errs late, so it can never show early. A leak-safe run reads such a value as na.

Company financials ​

request.financial(symbol, financial_id, period) reads a US company's filings. period is "FQ", "FY" or "TTM"; "FH" reads na, since US companies don't report half years. These ids have a source:

Statementfinancial_id
IncomeTOTAL_REVENUE, COST_OF_GOODS, GROSS_PROFIT, OPER_INCOME, NET_INCOME, SELL_GEN_ADMIN_EXP_TOTAL, RESEARCH_AND_DEV, EARNINGS_PER_SHARE_BASIC, EARNINGS_PER_SHARE_DILUTED
Balance sheetTOTAL_ASSETS, TOTAL_CURRENT_ASSETS, CASH_N_EQUIVALENTS, TOTAL_INVENTORY, ACCOUNTS_RECEIVABLES_NET, TOTAL_LIABILITIES, TOTAL_CURRENT_LIABILITIES, LONG_TERM_DEBT, SHORT_TERM_DEBT, TOTAL_EQUITY, TOTAL_SHARES_OUTSTANDING
Cash flowCASH_F_OPERATING_ACTIVITIES, CAPITAL_EXPENDITURES, TOTAL_CASH_DIVIDENDS_PAID

Any other id reads na, with a warning. A quarter lands on the day it was filed. TradingView shows it from the quarter's last session, weeks before anyone could read it, so here it sits later on purpose.

Funding rates ​

request.funding(coin, venue, series) reads a perpetual future's funding rate, an AmenoScript addition:

ameno
indicator("BTC funding")
// Annualised, in percent; series = "rate" reads each settlement's rate
float apr = request.funding("BTC", "binance")
plot(apr, "BTC funding, APR (%)")
hline(0)

venue is "binance", "bybit" or "hyperliquid", and Binance when you name none or another. series is "apr" by default, the rate annualised in percent, or "rate" for each settlement's own rate. Each settlement is read on the bar that closes after it.

Other dated series ​

Many more series ride the same rules, each with its publication time on every row. Read them with request.security like any symbol. The symbol search and the Data Catalogue, the terminal's list of every series it holds, give each one's exact name.

PrefixWhat it holds
FRED:Federal Reserve economic data, at first prints where the release dates are known.
RATE:Policy rates, Treasury yields and money-market rates.
COT:The CFTC's weekly Commitments of Traders, by group.
PERP:Perpetual futures' open interest, long/short ratios and premiums.
VOL:Volatility indices, VIX futures and option-chain readings.
LIQ:Stablecoin supply, on-chain measures and the crypto Fear and Greed index.
CURVE:Futures curves: each contract month, and the roll yield.
CAL:Calendar events, such as FOMC decision days.
SEC:Company filings, as request.financial reads them.
DIV:, SPLIT:, EARN:, ECON:What the requests above read.
CMC:CoinMarketCap's daily history. See Universes.
CSV:A file of your own, as below.

A file of your own ​

A CSV file in the terminal's CSV folder reads as CSV:<name>. The name is the file's, in lower case and without .csv, with any character other than a letter, digit, dot, dash or underscore turned into a dash. The file needs a date column and either a value column or open, high, low and close, with volume optional:

text
# name: Baltic Dry Index
# lag: 3d
date,value
2024-01-02,1234.5
2024-01-03,1240.0

A row is public at the end of its date unless the file says otherwise. A # lag: line, in s, m, h or d, makes every row public that long after its date or time, and a public_at column sets the time row by row. Each row lands on the first bar that closes at or after its public time. A file whose public times can't be read gives no rows at all, since a guess could show a value early.

Known time ​

Under gaps_on, a feed that failed and a day with no new value both read na. Under gaps_off, a value 40 days old reads like a fresh one. These AmenoScript reads tell them apart:

ameno
indicator("Is the CPI fresh?")
// na once the print is more than 45 days old, instead of repeating it
const string CPI = "FRED:CPIAUCSL"
float cpi = request.security(CPI, "1M", close, max_age = 45 * 86400)
int age = request.age(CPI, "1M")
bool fresh = request.status(CPI, "1M") == "ok"
plot(cpi, "CPI")
plot(age / 86400, "Days since the print")
plot(fresh ? 1 : 0, "On time")
ReadGives
max_age = seconds on request.securityna once the print it would show was public more than that long before this bar's close, until the next print.
request.age(symbol, timeframe)Seconds from when the value this bar reads became public to this bar's close, as an int. na before the first print.
request.status(symbol, timeframe)"ok": there's a print to read. "late": the next print is overdue. "waiting": loaded, nothing public yet. "failed": nothing loaded.
request.quality(symbol, timeframe)The Data Catalogue's flag on the value this bar reads: "bad", "gap", "jump" or "partial", or "" when it's clean.
syminfo.unitWhat the series measures, such as "%" or "USD".
syminfo.cadenceHow often it prints, such as "1M". Empty for a market, whose bars are the size you ask for.
syminfo.lagSeconds from the end of a value's period to when it is usually public.

"late" goes by the series' rhythm: 40 days on a monthly macro series, 6 days on a stock, 2.5 bars on a coin. A symbol worked out on each bar, which the chart can't read in your text, reads "failed" until the chart has fetched it and run the script again. None of these can read ahead: each looks at the print this bar can already read, and max_age only takes values away.

See also ​

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