StructureX

Home › Guides › Platforms

Pine Script higher-timeframe trend: see the bigger chart on any chart

We check the bigger chart before every trade, and trade with it. This script does that check for you, on whatever chart you're looking at, using only daily candles that have already closed.

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

Why a bigger-chart filter?

A 15-minute chart shows the waves. The daily chart shows the tide.

A buy setup on the 15-minute chart is swimming with the tide when the daily trend is up, and against it when the daily trend is down. Our method is simple about this: check the bigger chart first, and trade with it. More in multiple timeframe analysis.

Switching charts back and forth is easy to skip. A small script puts the answer on the chart you trade from.

This page builds on Pine Script request.security, which explains how bigger-timeframe data works and why it can repaint. Read that first if the terms are new.

What "trend up" means here

We need a rule a script can check. This one uses the daily chart and a 50-day EMA (an average that leans toward recent days):

"Unclear" is an answer too. It often means sit tight.

The script

//@version=6
indicator("Bigger-chart trend", overlay=true)
tf = input.timeframe("D", "Bigger timeframe")
len = input.int(50, "Average length", minval=2)
if timeframe.in_seconds(tf) <= timeframe.in_seconds(timeframe.period)
    runtime.error("Pick a bigger timeframe than the chart's.")
[bigClose, bigAvg, bigAvgPrev] = request.security(syminfo.tickerid, tf, [close[1], ta.ema(close, len)[1], ta.ema(close, len)[2]], lookahead=barmerge.lookahead_on)
trendUp = bigClose > bigAvg and bigAvg > bigAvgPrev
trendDown = bigClose < bigAvg and bigAvg < bigAvgPrev
bgcolor(trendUp ? color.new(color.green, 92) : trendDown ? color.new(color.red, 92) : na)
plot(bigAvg, "Bigger average", color=color.purple, linewidth=2)
var label tag = label.new(bar_index, close, "", style=label.style_label_left, textcolor=color.white)
if barstate.islast
    word = trendUp ? "Up" : trendDown ? "Down" : "Unclear"
    label.set_xy(tag, bar_index + 2, close)
    label.set_text(tag, tf + " trend: " + word)
    label.set_color(tag, trendUp ? color.green : trendDown ? color.red : color.gray)

Every line, in plain words

Why [1] with lookahead_on?

This is the part that keeps the script honest.

Line 7 only uses finished daily candles: [1] and [2]. lookahead_on lines each finished value up with the start of the next day, instead of a day late.

Together, they mean: what you see live is what history shows later. Nothing changes after it's drawn.

The cost is that the trend is always one day behind. On a daily trend check, that's a fair trade. A full explanation is in Pine Script request.security.

Never use lookahead_on without [1]. Past candles would see the day's final close before the day was over. The chart would look brilliant and be wrong.

Picking the bigger timeframe

A common habit is about 4 to 6 times bigger than the chart you trade:

Your chartA bigger chart to check
5 minutes30 minutes or 1 hour
15 minutes1 hour or 4 hours
1 hour4 hours or daily
DailyWeekly

Too close, and the "bigger" trend is just noise. Too far, and it changes so rarely it says little.

A better trend rule

An average is a simple way to read direction. It's also late. A more direct read is the one we teach: higher highs and higher lows for up, lower highs and lower lows for down. See higher highs and higher lows and how to identify a trend.

You can code that too, with turning points from Pine Script swing highs and lows, and pull it from the bigger timeframe the same way.

Use it as a filter, not a trigger

The bigger-chart trend answers one question: which way should I be looking? It doesn't say when to act.

Combine it with a setup rule, like a candle body closing past a level. Pair it with the crossover in Pine Script moving average crossover, or put the answer in a Pine Script table with your other checks.

Then every trade still needs a stop from the chart and a size from the math.

Try it today

  1. Paste the script into the Pine Editor on a computer. Save and add it to a 15-minute chart.
  2. Scroll back a few weeks. Notice the shading changes only at the start of a day.
  3. Change the timeframe setting to "W" (weekly) and look again. Fewer changes.
  4. On bar replay, step through a week. Check that the color never changes after it's drawn.

Unclear is useful. Count how many days were "Unclear". Those are days the bigger chart wasn't giving a clear direction. Many traders do less on those days.

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-chart filter. It's source code, not a ready-made trading bot.

Common mistakes

Questions

How do I show the daily trend on an intraday chart in Pine Script?

Use request.security() with the daily timeframe and values offset by [1], with lookahead=barmerge.lookahead_on. Then compare the finished daily close to a finished daily average.

Does a higher timeframe filter repaint in Pine Script?

It can. With plain values and lookahead off, today's value moves until the day closes. Using [1] with lookahead_on uses only finished candles, so it doesn't change after it's drawn.

Can request.security return more than one value?

Yes. Put the values in square brackets, like [close[1], ta.ema(close, 50)[1]], and receive them as a group on the left side.

What higher timeframe should I use?

A common habit is 4 to 6 times your chart: 1 hour for a 15-minute chart, daily for a 1-hour chart.

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