A Pine Script multi time frame strategy combines signals from one chart timeframe with context from another, often using a confirmed higher-timeframe filter to gate lower-timeframe entries. Request the prior closed higher-timeframe value to avoid acting on a candle that is still forming.
How does a multi-timeframe strategy fit together?
A multi-timeframe strategy uses data from more than one timeframe to make a single trading decision. A common design puts the slower timeframe in charge of context and the faster timeframe in charge of timing. For example, a daily trend filter can allow long entries on an hourly chart, while a short-term signal decides when to enter.
Think of the two parts as separate rules:
Context: What market conditions allow a trade? A trend filter might permit longs only when the confirmed higher-timeframe close is above its moving average.
Trigger: What event creates an entry? It could be a crossover, breakout, or oscillator signal on the chart timeframe.
Exit and risk: What closes the position, and how are order size and costs handled?
The filter does not predict what the market will do next. It simply restricts which entries your strategy is allowed to take. That restriction can reduce trades as well as change results, so compare the filtered and unfiltered versions rather than assuming the filter improves the system.
If you are still turning an idea into explicit rules, our guide to turning a trading idea into testable Pine Script can help you define the entry, exit, filter, and sizing before coding.
How do you request a confirmed higher-timeframe value?
Use request.security() to evaluate an expression in another symbol-and-timeframe context and bring its result onto the chart. For a strategy, the important part is not just which timeframe you request, but whether the requested bar has finished.
A higher-timeframe candle can still be forming while several lower-timeframe bars appear. Its moving average, RSI, or close can change during that period. If your strategy uses that unfinished value, a signal may look different after the higher-timeframe candle closes. The [1] offset inside the requested expression selects the previous higher-timeframe bar, which is closed. State lookahead_off explicitly so the intent is visible in the code.
//@version=6
strategy("Confirmed MTF trend filter", overlay = true)
htf = input.timeframe("D", "Trend timeframe")
trendLength = input.int(50, "Trend EMA length", minval = 2)
// Request the EMA from the previous, closed higher-timeframe bar.
confirmedHtfEma = request.security(
syminfo.tickerid,
htf,
ta.ema(close, trendLength)[1],
lookahead = barmerge.lookahead_off
)
allowLong = close > confirmedHtfEma
plot(confirmedHtfEma, "Confirmed HTF EMA", color = color.orange)Here, close in allowLong is from the chart timeframe, while confirmedHtfEma is the prior closed higher-timeframe EMA. The example only defines a filter; it is not a complete trading system. Add an entry trigger and exit rules that match your own hypothesis.
The offset belongs inside the request.security() expression. Moving it outside changes which series is offset and can produce a different result. For more detail, see our explanation of how request.security works and the confirmed-bar pattern for multi-timeframe indicators.
How do you add lower-timeframe entries?
Once the higher-timeframe filter is stable, combine it with a clearly defined entry condition on the chart timeframe. For instance, an RSI crossover can act as the trigger, while the confirmed EMA decides whether a long is allowed. The entry then reads as a rule you can inspect: take the crossover only when the trend gate is open.
rsiLength = input.int(14, "RSI length", minval = 2)
rsiValue = ta.rsi(close, rsiLength)
longTrigger = ta.crossover(rsiValue, 30)
longEntry = longTrigger and allowLong
if longEntry
strategy.entry("Long", strategy.long)This snippet illustrates the relationship between filter and trigger, not a recommended RSI system. Choose thresholds, direction rules, and exits for the hypothesis you want to test. If you want both long and short entries, define their filters and triggers separately; do not assume the short side should simply mirror the long side.
Keep each condition readable while developing. Plot the higher-timeframe filter, and mark the trigger and actual entry separately. That makes it easier to see whether a missed trade came from the filter, the trigger, or the order logic. A 200 EMA trend filter guide shows how to treat a filter as a gate on an existing entry rather than an entry signal by itself.
What can make an MTF strategy repaint?
The main hazard is using a higher-timeframe value before that candle has closed. A daily RSI or EMA can move while the daily bar is live. Historical bars show the final settled value, but a live strategy encountered the unfinished value as it changed. That mismatch can make past entries appear cleaner than the decisions available in real time.
Do not treat barmerge.lookahead_off alone as a full repainting fix. It prevents the particular future leak associated with lookahead_on, but a request without a prior-bar offset can still use the current, unfinished higher-timeframe bar. Conversely, using lookahead_on with a current higher-timeframe value can expose the final value on historical lower-timeframe bars before it would have been known.
For signals that must use completed higher-timeframe data, request the prior value inside the expression and use lookahead_off, as in the earlier code. This introduces a delay: you are choosing confirmation over using a moving value. That delay is part of the rule, not a coding defect.
Also check how your strategy handles the chart’s live bar. If an entry condition is allowed to change before that bar closes, it may appear and disappear intrabar. Decide whether your system acts on intrabar changes or only confirmed chart bars, and test that behavior deliberately. Our guide to Pine Script lookahead explains why the setting matters; our article on repainting and its different causes covers related pitfalls.
When should you use lower-timeframe data requests?
A strategy that requests a higher timeframe is different from one that needs the individual bars inside a chart bar. request.security() returns a value merged onto the chart’s bars. When you need the collection of intrabars within each chart bar, investigate request.security_lower_tf() and its array-based results instead.
That distinction matters for questions such as whether a stop or target was reached first inside a larger chart candle. A single merged value may not provide the intrabar sequence your rule needs. Lower-timeframe requests can offer more detail, but they also make the data structure and logic more involved. Use them only when the strategy’s decision genuinely depends on information at that finer resolution.
Before changing functions, write down the exact question your strategy is asking. Is it “Was the prior daily trend positive?” or “What happened inside this five-minute bar?” The first is a higher-timeframe context request; the second is an intrabar-data problem. Our guide to request.security_lower_tf() walks through lower-timeframe arrays and their use.
How should you test the strategy fairly?
A clean compile only tells you that Pine accepted the script. It does not establish that the rules behave as intended or that the backtest is useful. Review the strategy in stages:
Check the logic on the chart. Confirm that the higher-timeframe filter changes only when expected and that entries match the written conditions.
Inspect individual trades. Look at entry and exit bars, not just the headline result. Check whether the strategy uses the intended timeframe values.
Compare like with like. Run the same entry and exit logic with the filter on and off. Note changes in trade count as well as performance measures.
Include trading costs. Set commission and slippage to assumptions you consider realistic. Results without costs can misrepresent a strategy.
Check for future dependence. Replay the script bar by bar and inspect whether signals that looked present historically were actually available at the time.
PineScripter can simulate strategies on past bars, and its strategy simulations use starting capital, commission, and slippage specified by the user. The simulation describes historical behavior; it is not a forecast. Our strategy commission and slippage guide explains how costs enter a Pine Script strategy.
For an MTF strategy, bar replay is especially useful: stop where a higher-timeframe candle is still forming and ask whether your rule uses only information available then. A backtest can be a way to investigate a hypothesis, not a promise about future performance.
How can you build and debug the strategy efficiently?
Start with a small, testable specification rather than asking for a complete strategy in one vague sentence. State the chart timeframe, requested timeframe, exact higher-timeframe series, whether it must be confirmed, entry trigger, exits, and cost assumptions. If a choice is open—such as whether a short entry should be included—decide it before treating the code as finished.
When debugging, isolate one question at a time. First confirm the requested series on the chart. Then check the filter. Then add the entry condition and inspect its markers. Finally, add exits and compare the strategy’s trade list with the rules. This makes a logic problem easier to distinguish from a compile error.
In PineScripter, we turn a request into a requirements checklist, ask clarifying questions when details are ambiguous, write Pine Script v6, and run draft scripts through a built-in lint engine to check and repair compile errors. We explain the resulting script in plain English. For follow-up changes, we edit affected lines and show the changes side by side, with saved versions in the library. These checks help with code and iteration; they do not prove that a strategy is profitable or suitable for live trading.
You can also inspect the script on a chart and use replay to see when conditions trigger. If you want to try that workflow, see our Pine Script AI editor and bar replay tools.