Skip to content
Algo Trade Analytics Docs

request.security() - Pine Script Function

Requests the result of an expression from a specified context (symbol and timeframe).

request.security(symbol, timeframe, expression, gaps, lookahead, ignore_invalid_symbol, currency, calc_bars_count) → series <type>
NameTypeDescription
symbolseries stringSymbol or ticker identifier of the requested data. Use an empty string or syminfo.tickerid to request data using the chart’s symbol. To retrieve data with additional modifiers (extended sessions
dividendadjustments
non-standardchart types like Heikin Ashi and Renko
etc.)
createa custom ticker ID for the request using the functions in the ticker.* namespace.

A result determined by expression.

  • Scripts using this function might calculate differently on historical and realtime bars, leading to repainting.
//@version=6
indicator("Advanced `request.security()` calls")// This calculates a 10-period moving average on the active chart.sma = ta.sma(close, 10)// This sends the `sma` calculation
for execution in the context of the "AAPL" symbol at a "240" (4 hours)
timeframe.aaplSma = request.security("AAPL", "240", sma)
plot(aaplSma)// To avoid differences on historical and realtime bars, you can use this technique, which only returns a value from the higher timeframe on the bar after it completes:indexHighTF = barstate.isrealtime ? 1 : 0indexCurrTF = barstate.isrealtime ? 0 : 1nonRepaintingClose = request.security(syminfo.tickerid, "1D", close[indexHighTF])[indexCurrTF]
plot(nonRepaintingClose, "Non-repainting close")// Returns the 1H close of "AAPL", extended session included. The value is dividend-adjusted.extendedTicker = ticker.modify("NASDAQ:AAPL", session = session.extended, adjustment = adjustment.dividends)
aaplExtAdj = request.security(extendedTicker, "60", close)
plot(aaplExtAdj)// Returns the result of a user-defined function.// The `max` variable is mutable, but we can pass it to `request.security()` because it is wrapped in a function.allTimeHigh(source) =>
var max = source max := math.max(max, source)
allTimeHigh1D = request.security(syminfo.tickerid, "1D", allTimeHigh(high))// By using a tuple `expression`, we obtain several values with only one `request.security()` call.[open1D, high1D, low1D, close1D, ema1D] = request.security(syminfo.tickerid, "1D", [open, high, low, close, ta.ema(close, 10)])
plotcandle(open1D, high1D, low1D, close1D)
plot(ema1D)// Returns an array containing the OHLC values of the chart's symbol from the 1D timeframe.ohlcArray = request.security(syminfo.tickerid, "1D", array.from(open, high, low, close))
plotcandle(array.get(ohlcArray, 0), array.get(ohlcArray, 1), array.get(ohlcArray, 2), array.get(ohlcArray, 3))