request.security() syntax and parameters in Pine Script v6
The request.security() function is Pine Scripts primary mechanism for intermarket analysis and multi-timeframe (MTF) trading logic. Whether pulling SPY index returns onto an individual stock chart, comparing gold against the US dollar, or displaying a 4-hour EMA on a 5-minute execution chart, request.security handles the data alignment between differing resolution feeds.
| Parameter | Type | Default | Function / Behavior |
|---|---|---|---|
| symbol | simple string | Required | Ticker ID (e.g. syminfo.tickerid or "INDEX:SPX") |
| timeframe | simple string | Required | Timeframe string: "1", "5", "60", "240", "D", "W", "M" |
| expression | any type/tuple | Required | The calculation or series to evaluate (e.g. close, ta.ema(close, 50), [high, low]) |
| gaps | barmerge.gaps_* | barmerge.gaps_off | barmerge.gaps_off carries previous value forward; gaps_on returns na when no bar exists |
| lookahead | barmerge.lookahead_* | barmerge.lookahead_off | Controls whether historical calculations access future completed bars prematurely |
| ignore_invalid_symbol | simple bool | false | If true, returns na instead of halting execution when a symbol is invalid |