Indicator · Pine Script v6 · Own pane

Multi-Timeframe Trend Alignment

by shubhamtaywade82

Compares price with a moving average on four selectable timeframes, defaulting to 15 minutes, 1 hour, 4 hours and 1 day.

View on GitHub

Archived by its author

GitHub stars1on the repository
Pine versionv6current
Lines of code67
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago31 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

67 lines of Pine Script v6 from indicators/agent-examples/mtf-trend-alignment.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mtf-trend-alignment.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Ported from pinescript-agents/examples/simple/mtf-trend-alignment.pine for local testing in pinescripts-collections.

//@version=6
indicator("Multi-Timeframe Trend Alignment [Agent Example]", "MTFTrAE", overlay=false)

ma_type = input.string("EMA", "Moving Average Type", options=["SMA", "EMA", "WMA"], group="Settings")
ma_length = input.int(20, "MA Length", minval=5, maxval=200, group="Settings")

tf1 = input.timeframe("15", "Timeframe 1", group="Timeframes")
tf2 = input.timeframe("60", "Timeframe 2", group="Timeframes")
tf3 = input.timeframe("240", "Timeframe 3", group="Timeframes")
tf4 = input.timeframe("1D", "Timeframe 4", group="Timeframes")

bull_color = input.color(#089981, "Bullish Color", group="Colors")
bear_color = input.color(#f23645, "Bearish Color", group="Colors")
neutral_color = input.color(color.new(#2a2e39, 0), "Neutral Color", group="Colors")

get_ma(src, length, ma_type_) =>
    switch ma_type_
        "SMA" => ta.sma(src, length)
        "EMA" => ta.ema(src, length)
        "WMA" => ta.wma(src, length)
        => ta.ema(src, length)

get_trend(ma_value, close_value) =>
    if close_value > ma_value
        1
    else if close_value < ma_value
        -1
    else
        0

ma_tf1 = request.security(syminfo.tickerid, tf1, get_ma(close, ma_length, ma_type), lookahead=barmerge.lookahead_off)
ma_tf2 = request.security(syminfo.tickerid, tf2, get_ma(close, ma_length, ma_type), lookahead=barmerge.lookahead_off)
ma_tf3 = request.security(syminfo.tickerid, tf3, get_ma(close, ma_length, ma_type), lookahead=barmerge.lookahead_off)
ma_tf4 = request.security(syminfo.tickerid, tf4, get_ma(close, ma_length, ma_type), lookahead=barmerge.lookahead_off)

close_tf1 = request.security(syminfo.tickerid, tf1, close, lookahead=barmerge.lookahead_off)
close_tf2 = request.security(syminfo.tickerid, tf2, close, lookahead=barmerge.lookahead_off)
close_tf3 = request.security(syminfo.tickerid, tf3, close, lookahead=barmerge.lookahead_off)
close_tf4 = request.security(syminfo.tickerid, tf4, close, lookahead=barmerge.lookahead_off)

trend_tf1 = get_trend(ma_tf1, close_tf1)
trend_tf2 = get_trend(ma_tf2, close_tf2)
trend_tf3 = get_trend(ma_tf3, close_tf3)
trend_tf4 = get_trend(ma_tf4, close_tf4)

trend_score = trend_tf1 + trend_tf2 + trend_tf3 + trend_tf4

plot(trend_tf1, title="TF1 Trend", color=trend_tf1 > 0 ? bull_color : trend_tf1 < 0 ? bear_color : neutral_color, linewidth=2, offset=3)
plot(trend_tf2, title="TF2 Trend", color=trend_tf2 > 0 ? bull_color : trend_tf2 < 0 ? bear_color : neutral_color, linewidth=2, offset=2)
plot(trend_tf3, title="TF3 Trend", color=trend_tf3 > 0 ? bull_color : trend_tf3 < 0 ? bear_color : neutral_color, linewidth=2, offset=1)
plot(trend_tf4, title="TF4 Trend", color=trend_tf4 > 0 ? bull_color : trend_tf4 < 0 ? bear_color : neutral_color, linewidth=2, offset=0)

hline(0, "Zero Line", color=color.new(neutral_color, 45), linestyle=hline.style_dashed)
hline(4, "All Bullish", color=color.new(bull_color, 25), linestyle=hline.style_solid)
hline(-4, "All Bearish", color=color.new(bear_color, 25), linestyle=hline.style_solid)

plot(trend_score, title="Trend Alignment", color=trend_score > 2 ? bull_color : trend_score < -2 ? bear_color : neutral_color, linewidth=3)

bgcolor(trend_score == 4 ? color.new(bull_color, 90) : trend_score == -4 ? color.new(bear_color, 90) : na, title="Full Alignment")

alertcondition(trend_score == 4, "All Timeframes Bullish", "All timeframes are bullish aligned")
alertcondition(trend_score == -4, "All Timeframes Bearish", "All timeframes are bearish aligned")
alertcondition(ta.crossover(trend_score, 2), "Strong Bullish Alignment", "Strong bullish trend alignment")
alertcondition(ta.crossunder(trend_score, -2), "Strong Bearish Alignment", "Strong bearish trend alignment")

Overview

Each timeframe scores plus one, minus one or zero, and the four are summed into an alignment score from minus four to plus four. It plots in a separate pane, with reference lines at full alignment and a background tint when all four agree. The average can be SMA, EMA or WMA.

Details

Published by

shubhamtaywade82 on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Moving Average TypestringEMAma_type
MA Lengthint20ma_length
Timeframe 1timeframe15tf1
Timeframe 2timeframe60tf2
Timeframe 3timeframe240tf3
Timeframe 4timeframe1Dtf4
Bullish Colorcolor#089981bull_color
Bearish Colorcolor#f23645bear_color
Neutral Colorcolorcolor.new(#2a2e39, 0)neutral_color
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator
99 stars

Calculates the Archer Moving Averages Trends (AMAT) indicator by comparing fast and slow Exponential Moving Averages (EMAs) alongside their slope directions. A bullish trend (+1) is identified when the fast EMA exceeds the slow EMA with both rising, while a be

Indicator v6 TrendMoving averages
Updated 4 weeks ago · Apache-2.0 GitHub repository of Archer Moving Averages Trends (AMAT)

Colored fill

by be-thomas
65 stars

This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n

Indicator v4 Moving averagesTrend
Updated 5 days ago · GPL-3.0 GitHub repository of Colored fill

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers