Understanding Pine Script's request.security() Function: Pull Data from Any Symbol or Timeframe
Ever found yourself staring at a 1-minute chart wondering what the daily trend looks like? Or maybe you're trading SPY but want to keep an eye on what the VIX is doing at the same time? That's exactly where Pine Script's request.security() function becomes your best friend.
I've been using this function for years, and honestly, once you understand how it works, it opens up a whole new world of trading possibilities. Let me walk you through everything you need to know about pulling data from different symbols and timeframes.
What is request.security() and why should you care?
Think of request.security() as your data messenger. While you're looking at one chart, this function can sprint over to any other symbol or timeframe, grab the information you need, and bring it back to display on your current chart.
Here's a real-world example: You're scalping EURUSD on a 5-minute chart, but you want to make sure you're not fighting against the 4-hour trend. Instead of constantly switching between timeframes, request.security() can pull that 4-hour moving average and display it right on your 5-minute chart.
This isn't just convenient – it's powerful. You can build indicators that combine data from multiple sources, create multi-timeframe strategies, and even monitor correlation between different assets.
The basic syntax (don't worry, it's simpler than it looks)
Here's the basic structure:
data = request.security(symbol, timeframe, expression, gaps, lookahead)
Let me break down each parameter:
- symbol: The ticker you want data from (like "NASDAQ:AAPL" or "BINANCE:BTCUSDT")
- timeframe: The timeframe you're requesting ("1D", "4H", "15", etc.)
- expression: What data you want (close, high, low, or custom calculations)
- gaps: How to handle gaps in data (optional)
- lookahead: Whether to use future data (usually set to barmerge.lookahead_off)
Here's a simple example that pulls the daily close price:
//@version=5
indicator("Daily Close on Intraday Chart")
daily_close = request.security(syminfo.tickerid, "1D", close)
plot(daily_close, "Daily Close", color.blue, linewidth=2)
Real-world applications that actually make money
Multi-timeframe trend analysis: This is probably the most popular use case. You're day trading on a 15-minute chart but want to see the daily and weekly trends. Pull those higher timeframe moving averages and overlay them on your intraday chart.
Cross-asset correlation: Trading forex? Pull in the Dollar Index (DXY) to see overall USD strength. Trading individual stocks? Monitor the SPY or sector ETFs to understand broader market sentiment.
Relative strength analysis: Compare your stock against its sector or the overall market. This helps you identify when a stock is outperforming or underperforming its peers.
Volatility context: Pull VIX data onto your stock charts to understand the fear/greed context of your trades.
A practical example: Building a multi-timeframe RSI
Let's build something useful – an indicator that shows RSI from multiple timeframes:
//@version=5
indicator("Multi-Timeframe RSI", shorttitle="MTF RSI")
// Input parameters
rsi_length = input.int(14, "RSI Length")
htf1 = input.timeframe("1H", "Higher Timeframe 1")
htf2 = input.timeframe("4H", "Higher Timeframe 2")
htf3 = input.timeframe("1D", "Higher Timeframe 3")
// Calculate RSI for current timeframe
current_rsi = ta.rsi(close, rsi_length)
// Request RSI from higher timeframes
htf1_rsi = request.security(syminfo.tickerid, htf1, ta.rsi(close, rsi_length))
htf2_rsi = request.security(syminfo.tickerid, htf2, ta.rsi(close, rsi_length))
htf3_rsi = request.security(syminfo.tickerid, htf3, ta.rsi(close, rsi_length))
// Plot everything
plot(current_rsi, "Current TF RSI", color.white)
plot(htf1_rsi, "1H RSI", color.yellow)
plot(htf2_rsi, "4H RSI", color.orange)
plot(htf3_rsi, "Daily RSI", color.red)
// Add overbought/oversold levels
hline(70, "Overbought", color.red, linestyle=hline.style_dashed)
hline(30, "Oversold", color.green, linestyle=hline.style_dashed)
This gives you a complete picture of momentum across multiple timeframes in one indicator.
Important limitations and gotchas
The 40-request limit: TradingView caps you at 40 request.security() calls per script. If you need more, you'll have to get creative with your code structure or break things into multiple indicators.
Performance considerations: Each security request takes processing power. The more you add, the slower your script becomes. I've learned this the hard way after creating indicators that took forever to load.
Timeframe relationships: You can only request data from higher timeframes, not lower ones. If you're on a daily chart, you can't request 1-hour data (well, you can, but it won't work as expected).
Repainting issues: Be careful with real-time data. The current bar of a higher timeframe can change until it closes. If you're building strategies, consider using barmerge.lookahead_off to avoid repainting problems.
Making it easier with visual tools
Here's the truth – while request.security() is powerful, writing all this code manually can be tedious. You have to remember syntax, handle errors, and debug when things go wrong.
This is where visual tools like Pineify really shine. Instead of writing code from scratch, you can build multi-timeframe and multi-symbol indicators using a drag-and-drop interface. It handles all the request.security() complexity behind the scenes while you focus on your trading logic.
For anyone getting started with Pine Script, this approach lets you experiment with different combinations without getting lost in syntax errors. Once you understand how the function works conceptually, diving into the code becomes much easier.
Advanced techniques for power users
Custom expressions: Don't limit yourself to basic OHLC data. You can request complex calculations:
// Request a custom calculation from daily timeframe
daily_volatility = request.security(syminfo.tickerid, "1D", ta.stdev(close, 20))
Using variables: Store your timeframe inputs in variables for cleaner code:
htf = input.timeframe("4H", "Higher Timeframe")
ma_length = input.int(20, "MA Length")
htf_ma = request.security(syminfo.tickerid, htf, ta.sma(close, ma_length))
Handling gaps: Control how missing data is handled:
// Different gap handling options
continuous_data = request.security(symbol, timeframe, close, gaps=barmerge.gaps_off)
with_gaps = request.security(symbol, timeframe, close, gaps=barmerge.gaps_on)
Putting it all together
The request.security() function is genuinely one of the most powerful features in Pine Script. It transforms TradingView from a simple charting platform into a sophisticated analysis tool that can correlate data across multiple dimensions.
Start simple – maybe pull a daily moving average onto your intraday charts. Once you're comfortable with that, experiment with cross-asset analysis or build comprehensive multi-timeframe indicators. The key is understanding that you're essentially asking TradingView to be your data fetcher, grabbing information from anywhere and bringing it to your current view.
Whether you're building automated trading strategies or just want better context for your manual trades, mastering request.security() will significantly upgrade your trading toolkit.
And remember, if you're just getting started or want to experiment without the coding headaches, tools like Pineify's visual indicator builder can help you explore these concepts before diving into the code. Sometimes the best way to learn is by seeing what's possible first, then understanding how it works under the hood.
