request
Functions
currency_rate
request.currency_rate(
from: series string,
to: series string,
ignore_invalid_currency: series bool = false
): series floatReturns the exchange rate for converting one unit of from currency into to currency at the current bar. The rate is provided by the engine's DataProvider.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
from | series string | Source currency code, e.g. "USD" or currency.USD. | |
to | series string | Target currency code, e.g. "EUR" or currency.EUR. | |
ignore_invalid_currency | series bool | false | If true, returns na when the conversion rate cannot be determined instead of raising a runtime error. |
Returns: series float
data
request.data(
function: simple string,
args: series Map<string, any> = na,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
lookahead: simple BarmergeLookahead = BarmergeLookahead.Off
): series floatCalls a user-defined function on the engine's DataProvider and maps the resulting time-series onto the current chart bar. The args map accepts bool, int, float, and string values; other types cause a runtime error. na entries in the map are silently ignored. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
function | simple string | Name of the DataProvider function to call. | |
args | series Map<string, any> | na | Optional Map<string, any> of typed parameters passed to the function. |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Bar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On). |
lookahead | simple BarmergeLookahead | BarmergeLookahead.Off | Controls lookahead semantics for backtesting correctness. |
Returns: series float
dividends
request.dividends(
ticker: series string = syminfo.tickerid,
field: series DividendsField = DividendsField.Gross,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
ignore_invalid_symbol: input bool = false,
currency: series string = syminfo.currency
): series floatQueries the engine's DataProvider for a dividend value at the current bar. Supports lookahead control. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
ticker | series string | syminfo.tickerid | Ticker whose dividends to query; defaults to the chart symbol. |
field | series DividendsField | DividendsField.Gross | Which dividend figure to retrieve: DividendsField.Gross (before withholding) or DividendsField.Net (after withholding). |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Bar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On). |
lookahead | simple BarmergeLookahead | BarmergeLookahead.Off | Controls whether the value appears on the event bar itself (lookahead_on) or only after confirmation (lookahead_off). |
ignore_invalid_symbol | input bool | false | When true, unrecognised tickers silently yield na. |
currency | series string | syminfo.currency | Currency code for value conversion. |
Returns: series float
earnings
request.earnings(
ticker: series string = syminfo.tickerid,
field: series EarningsField = EarningsField.Actual,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
ignore_invalid_symbol: input bool = false,
currency: series string = syminfo.currency
): series floatQueries the engine's DataProvider for an earnings value at the current bar. Supports lookahead control for backtesting correctness. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
ticker | series string | syminfo.tickerid | Ticker whose earnings to query; defaults to the chart symbol. |
field | series EarningsField | EarningsField.Actual | Which earnings figure to retrieve: EarningsField.Actual, EarningsField.Estimate, or EarningsField.Standardized. |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Bar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On). |
lookahead | simple BarmergeLookahead | BarmergeLookahead.Off | When BarmergeLookahead.Off (default), a data point becomes visible only after a subsequent point confirms it, preventing future-leak in backtests. |
ignore_invalid_symbol | input bool | false | When true, unrecognised tickers silently yield na. |
currency | series string | syminfo.currency | Currency code for value conversion. |
Returns: series float
economic
request.economic(
country_code: series string,
field: series string,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
ignore_invalid_symbol: input bool = false
): series floatQueries the engine's DataProvider for a macroeconomic indicator value at the current bar. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
country_code | series string | ISO 3166-1 alpha-2 country code, e.g. "US", "CN". | |
field | series string | Identifier of the economic indicator to retrieve. | |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Bar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On). |
ignore_invalid_symbol | input bool | false | When true, unrecognised identifiers silently yield na. |
Returns: series float
financial
request.financial(
symbol: series string,
financial_id: series string,
period: series string,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
ignore_invalid_symbol: input bool = false,
currency: series string = syminfo.currency
): series floatQueries the engine's DataProvider for a financial metric value at the current bar. The provider streams timestamped data points which the VM maps onto chart bars using the gaps mode. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
symbol | series string | Symbol whose financials to query. | |
financial_id | series string | Identifier of the financial metric to retrieve. | |
period | series string | Reporting period: "FQ" (quarterly) or "FY" (annual). | |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Controls bar mapping when the data point does not align with a chart bar. BarmergeGaps.Off forward-fills; BarmergeGaps.On leaves gaps as na. |
ignore_invalid_symbol | input bool | false | When true, unrecognised symbols silently yield na. |
currency | series string | syminfo.currency | Currency code for value conversion; defaults to the chart symbol's currency. |
Returns: series float
security
request.security(
symbol: series string,
timeframe: series string,
expression: instructions<T>,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
ignore_invalid_symbol: input bool = false,
currency: series string = na,
calc_bars_count: simple int = na
): series TEvaluates expression on another symbol or timeframe and maps the result onto the current chart.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
symbol | series string | Symbol to request. | |
timeframe | series string | Requested timeframe string, such as "D", "60", or "W". | |
expression | instructions<T> | Expression to execute in the requested context. | |
gaps | simple BarmergeGaps | BarmergeGaps.Off | How missing requested bars are mapped back onto the current chart. |
lookahead | simple BarmergeLookahead | BarmergeLookahead.Off | Whether requested values may look ahead on historical bars. |
ignore_invalid_symbol | input bool | false | If true, returns na for unknown symbols instead of raising an error. |
currency | series string | na | Optional currency used for price conversion. |
calc_bars_count | simple int | na | Optional positive limit for the recent history window loaded for the request stream. |
Returns: series T
Examples
// Get daily close of a different symbol on the current intraday chart let
dailyClose = request.security("AAPL", "D", close);
plot(dailyClose, title: "AAPL Daily Close");// Request daily high and low simultaneously using a tuple expression let
(dHigh, dLow) = request.security("AAPL", "D", (high, low));
plot(dHigh, title: "Daily High", color: color.GREEN);
plot(dLow, title: "Daily Low", color: color.RED);security_lower_tf
request.security_lower_tf(
symbol: series string,
timeframe: series string,
expression: instructions<T>,
ignore_invalid_symbol: input bool = false,
currency: series string = na,
ignore_invalid_timeframe: input bool = false,
calc_bars_count: simple int = na
): series Array<T>Evaluates expression on a lower timeframe and returns one array element per lower-timeframe bar inside the current chart bar.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
symbol | series string | Symbol to request. | |
timeframe | series string | Lower or equal timeframe string, such as "1" or "5". | |
expression | instructions<T> | Expression to evaluate for each lower-timeframe bar. | |
ignore_invalid_symbol | input bool | false | If true, returns na for unknown symbols instead of raising an error. |
currency | series string | na | Optional currency used for price conversion. |
ignore_invalid_timeframe | input bool | false | If true, returns na when the requested timeframe is not lower than the chart timeframe. |
calc_bars_count | simple int | na | Optional positive limit for the recent history window loaded for the request stream. |
Returns: series Array<T>
splits
request.splits(
ticker: series string = syminfo.tickerid,
field: series SplitsField = SplitsField.Denominator,
gaps: simple BarmergeGaps = BarmergeGaps.Off,
lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
ignore_invalid_symbol: input bool = false
): series floatQueries the engine's DataProvider for a stock-split value at the current bar. Supports lookahead control. Returns na when no data is available.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
ticker | series string | syminfo.tickerid | Ticker whose splits to query; defaults to the chart symbol. |
field | series SplitsField | SplitsField.Denominator | Which component of the split ratio to retrieve: SplitsField.Numerator or SplitsField.Denominator. |
gaps | simple BarmergeGaps | BarmergeGaps.Off | Bar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On). |
lookahead | simple BarmergeLookahead | BarmergeLookahead.Off | Controls whether the value appears on the event bar itself (lookahead_on) or only after confirmation (lookahead_off). |
ignore_invalid_symbol | input bool | false | When true, unrecognised tickers silently yield na. |
Returns: series float