request.security(syminfo.tickerid, "60", close, lookahead = barmerge.lookahead_on) You can fetch data from any symbol – even FX, crypto, or stocks – and combine them:
request.security(syminfo.tickerid, "60", close, lookahead = barmerge.lookahead_off) ❌ pine script v5 request.security function documentation
📜 Basic Syntax request.security(symbol, timeframe, expression, gaps, lookahead, ignore_invalid_symbol, currency) 🧠 Mental Model Think of it as: "Go to this symbol and timeframe, run this code there, then bring the result back to my current chart." 🧩 Parameters That Matter Most | Parameter | What it does | Cool trick | |-----------|--------------|-------------| | symbol | Ticker ID (e.g., syminfo.tickerid , "AAPL" ) | Use syminfo.tickerid for current symbol | | timeframe | Target TF ( "D" , "240" , "1W" ) | Use "1D" for daily data even on 1min chart | | expression | Any Pine expression (ohlc, custom calc) | Can be a tuple – return multiple values! | | gaps | barmerge.gaps_on or barmerge.gaps_off | Gaps on = show missing bars; off = forward fill | | lookahead | lookahead.on / lookahead.off | 🚨 Critical for repainting behavior | 🎯 Example 1: The Classic Higher-Timeframe Moving Average //@version=6 indicator("HTF MA", overlay=true) htf_ma = request.security(syminfo.tickerid, "1D", ta.sma(close, 20)) plot(htf_ma, color=color.yellow, linewidth=2) Shows the 20-day SMA on an intraday chart. No repainting if lookahead is default ( barmerge.lookahead_off ). 🧠 Example 2: Tuple Magic – Return Multiple Values // Get daily high, low, and volume in one call [dailyHigh, dailyLow, dailyVol] = request.security(syminfo.tickerid, "D", [high, low, volume]) plot(dailyHigh, "Daily High", color.green) plot(dailyLow, "Daily Low", color.red) ⚠️ The Repainting Trap (And How to Avoid It) If you use lookahead = barmerge.lookahead_on , your script can repaint – future bars affect past values. This makes backtests lie. request