StructureX

Home › Guides › Platforms

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.

Beginner guide · 8-minute read · Updated 2026-10-21

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:

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()

PartWhat it meansIn the example
symbolWhich chart to asksyminfo.tickerid (this one)
timeframeWhich timeframetf ("D" = daily)
expressionWhat to work out thereta.sma(close, 20)
lookaheadWhether past candles may see aheadbarmerge.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:

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)

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

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

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 anytime

Or 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:

Follow on XFollow on TradingView