Higher-timeframe data and confirmation

Multi Timeframe Trend Indicator: Know Which Bar Supplies the Signal

A multi timeframe trend indicator combines price information from different chart intervals. A useful specification names the trend rule, the requested interval and whether the requested bar is confirmed. This example compares the previous higher-timeframe close with its EMA; it displays a lagged trend state, not an entry order or a prediction of the next move.

See the decision guide

Choose a testable trend definition

A one-hour close above its 50-period EMA is one possible trend definition. It is different from an EMA slope, a sequence of swing highs or a breakout rule. On a five-minute chart, the one-hour EMA must be calculated in the one-hour context; an EMA applied afterward to a repeated requested series instead weights chart bars. State the symbol, session and chart type as well as the two intervals.

Future leakage and changing live values are different problems

An unoffset higher-timeframe request with lookahead_on can expose a completed higher-timeframe value too early in historical bars. Using lookahead_off avoids that historical future leak, but requesting the current HTF bar can still change while it forms. For the confirmed HTF pattern used here, the requested expressions use [1] together with lookahead_on. Removing either part changes the timing.

  • Keep the offset inside the requested expression. Shifting the returned series afterward shifts chart bars, not the requested timeframe bars.
  • Adding [1] while retaining lookahead_off is not the same alignment: historical values update at the end of the HTF interval instead of its start.
  • A chart-bar close does not necessarily close the requested higher-timeframe bar. Avoid using chart confirmation as proof of HTF confirmation.

Follow one hourly observation through a five-minute chart

Consider a continuous market with hourly bars aligned at whole UTC hours. Assume the 10:00–11:00 bar closes at 102 and its EMA is 100. The following numbers illustrate information availability, not historical market performance.

Chart timeConfirmed hourly data usedDisplayed state
First available five-minute bar at 11:0010:00–11:00 close 102; EMA 100Above EMA; spread +2
11:55, before the next hourly closeThe same prior hourly close and EMAStill above EMA, even if the developing hour falls
First available chart bar at 12:0011:00–12:00 values become availableRecompute from that completed hour

Complete Pine Script v6 example

Apply this indicator to a standard time-based chart and choose a higher requested timeframe. The example requests both values in one tuple, carries the last available confirmed values between updates, and distinguishes missing and equal values. The histogram is a price difference in the symbol’s price units, not a percentage or probability.

Confirmed HTF close relative to its EMA; display only, no orderspinescript
//@version=6
indicator("Confirmed HTF Trend State [Pineify]", overlay=false)

string higherTf = input.timeframe("60", "Higher timeframe")
int maLength = input.int(50, "Higher-timeframe EMA length", minval=1)

if timeframe.in_seconds(higherTf) <= timeframe.in_seconds()
    runtime.error("Choose a timeframe strictly above the chart timeframe.")

// Both expressions refer to the preceding bar in the requested context.
[confirmedClose, confirmedEma] = request.security(syminfo.tickerid, higherTf, [close[1], ta.ema(close, maLength)[1]], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)

bool ready = not na(confirmedClose) and not na(confirmedEma)
float spread = ready ? confirmedClose - confirmedEma : na
string state = not ready ? "NO DATA" : spread > 0 ? "ABOVE EMA" : spread < 0 ? "BELOW EMA" : "AT EMA"
color stateColor = not ready ? color.gray : spread > 0 ? color.green : spread < 0 ? color.red : color.gray

plot(spread, "Previous HTF close minus previous HTF EMA", color=stateColor, style=plot.style_columns)
hline(0, "EMA reference", color=color.gray)

var table status = table.new(position.top_right, 2, 1, bgcolor=color.new(color.black, 20))
if barstate.islast
    table.cell(status, 0, 0, "Requested TF: " + higherTf, text_color=color.white)
    table.cell(status, 1, 0, state, text_color=stateColor)

Validate timing before testing a strategy

Check a five-minute chart with a 60-minute request across an hourly boundary. Inspect when the state updates, then reload and compare the same completed bars. Repeat for the sessions and chart history you intend to use. Data corrections or a different available history can still change calculations; this example addresses unconfirmed HTF requests, not every possible source of revision.

  • An equal or lower timeframe input must stop with the explanatory runtime error.
  • The table must show AT EMA for an exact tie and NO DATA when either requested value is unavailable.
  • Changing the input to a daily interval must display its timeframe code without appending an incorrect minute suffix.
  • If adding entries, exits or alerts, specify their timing separately and test costs, slippage, missed signals and behavior outside the development sample.

Use alignment as a research rule, not a guarantee

A slow filter can remove some countertrend trades and also exclude early reversals or profitable trades. It cannot establish institutional participation, an optimal stop distance or a superior timeframe combination. Compare a fully specified strategy with and without the filter under the same execution assumptions. This page provides a data-timing example; it does not report a profitable backtest.

Where Pineify fits

Pine Script AI Coding Agent

Draft or revise a timeframe rule, then inspect the requested context, confirmation timing and chart behavior. Syntax diagnostics do not establish that a trading rule is profitable or free of every runtime issue.

Explore the Pine Script coding workflow

Frequently asked questions

Educational code and hypothetical timing example, not investment advice. Syntax validation does not replace TradingView chart testing or establish a trading edge.

Sources and verification