Pine Script request.security(): show bigger-timeframe data on any chart
We check the bigger chart before every trade. request.security() brings that bigger chart onto the one you're looking at. One setting decides if it tells the truth about the past.
What request.security() does
request.security() asks TradingView for data from somewhere else. Another Timeframe, or even another symbol.
The most common use: showing bigger-timeframe data on a smaller chart. For example, the daily average on a 15-minute chart.
Why does that matter? Our method checks the bigger chart first and trades with it. See multiple timeframe analysis. With request.security(), the bigger picture sits on the chart you trade from.
New to Pine Script? Start with Pine Script for beginners.
A first example
This draws the daily 20-candle average on any smaller chart:
//@version=6
indicator("Bigger-timeframe average", overlay=true)
tf = input.timeframe("D", "Bigger timeframe")
bigAvg = request.security(syminfo.tickerid, tf, ta.sma(close, 20), lookahead=barmerge.lookahead_off)
plot(bigAvg, "Bigger average", color=color.purple, linewidth=2)
Line by line:
- Line 1 says this is Pine Script version 6.
- Line 2 names the indicator and puts it on the price chart.
- Line 3 makes the bigger timeframe a setting. "D" means daily. The setting shows a timeframe menu. See Pine Script inputs.
- Line 4 does the work. In plain words: "for this same symbol, on the daily chart, work out the 20-candle average, and bring it here."
- Line 5 draws it as a thicker purple line.
On a 15-minute chart, the line looks like steps. It holds one value for a whole day, then jumps. That's right: one daily candle covers many 15-minute candles.
The 4 parts of request.security()
| Part | What it means | In the example |
|---|---|---|
| symbol | Which chart to ask | syminfo.tickerid (this one) |
| timeframe | Which timeframe | tf ("D" = daily) |
| expression | What to work out there | ta.sma(close, 20) |
| lookahead | Whether past candles may see ahead | barmerge.lookahead_off |
syminfo.tickerid means "the symbol on this chart, with its exchange". It's the safe way to ask for the same symbol.
The expression is worked out on the other timeframe. So ta.sma(close, 20) here means 20 daily candles, not 20 small ones.
What lookahead means
barmerge.lookahead_off is the default. It's also the safe choice for past candles.
With it off, each past 15-minute candle only gets the daily value that was known by then. You never see the day's final close before the day is over.
With barmerge.lookahead_on on its own, past candles can see the day's final value early. The chart looks brilliant in hindsight. It's using the future. That's look-ahead, and it makes any test you run on it wrong.
Never use lookahead_on with a plain value. It lets past candles peek at the future. The one safe use is the pattern further down this page.
The repainting catch
There's still one catch, even with lookahead off.
On past candles, you see each day's value only once that day had finished. But on the live chart, today isn't finished. So the line follows today's price as it moves, all day.
Then, when you reload the chart later, history shows the finished value instead. What you saw live and what history shows don't match. That's called repainting.
Why care? Say you only trade when price is above the daily average. Live, the line might put you "above" at 11 am. History might later say you were below. Your notes and the chart won't agree.
The safe pattern: finished candles only
TradingView's own Pine Script manual shows a pattern that only uses finished bigger candles:
bigAvgDone = request.security(syminfo.tickerid, tf, ta.sma(close, 20)[1], lookahead=barmerge.lookahead_on)
What changed:
- [1] at the end of the expression means "one daily candle back". That's the last finished day.
- lookahead_on lines that finished value up with the start of the new day, instead of a day late.
Together, they give a value that never changes once it's drawn, live or in history. The price: it's always one bigger candle behind. For checking the bigger trend, that's usually fine.
The 2 parts belong together. [1] with lookahead_on is safe. lookahead_on without [1] is not.
Using it to check the bigger trend
Here's a simple bigger-chart check. It shades the background when the last finished daily close was above the last finished daily average:
bigClose = request.security(syminfo.tickerid, tf, close[1], lookahead=barmerge.lookahead_on)
bigUp = bigClose > bigAvgDone
bgcolor(bigUp ? color.new(color.green, 90) : na)
- Line 1 gets yesterday's finished daily close, the safe way.
- Line 2 is true when that close was above the finished daily average.
- Line 3 shades the background a faint green when it's true, and leaves it clear when not. 90 means 90% see-through.
An average is one simple way to read direction. A more direct one: higher highs and higher lows. The free StructureX chart tool marks those turning points for you.
Pick a bigger timeframe that's really bigger. On a daily chart, asking for daily data adds nothing. A common pairing is about 4 to 6 times bigger: 15-minute with 1-hour, 1-hour with 4-hour or daily.
A few more rules
- Smaller timeframes need a different tool. To look inside the candles of your chart, Pine Script has request.security_lower_tf().
- There's a limit on how many request calls one script can make. Keep them few.
- Other symbols work too. Replace syminfo.tickerid with a symbol in quotes. Check the exact name in TradingView's symbol search.
Learning from a real script
Our course includes the full source code of the StructureX chart tool, to learn from and customize, for example adding your own bigger-timeframe check. It's source code, not a ready-made trading bot.
Common mistakes
- lookahead_on without [1]. The past peeks at the future. Tests built on it are wrong.
- Trusting the live line as final. With lookahead off, today's value moves until the day closes.
- Asking for a smaller timeframe. Use request.security_lower_tf() instead.
- Forgetting the expression runs on the other timeframe. 20 means 20 bigger candles.
Questions
What does request.security do in Pine Script?
It gets data from another timeframe or symbol and brings it onto your chart. The most common use is showing daily or hourly values on a smaller chart.
Does request.security repaint?
It can. With lookahead off, the live bigger-timeframe value moves until that bigger candle closes. Using the expression with [1] and lookahead on gives values that don't change.
What is barmerge.lookahead_on?
It lets past candles line up with bigger-timeframe values early. Used alone, it leaks future data into history. It's only safe with the expression offset by [1].
How do I show the daily chart on an intraday chart in Pine Script?
Call request.security(syminfo.tickerid, "D", your value) and plot the result. Use the [1] and lookahead on pattern if you need values that never change.
Want the next step? We'll walk you through it.
Four free lessons by email, one every few days — each with a 10-minute exercise on a real chart.
Send Me the Free Lessons 4 short emails · No spam · Unsubscribe anytimeOr see the whole method, step by step:
See What’s Inside the Course Try everything free first. Decide when you're ready. · Open the free chart tool (works in the TradingView phone app)One chart idea a day, in plain English. Follow along: