Skip to content

request

Functions

currency_rate

navi
request.currency_rate(
    from: series string,
    to: series string,
    ignore_invalid_currency: series bool = false
  ): series float

Returns 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

NameTypeDefaultDescription
fromseries stringSource currency code, e.g. "USD" or currency.USD.
toseries stringTarget currency code, e.g. "EUR" or currency.EUR.
ignore_invalid_currencyseries boolfalseIf true, returns na when the conversion rate cannot be determined instead of raising a runtime error.

Returns: series float


data

navi
request.data(
    function: simple string,
    args: series Map<string, any> = na,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off
  ): series float

Calls 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

NameTypeDefaultDescription
functionsimple stringName of the DataProvider function to call.
argsseries Map<string, any>naOptional Map&lt;string, any&gt; of typed parameters passed to the function.
gapssimple BarmergeGapsBarmergeGaps.OffBar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On).
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffControls lookahead semantics for backtesting correctness.

Returns: series float


dividends

navi
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 float

Queries the engine's DataProvider for a dividend value at the current bar. Supports lookahead control. Returns na when no data is available.

Parameters

NameTypeDefaultDescription
tickerseries stringsyminfo.tickeridTicker whose dividends to query; defaults to the chart symbol.
fieldseries DividendsFieldDividendsField.GrossWhich dividend figure to retrieve: DividendsField.Gross (before withholding) or DividendsField.Net (after withholding).
gapssimple BarmergeGapsBarmergeGaps.OffBar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On).
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffControls whether the value appears on the event bar itself (lookahead_on) or only after confirmation (lookahead_off).
ignore_invalid_symbolinput boolfalseWhen true, unrecognised tickers silently yield na.
currencyseries stringsyminfo.currencyCurrency code for value conversion.

Returns: series float


earnings

navi
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 float

Queries 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

NameTypeDefaultDescription
tickerseries stringsyminfo.tickeridTicker whose earnings to query; defaults to the chart symbol.
fieldseries EarningsFieldEarningsField.ActualWhich earnings figure to retrieve: EarningsField.Actual, EarningsField.Estimate, or EarningsField.Standardized.
gapssimple BarmergeGapsBarmergeGaps.OffBar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On).
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffWhen BarmergeLookahead.Off (default), a data point becomes visible only after a subsequent point confirms it, preventing future-leak in backtests.
ignore_invalid_symbolinput boolfalseWhen true, unrecognised tickers silently yield na.
currencyseries stringsyminfo.currencyCurrency code for value conversion.

Returns: series float


economic

navi
request.economic(
    country_code: series string,
    field: series string,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    ignore_invalid_symbol: input bool = false
  ): series float

Queries the engine's DataProvider for a macroeconomic indicator value at the current bar. Returns na when no data is available.

Parameters

NameTypeDefaultDescription
country_codeseries stringISO 3166-1 alpha-2 country code, e.g. "US", "CN".
fieldseries stringIdentifier of the economic indicator to retrieve.
gapssimple BarmergeGapsBarmergeGaps.OffBar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On).
ignore_invalid_symbolinput boolfalseWhen true, unrecognised identifiers silently yield na.

Returns: series float


financial

navi
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 float

Queries 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

NameTypeDefaultDescription
symbolseries stringSymbol whose financials to query.
financial_idseries stringIdentifier of the financial metric to retrieve.
periodseries stringReporting period: "FQ" (quarterly) or "FY" (annual).
gapssimple BarmergeGapsBarmergeGaps.OffControls 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_symbolinput boolfalseWhen true, unrecognised symbols silently yield na.
currencyseries stringsyminfo.currencyCurrency code for value conversion; defaults to the chart symbol's currency.

Returns: series float


security

navi
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 T

Evaluates expression on another symbol or timeframe and maps the result onto the current chart.

Parameters

NameTypeDefaultDescription
symbolseries stringSymbol to request.
timeframeseries stringRequested timeframe string, such as "D", "60", or "W".
expressioninstructions<T>Expression to execute in the requested context.
gapssimple BarmergeGapsBarmergeGaps.OffHow missing requested bars are mapped back onto the current chart.
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffWhether requested values may look ahead on historical bars.
ignore_invalid_symbolinput boolfalseIf true, returns na for unknown symbols instead of raising an error.
currencyseries stringnaOptional currency used for price conversion.
calc_bars_countsimple intnaOptional positive limit for the recent history window loaded for the request stream.

Returns: series T

Examples

navi
// 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");
navi
// 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

navi
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

NameTypeDefaultDescription
symbolseries stringSymbol to request.
timeframeseries stringLower or equal timeframe string, such as "1" or "5".
expressioninstructions<T>Expression to evaluate for each lower-timeframe bar.
ignore_invalid_symbolinput boolfalseIf true, returns na for unknown symbols instead of raising an error.
currencyseries stringnaOptional currency used for price conversion.
ignore_invalid_timeframeinput boolfalseIf true, returns na when the requested timeframe is not lower than the chart timeframe.
calc_bars_countsimple intnaOptional positive limit for the recent history window loaded for the request stream.

Returns: series Array<T>


splits

navi
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 float

Queries the engine's DataProvider for a stock-split value at the current bar. Supports lookahead control. Returns na when no data is available.

Parameters

NameTypeDefaultDescription
tickerseries stringsyminfo.tickeridTicker whose splits to query; defaults to the chart symbol.
fieldseries SplitsFieldSplitsField.DenominatorWhich component of the split ratio to retrieve: SplitsField.Numerator or SplitsField.Denominator.
gapssimple BarmergeGapsBarmergeGaps.OffBar-mapping mode (see BarmergeGaps.Off / BarmergeGaps.On).
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffControls whether the value appears on the event bar itself (lookahead_on) or only after confirmation (lookahead_off).
ignore_invalid_symbolinput boolfalseWhen true, unrecognised tickers silently yield na.

Returns: series float

Released under the MIT License.