request.security() is one of Pine Script's most powerful functions, allowing traders to fetch data from different symbols and timeframes while working on their current chart. Whether you're comparing multiple assets or analyzing higher timeframes, mastering this function can significantly enhance your trading strategy.
What Does request.security() Do?
request.security() retrieves data from a specified symbol or timeframe and integrates it into your current script. For example:
- Multi-asset analysis: View Bitcoin's performance while analyzing Apple stock.
- Multi-timeframe analysis: Access daily closing prices on a 5-minute chart.
Simply put, it bridges data gaps without switching charts.
How to Use request.security()
The syntax follows this structure:
data = request.security(symbol, timeframe, expression)Parameters Explained:
| Parameter | Description | Example |
|---|---|---|
symbol | The ticker symbol (e.g., "NASDAQ:AAPL", "BINANCE:BTCUSDT") | "NYSE:TSLA" |
timeframe | The desired timeframe (e.g., "1D", "4H", "15M") | "1W" |
expression | The data or calculation to fetch (e.g., close, ta.ema(close, 20)) | ta.rsi(close, 14) |
Example Use Cases
Higher Timeframe Trends:
dailyMA = request.security("NASDAQ:AAPL", "1D", ta.sma(close, 50)) plot(dailyMA, title="50-Day Daily MA")Displays a 50-day moving average from daily data on an intraday chart.
Sector Correlation:
goldPrice = request.security("XAUUSD", "1H", close) silverPrice = request.security("XAGUSD", "1H", close)Compares hourly gold and silver prices.
Market-Wide Signals:
btcDominance = request.security("CRYPTOCAP:BTC.D", "4H", close)Monitors Bitcoin dominance across crypto markets.
Common Pitfalls & Solutions
👉 Limit Overload: TradingView caps scripts at 40 request.security() calls. Prioritize essential data.
👉 Timeframe Misalignment: Daily data repeats on minute charts—aggregate carefully.
👉 Performance Lag: Excessive requests slow execution. Optimize with fewer calls or lightweight expressions.
👉 Real-Time Glitches: Test scripts on historical and live data to avoid inconsistencies.
FAQ
Q: Can I fetch custom indicators from another symbol?
A: Yes! Pass any valid Pine Script expression:
rsiCustom = request.security("EURUSD", "1H", ta.rsi(close, 14))Q: Why does my script fail to compile?
A: Check for:
- Misspelled symbols (
"BINANCE:BTCUSDT"vs."BINANCE:BTC-USD"). - Invalid timeframes (use "1D", not "1DAY").
Q: How do I avoid hitting the 40-request limit?
A: Combine requests using arrays or functions, or focus on critical assets.
Pro Tip: Simplify with Pine Script Tools
Manually coding multi-symbol scripts can be tedious. Tools like Pineify streamline the process with drag-and-drop builders—ideal for rapid prototyping.
Final Thoughts
request.security() unlocks advanced multi-asset/ timeframe analysis in Pine Script. Start small, validate outputs, and gradually scale complexity.
👉 Master Pine Script with these advanced techniques for sharper trading insights!