Skip to main content
On this page

Pine Script Multi-Timeframe Analysis with Confirmed Data

· 5 min read
Pineify Team
Pine Script and AI trading workflow research team

Multi-timeframe Pine scripts evaluate data in more than one chart interval. The main implementation decisions are which context performs the calculation and when its result becomes available. Agreement between timeframes is a possible strategy rule, not evidence that a trade has a higher probability of success.

Use valid Pine timeframe strings​

Minutes have no suffix, and hours are expressed as minutes. Use "60" for one hour, not "1h" or "1H". Months use uppercase M, so "1M" means one month, not one minute.

IntervalPine string
5 minutes"5"
15 minutes"15"
1 hour"60"
4 hours"240"
1 day"1D"
1 week"1W"
1 month"1M"

Pine also supports specified second and tick intervals. See the official timeframe specification for valid multipliers. input.timeframe() provides a user-selectable interval; it does not ensure that the selected value is higher than the current chart.

Calculate in the requested context​

request.security() evaluates its expression in the requested symbol and timeframe. To calculate a daily RSI, request the RSI expression in the daily context. Calculating an RSI over daily values already repeated across intraday bars can produce a different result.

Decide whether you want the developing higher-timeframe value or the last confirmed value. The developing value can change before its bar closes. That may be useful for a live display, but it needs to be disclosed and cannot be assumed to reproduce identically after a reload.

Complete confirmed higher-timeframe RSI example​

Use this educational example on a standard time-based chart with a strictly higher time-based input. For example, choose a 15-minute chart and a 60-minute input. The periods are illustrative, not optimized trading settings.

//@version=6
indicator("Chart RSI and Confirmed HTF RSI", overlay=false)
length = input.int(14, "RSI length", minval=1)
higherTimeframe = input.timeframe("60", "Higher timeframe")
if timeframe.in_seconds(higherTimeframe) <= timeframe.in_seconds()
runtime.error("Choose a timeframe higher than the chart timeframe.")
chartRSI = ta.rsi(close, length)
confirmedHTFRSI = request.security(syminfo.tickerid, higherTimeframe, ta.rsi(close, length)[1], lookahead=barmerge.lookahead_on)
plot(chartRSI, "Chart RSI (developing)", color=color.blue)
plot(confirmedHTFRSI, "Last confirmed HTF RSI", color=color.orange, style=plot.style_stepline)
hline(70, "Upper reference", color=color.gray)
hline(30, "Lower reference", color=color.gray)

The [1] belongs inside the requested expression, so it refers to the previous higher-timeframe bar. Combined with lookahead_on, it makes that already-confirmed result available from the next higher-timeframe period. The cost is delayed information. The chart RSI still develops on the open chart bar.

lookahead_off alone does not prevent repainting​

The default lookahead_off avoids the historical future leak caused by requesting an unoffset higher-timeframe value with lookahead_on. It does not stop a developing higher-timeframe value from fluctuating in realtime.

For the confirmed higher-timeframe pattern above, keep the expression offset and lookahead_on together. Removing the offset can leak future values into historical bars. TradingView explains this distinction in its repainting guide.

"Non-repainting" should describe a specific behavior under stated conditions. It is not a promise that data-provider corrections, different datasets, or changes to other parts of a script can never change a result.

Lower-timeframe requests need a different design​

A normal request.security() call does not return every intrabar as a collection. If you need to analyze multiple lower-timeframe bars inside a chart bar, review request.security_lower_tf() and its array output in the other timeframes and data guide.

Do not apply the confirmed higher-timeframe example to a lower input. Its guard rejects that choice because the timing assumptions would no longer match the example's purpose.

Review the implementation before using signals​

Record the chart interval, requested interval, source symbol, and confirmation policy. Inspect the plot at a higher-timeframe boundary and compare its value with the corresponding confirmed bar on a separate chart. Allow enough history for the calculation to initialize.

Then test the realtime behavior and a reload. For a strategy, add explicit costs and order assumptions before studying returns. Additional timeframes add design choices and resource use; there is no universal number or interval ratio that guarantees a better strategy.

Frequently asked questions​

How do I write one hour in Pine Script?

Use the string "60". Pine has no hour suffix; "1M" is one month.

Does lookahead_off guarantee no repainting?

No. A requested higher-timeframe value can still develop before its bar closes. The confirmed-value pattern uses an offset expression together with lookahead_on.

Why does the confirmed line update later?

It waits for the higher-timeframe bar to finish. That delay is the tradeoff for using its confirmed value rather than its current estimate.

Does timeframe agreement improve returns?

That is a testable hypothesis for a specific strategy, market, and cost model. Agreement alone does not establish an advantage.

The Best Pine Script Generator