Requests an expression evaluated on another symbol or timeframe and returns the result on the chart's bars.
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
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
| Name | Type | Default | Description |
|---|---|---|---|
| symbol | series string | required | The symbol to read. syminfo.tickerid is the chart's own symbol. |
| timeframe | series string | required | The timeframe to evaluate on, such as "60", "D" or "W". An empty string means the chart's timeframe. |
| expression | variable, function, object, array, matrix, or map of series int/ | required | What to calculate there: a series, a function call, or a tuple of them. |
| gaps | simple barmerge_gaps | barmerge. | barmerge.gaps_on leaves na between updates of a higher timeframe. barmerge.gaps_off carries the last value forward. |
| lookahead | simple barmerge_lookahead | barmerge. | barmerge.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_symbol | input bool | false | When true, an unknown symbol returns na instead of stopping the script. |
| currency | series string | the symbol's own currency | Currency to convert price values to. |
| calc_bars_count | simple int | 0 | Limits 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
//@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