Sidechair

request.security()

Browse the reference

Requests an expression evaluated on another symbol or timeframe and returns the result on the chart's bars.

Try it in the editor

request.security runs an expression in the context of a symbol and timeframe you choose, then hands the value back to your script on the current chart. The expression can be a price, an indicator call or a tuple of them.

Use it for multi-timeframe work, such as reading the daily close on a 5-minute chart, and for comparing the chart symbol with another one. Each chart bar sees the value from the requested bar that covers it.

Syntax

Pine Script
request.security(symbol: series string, timeframe: series string, expression: variable, function, object, array, matrix, or map of series int/float/bool/string/color/enum, or a tuple of these, gaps: simple barmerge_gaps (optional), lookahead: simple barmerge_lookahead (optional), ignore_invalid_symbol: input bool (optional), currency: series string (optional), calc_bars_count: simple int (optional)) -> series <type>

Arguments

NameTypeDefaultDescription
symbolseries stringrequiredThe symbol to read. syminfo.tickerid is the chart's own symbol.
timeframeseries stringrequiredThe timeframe to evaluate on, such as "60", "D" or "W". An empty string means the chart's timeframe.
expressionvariable, function, object, array, matrix, or map of series int/float/bool/string/color/enum, or a tuple of theserequiredWhat to calculate there: a series, a function call, or a tuple of them.
gapssimple barmerge_gapsbarmerge.gaps_offbarmerge.gaps_on leaves na between updates of a higher timeframe. barmerge.gaps_off carries the last value forward.
lookaheadsimple barmerge_lookaheadbarmerge.lookahead_offbarmerge.lookahead_off returns only finished data. barmerge.lookahead_on gives a historical bar the value its higher-timeframe bar ends with, before that end has happened.
ignore_invalid_symbolinput boolfalseWhen true, an unknown symbol returns na instead of stopping the script.
currencyseries stringthe symbol's own currencyCurrency to convert price values to.
calc_bars_countsimple int0Limits how many bars of the requested context are calculated. 0 means all.

Returns

series <type>: the expression's value from the requested context, aligned to the chart's bars.

Remarks

  • With lookahead off, a bar on a lower timeframe than the request shows the previous completed period's value until its own period closes. With lookahead on, history shows the period's final value on every bar of it, which a live chart cannot know. Scripts that use lookahead on without an offset repaint.
  • To read the previous completed higher-timeframe bar without repainting, request expression[1] with lookahead on.
  • On Sidechair: only the chart's own symbol on its own timeframe or a higher one is evaluated. Other symbols and lower timeframes give na with a warning, and gaps, ignore_invalid_symbol, currency and calc_bars_count have no effect.

Example

Pine ScriptHourly close on a 5-minute chartOpen in editor
//@version=6
indicator("Higher timeframe close", overlay = true)
tf = input.timeframe("60", "Timeframe")
htfClose = request.security(syminfo.tickerid, tf, close)
htfEma = request.security(syminfo.tickerid, tf, ta.ema(close, 20))
plot(htfClose, "HTF close", color = color.orange, style = plot.style_stepline)
plot(htfEma, "HTF EMA", color = color.blue, linewidth = 2)

See also

Runs on Sidechair in part