Sooner or later, almost every TradingView trader wants to pull data from a higher timeframe into the current chart — for example, watching the daily trend while trading the 15-minute chart. In Pine Script v6, the function that does this is request.security(). It is powerful, but it is also the biggest source of repaint (signals that change after the candle closes). This guide shows the correct syntax, a ready-to-use example and the pattern that avoids repainting reliably.

Ready to step away from the chart and execute in an automated way?

See automation with a Python API →

What request.security does

The function fetches the value of an expression from another symbol or another timeframe and brings it into the chart where your script is running. With it you build multi-timeframe (MTF) indicators: for example, displaying the 1-hour chart’s EMA while you analyze the 5-minute chart.

Golden rule: requesting a timeframe higher than the chart’s is safe and common. Requesting a lower timeframe brings intrabar data and opens the door to biases that are hard to control — avoid it unless you know exactly what you are doing.

Syntax

request.security(symbol, timeframe, expression, gaps, lookahead) // symbol -> syminfo.tickerid (the current asset) or “BINANCE:BTCUSDT” // timeframe -> “60”, “D”, “W” … (string) // expression -> what to calculate, e.g.: close, ta.ema(close, 50) // gaps -> barmerge.gaps_off (default) or barmerge.gaps_on // lookahead -> barmerge.lookahead_off (default) or _on

The repaint problem

Repainting happens when the higher-timeframe value has not closed yet. While the 1-hour candle is still forming, its value changes with every tick; the historical chart, however, is drawn with the candle already closed. The result: the backtest shows a signal that, live, only appeared at the end of the hour — an edge that does not exist in practice.

The correct pattern (no repaint)

The time-tested solution is to request the value of the already closed bar using the [1] index together with lookahead_on. Combined, they always deliver the last confirmed value of the higher timeframe:

//@version=6 indicator(“EMA Multi-Timeframe sem Repaint”, overlay=true) tfSuperior = input.timeframe(“60”, “Timeframe superior”) comprimento = input.int(50, “Período da EMA”) // function with the expression calculated on the higher TF f_ema() => ta.ema(close, comprimento) // [1] + lookahead_on = value of the ALREADY closed bar (no repaint) emaHTF = request.security(syminfo.tickerid, tfSuperior, f_ema()[1], lookahead = barmerge.lookahead_on) plot(emaHTF, “EMA HTF”, color=color.yellow, linewidth=2)

Why is lookahead_on safe here? Because combined with [1] you are looking at a bar that has definitely closed — never into the future. Using lookahead_on without the [1] is exactly what causes the worst kind of repaint. The two go together.

Practical example: trend filter

A classic use is only buying when price is above the higher timeframe’s EMA — filtering out trades against the dominant trend:

tendenciaAlta = close > emaHTF corFundo = tendenciaAlta ? color.new(color.green, 90) : color.new(color.red, 90) bgcolor(corFundo)

This way you keep execution on the short timeframe, but use the context of the long timeframe to avoid bad entries.

Frequently asked questions (FAQ)

Can I use request.security for another asset?
Yes. Replace syminfo.tickerid with a full symbol, such as "BINANCE:BTCUSDT", to compare different assets on the same chart.

What is the difference between lookahead_on and lookahead_off?
lookahead_off (the default) avoids looking into the future, but on historical bars it can delay the higher TF value. lookahead_on aligns the value, which is why it should only be used with [1], guaranteeing the referenced bar has already closed.

How do I know if my indicator repaints?
Compare its historical behavior with real-time behavior over a few days, or reload the chart and check whether old signals moved. If they moved, there is repainting.

Can request.security be used in a strategy?
Yes, and the repaint caution is even more important: a backtest with leaked future data produces unrealistic results that will never repeat live.

Disclaimer: binary options and leveraged trading are very high-risk products and most retail investors lose money. This content is educational, does not constitute investment advice and does not guarantee any result. Indicators and backtests are study tools, not predictions. Always test on a demo account before risking real capital.

Similar Posts