Pine Script Mastery: Building a Multi-Timeframe AI Screener from Scratch

Pine Script Mastery: Building a Multi-Timeframe AI Screener from Scratch, Atech360 Insights cover

Pine Script Mastery: Building a Multi-Timeframe AI Screener

A complete step-by-step guide to building a professional-grade TradingView screener with multi-timeframe trend alignment and automated alerts.

Why Multi-Timeframe Analysis?

The biggest edge in trading comes from confluence, when multiple timeframes agree on direction. A daily uptrend + 4H pullback + 1H breakout is a much higher-probability trade than any single-timeframe signal.

The Screener We Are Building

This Pine Script screener will check three conditions across three timeframes and only generate a signal when all three align. Here is the logic:

  • Daily (D1): Price above 200 EMA (uptrend confirmed)
  • 4-Hour (4H): RSI recovering from oversold (momentum shift)
  • 1-Hour (1H): Bullish engulfing candle (entry trigger)

The Pine Script Code

//@version=5
indicator("Atech360 MTF Screener", overlay=true, max_labels_count=500)

// === INPUTS ===
ema_len   = input.int(200, "EMA Length", group="Trend Filter")
rsi_len   = input.int(14, "RSI Length", group="Momentum")
rsi_os    = input.int(35, "RSI Oversold Level", group="Momentum")

// === MULTI-TIMEFRAME DATA ===
daily_close  = request.security(syminfo.tickerid, "D",  close)
daily_ema200 = request.security(syminfo.tickerid, "D",  ta.ema(close, ema_len))
htf_rsi      = request.security(syminfo.tickerid, "240", ta.rsi(close, rsi_len))
htf_rsi_prev = request.security(syminfo.tickerid, "240", ta.rsi(close[1], rsi_len))

// === CONDITIONS ===
trend_up      = daily_close > daily_ema200
rsi_recovering = htf_rsi > rsi_os and htf_rsi_prev <= rsi_os
bull_engulf    = close > open and close[1] < open[1] and close >= open[1]

// === SIGNAL ===
signal = trend_up and rsi_recovering and bull_engulf

// === PLOT ===
plotshape(signal, title="MTF Buy Signal",
  location=location.belowbar, color=color.new(#00B8F0, 0),
  style=shape.labelup, text="▲ MTF", textcolor=color.white, size=size.small)

// === ALERTS ===
alertcondition(signal, "MTF Buy Signal",
  "{{ticker}}, Multi-Timeframe Buy Signal on {{interval}}")

Want a Custom Version?

We build custom TradingView screeners and strategies for traders. See our TradingView development service or get a quote.