Multi-Timeframe Trend Strategy
Multi-timeframe strategies use a higher timeframe (e.g., Daily) to determine the overall trend direction, then use a lower timeframe (e.g., 1H) for precise entry timing. This approach dramatically reduces false signals vs single-timeframe systems by only taking trades aligned with the larger trend.
Pine Script v6 — Complete Strategy Code
//@version=6//@version=6
strategy("Multi-Timeframe EMA Strategy", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// ── Inputs ──
int fastLen = input.int(defval=9, title="Fast EMA (Entry TF)", minval=1, group="Entry")
int slowLen = input.int(defval=21, title="Slow EMA (Entry TF)", minval=1, group="Entry")
int htfLen = input.int(defval=50, title="HTF EMA Length", minval=1, group="Higher TF")
string htfTf = input.string(defval="D", title="Higher Timeframe",
options=["60","240","D","W"], group="Higher TF")
float slMult = input.float(defval=1.5, title="SL ATR Mult", minval=0.1, step=0.1, group="Risk")
float tpMult = input.float(defval=3.0, title="TP ATR Mult", minval=0.1, step=0.1, group="Risk")
// ── Calculations ──
float fastEma = ta.ema(close, fastLen)
float slowEma = ta.ema(close, slowLen)
float atr = ta.atr(14)
// Higher timeframe EMA — confirmed (close[1]) to avoid lookahead
float htfClose = request.security(syminfo.tickerid, htfTf, close[1],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
float htfEma = request.security(syminfo.tickerid, htfTf,
ta.ema(close, htfLen)[1],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
bool bullBias = htfClose > htfEma
bool bearBias = htfClose < htfEma
bool longCond = ta.crossover(fastEma, slowEma) and bullBias
bool shortCond = ta.crossunder(fastEma, slowEma) and bearBias
// ── Visuals ──
plot(fastEma, "Fast EMA", color.new(color.aqua, 0), linewidth=1)
plot(slowEma, "Slow EMA", color.new(color.orange, 0), linewidth=1)
bgcolor(bullBias ? color.new(color.green, 97) : bearBias ? color.new(color.red, 97) : na)
plotshape(longCond, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCond, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// ── Orders ──
if longCond
strategy.entry("Long", strategy.long)
strategy.exit("XL", from_entry="Long", stop=close - atr * slMult, limit=close + atr * tpMult)
if shortCond
strategy.entry("Short", strategy.short)
strategy.exit("XS", from_entry="Short", stop=close + atr * slMult, limit=close - atr * tpMult)
// ── Alerts ──
alertcondition(longCond, title="MTF Long", message="Multi-TF long signal — {{ticker}}")
alertcondition(shortCond, title="MTF Short", message="Multi-TF short signal — {{ticker}}")Copy and paste into TradingView Pine Editor, or generate a custom variation with AI.
How it works
Strategy logic, step by step
- 1
Daily EMA(50) is fetched via request.security() with lookahead_off to prevent lookahead bias.
- 2
Bias: close above Daily EMA(50) = bullish, below = bearish.
- 3
On the 1H chart: long entry when EMA 9 crosses above EMA 21 AND daily bias is bullish.
- 4
Short entry when EMA 9 crosses below EMA 21 AND daily bias is bearish.
- 5
Only one direction trades at any time based on daily bias.
Parameters
Configurable inputs
| Parameter | Default |
|---|---|
| Fast EMA | 9 |
| Slow EMA | 21 |
| HTF EMA Length | 50 |
| Higher Timeframe | D |
Ask the TradePilot copilot to backtest this and sweep the inputs to find the best combination for your asset and timeframe.
FAQ
Multi-Timeframe Trend Strategy questions
Why use close[1] in request.security()?
Using close (not close[1]) in request.security() introduces lookahead bias — it reads the current unconfirmed bar on the higher timeframe. close[1] reads the last confirmed bar, giving you realistic backtest results.
What is the best higher timeframe to use?
Daily bias on a 1H entry chart is the most common and reliable combination. 4H bias on a 15m entry chart also works well. Going too far apart (Weekly bias on 5m entry) produces too few trades.
More strategies
Other Pine Script strategies
EMA Crossover Strategy
Fast/slow EMA crossover with RSI filter — the most tested trend-following setup in retail trading.
Supertrend Strategy
ATR-based trend-following with dynamic support/resistance. Two parameters, clear signals, easy to optimize.
RSI Divergence Strategy
Enter on confirmed RSI divergence — price making new extremes while RSI fails to confirm.
Want a custom version of this strategy?
Describe your modifications in plain English — different indicators, different risk parameters, long-only, multi-timeframe filter — and TradePilot generates the full Pine Script v6 code in seconds.