TradingCharts

Other Timeframes and Data

The request.* family lets a script reach outside its own symbol or timeframe: a higher-timeframe RSI on an intraday chart, a benchmark index's return, a stock's dividend / earnings…

request.security(symbol, timeframe, expression, gaps?, lookahead?, ignore_invalid_symbol?, currency?)

dClose = request.security(syminfo.tickerid, "D", close)
plot(dClose, "Daily close on intraday chart", style=plot.style_stepline)
Parameter Type / values Default Meaning
symbol string required "" → current chart symbol; otherwise a ticker or secmaster key.
timeframe string required "" → the chart's own; or "5", "D", …
expression series / tuple required Evaluated on the requested series' bars.
gaps barmerge.gaps_on / barmerge.gaps_off gaps_off _on returns na where no new HTF bar exists; _off carries the last value forward.
lookahead barmerge.lookahead_off / barmerge.lookahead_on lookahead_off _on lets the chart bar see the HTF bar's close before it has formed — repaints, used only intentionally.
ignore_invalid_symbol const bool false true returns na when the symbol has no data instead of raising.
currency const string ignored Accepted for compatibility; prices stay in the symbol's native currency.

Where the expression runs

The expression is compiled into a small program that executes on the requested series' bars, not on the chart's. That includes any script variable it refers to: a variable defined earlier in your script and used inside the expression is re-evaluated in the requested context (with the requested symbol's close, high, … and syminfo.* / timeframe.* of the requested series), so

len   = input.int(14)
basis = ta.sma(close, len)                                   // chart context
dBasis = request.security(syminfo.tickerid, "D", basis)      // ta.sma over DAILY closes — not the chart's basis sampled daily

returns the daily SMA, exactly as the reference platform does. Only values that cannot be replayed there (drawings, log.*, strategy.*, alert*) are rejected inside an expression. User functions are allowed, and a request.security nested inside another request's expression is allowed too (the inner one runs in the outer request's context).

Inside the requested context syminfo.*, timeframe.* and bar_index describe the requested series, and barstate.* the requested bar.

Tuple returns

Return more than one series from a single request.security call:

[dOpen, dHigh, dLow, dClose] = request.security(syminfo.tickerid, "D", [open, high, low, close])

Dynamic requests

The symbol and timeframe arguments can be series values (an input.symbol + input.timeframe pair, say). The declaration must either leave dynamic_requests at its default true or set it explicitly:

sym = input.symbol("NSE:NIFTY", "Symbol")
tf  = input.timeframe("D",      "Timeframe")
val = request.security(sym, tf, close)

The executor fetches each unique (symbol, timeframe) pair once per computation (up to 512 pairs per script). What is supported: a symbol or timeframe that is constant for the run (inputs, constants) or a loop variable over a fixed list of symbols. Not supported: a timeframe that changes from bar to bar (rejected at compile time), and symbol chains whose value depends on another request's data deeper than a few levels.

request.security_lower_tf(symbol, timeframe, expression)

Lower-timeframe aggregation: for each chart bar, the expression is evaluated on every lower-timeframe bar that falls inside it, and the results are returned as an array:

m1Closes = request.security_lower_tf(syminfo.tickerid, "1", close)
mean     = m1Closes.avg()
plot(mean, "Mean 1-minute close within this bar")
  • The returned array is ordered intrabar-first-to-last.
  • Empty-array semantics: when the requested timeframe is not lower than the chart's, every bar returns []. The executor treats "no data" as [] rather than raising.
  • Tuple form:
[closes, volumes] = request.security_lower_tf(syminfo.tickerid, "1", [close, volume])

request.dividends(ticker, field, gaps?, lookahead?, currency?)

Dividend series.

dps = request.dividends(syminfo.tickerid, dividends.gross)
plot(dps, "Dividend per share")

field: dividends.gross, dividends.net, dividends.payout_ratio. Any other member is a compile error (request.dividends field must be one of …). payout_ratio is accepted but is always na — the payout ratio is not in the source data.

Dividends land on the ex-date bar.

request.splits(ticker, field, …)

Split and bonus events.

splitRatio = request.splits(syminfo.tickerid, splits.numerator)

field: splits.numerator, splits.denominator (a 1:2 bonus → 1 / 2; divide for the ratio).

request.earnings(ticker, field, …)

Reported earnings.

eps = request.earnings(syminfo.tickerid, earnings.actual)

field: earnings.actual, earnings.estimate, earnings.standardized (quarterly EPS). estimate is accepted but is always na — analyst estimates are not in the source data.

Earnings land on the report date.

request.financial(ticker, financial_id, period)

Fundamentals. period is "FQ" (fiscal quarter), "FH" (half year), "FY" (fiscal year), "TTM" (trailing twelve months) or "D" (daily series such as market cap). financial_id is a reference identifier like "TOTAL_REVENUE", "NET_INCOME", "TOTAL_ASSETS", "CASH_AND_SHORT_TERM_INVESTMENTS", "TOTAL_LIABILITIES".

rev  = request.financial(syminfo.tickerid, "TOTAL_REVENUE", "FY")
yoy  = (rev - rev[1]) / rev[1]

Values land on the bar that opens the next fiscal period (the point when the figure first becomes known).

An id that is not available for a given symbol injects a script warning (request.financial("…"): no data — …) into the Logs panel instead of returning na silently.

request.economic(country, series, …)

Compiles with the warning request.economic has no data source yet — the series is na; every bar returns na. request.quandl, request.seed, request.currency_rate and request.footprint are not available (Unknown function).

Repainting

  • lookahead = barmerge.lookahead_off (default) uses the HTF bar's confirmed close. The confirmed value becomes visible on the last chart bar inside the HTF bar (the chart bar whose successor opens at or after the next HTF bar — on a weekly request that is Friday's last bar, not Monday's first), and every earlier chart bar inside that HTF bar still reads the previous HTF value. The live chart bar reads the HTF bar's current forming value. This is the safe default.
  • lookahead = barmerge.lookahead_on reads the forming HTF close on historical bars too — the HTF value has not actually formed yet at that chart-bar time. Signals derived from lookahead_on will repaint. Use only when the forward peek is intentional.

See Repainting.

See also