Multi-Timeframe Moving Average Alignment Panel
This indicator displays the alignment of moving averages across multiple timeframes in a panel, enabling traders to assess whether price trends are uniform across time horizons or fragmented. A trader viewing a 5-minute chart can instantly see whether the 1-hour, 4-hour and daily moving averages agree on direction, which helps confirm trend strength and filter out false micro-moves against the broader trend. This is commonly used in multi-timeframe analysis, where retail and institutional traders verify that buy or sell signals on a faster timeframe align with the trend on slower timeframes.
//@version=6
indicator("MTF MA Alignment Panel", overlay=false)
// Inputs
ma_length = input.int(20, "MA Length", minval=1)
ma_type = input.string("EMA", "MA Type", options=["SMA", "EMA", "WMA"])
tf1 = input.timeframe("60", "Timeframe 1")
tf2 = input.timeframe("240", "Timeframe 2")
tf3 = input.timeframe("D", "Timeframe 3")
tf4 = input.timeframe("W", "Timeframe 4")
panel_y_offset = input.float(0.1, "Panel Y Offset", minval=0, maxval=1)
// Helper function to calculate MA
ma(src, len, type) =>
if type == "SMA"
ta.sma(src, len)
else if type == "EMA"
ta.ema(src, len)
else
ta.wma(src, len)
// Request data from multiple timeframes
close1 = request.security(syminfo.tickerid, tf1, close)
close2 = request.security(syminfo.tickerid, tf2, close)
close3 = request.security(syminfo.tickerid, tf3, close)
close4 = request.security(syminfo.tickerid, tf4, close)
ma1 = request.security(syminfo.tickerid, tf1, ma(close, ma_length, ma_type))
ma2 = request.security(syminfo.tickerid, tf2, ma(close, ma_length, ma_type))
ma3 = request.security(syminfo.tickerid, tf3, ma(close, ma_length, ma_type))
ma4 = request.security(syminfo.tickerid, tf4, ma(close, ma_length, ma_type))
// Determine bullish (price above MA) for each timeframe
bull1 = close1 > ma1
bull2 = close2 > ma2
bull3 = close3 > ma3
bull4 = close4 > ma4
// Count bullish aligned
bull_count = (bull1 ? 1 : 0) + (bull2 ? 1 : 0) + (bull3 ? 1 : 0) + (bull4 ? 1 : 0)
// Determine panel color based on alignment
panel_color =
bull_count == 4 ? color.new(color.green, 80) :
bull_count == 3 ? color.new(color.lime, 85) :
bull_count == 2 ? color.new(color.gray, 85) :
bull_count == 1 ? color.new(color.orange, 85) :
color.new(color.red, 80)
// Draw panel background
panel_x1 = bar_index - 40
panel_x2 = bar_index + 1
panel_y1 = panel_y_offset
panel_y2 = panel_y_offset + 0.25
box.new(panel_x1, panel_y1, panel_x2, panel_y2, panel_color, border_color=na)
// Create label text for alignment status
label_text =
tf1 + (bull1 ? " ✓ " : " ✗ ") + "\n" +
tf2 + (bull2 ? " ✓ " : " ✗ ") + "\n" +
tf3 + (bull3 ? " ✓ " : " ✗ ") + "\n" +
tf4 + (bull4 ? " ✓ " : " ✗ ")
// Plot as table-like visual
if barstate.islast
label.new(panel_x1 + 20, panel_y1 + 0.125, label_text,
color=color.new(color.white, 0), textcolor=color.new(color.black, 0),
size=size.small, style=label.style_label_center)
// Alert on full alignment change
last_bull_count = ta.valuewhen(1, bull_count, 1)
if bull_count == 4 and last_bull_count != 4
alert("All timeframes bullish aligned", alert.freq_once_per_bar)
if bull_count == 0 and last_bull_count != 0
alert("All timeframes bearish aligned", alert.freq_once_per_bar)
How the code works
The script requests closing prices and moving averages from four separate timeframes specified in the inputs (default: 1-hour, 4-hour, daily, weekly). Each timeframe's closing price is compared to its respective moving average: if close exceeds MA, that timeframe is "bullish aligned"; if close is below MA, it is "bearish aligned".
The script counts how many timeframes are bullish (0 to 4) and assigns a panel color: green for all four bullish, lime for three, gray for two (neutral), orange for one, and red for all four bearish. A label displays a checkmark (✓) or cross (✗) for each timeframe, making alignment instantly visible.
The panel is drawn as a colored rectangle at a fixed position on the chart (controlled by panel_y_offset), and a text label lists each timeframe with its alignment status. Alerts fire when the market transitions to full consensus (all timeframes aligned in the same direction), helping traders detect strengthening or weakening trends.
Reading it on a chart
A green panel with four checkmarks signals that price is above the moving average on all four timeframes, a strong bullish alignment that suggests trend strength across all time horizons. Conversely, a red panel with four crosses means price is below the MA on all four timeframes, a strong bearish signal. Mixed alignment (gray, with two checkmarks and two crosses) indicates conflicting signals across timeframes: for example, a fast timeframe may be bullish while a slow timeframe remains bearish, suggesting caution or a potential trend reversal in progress.
Traders typically use this to filter entry signals: a bullish setup on a 5-minute chart that occurs during a green-panel (all-bullish) reading carries higher conviction than the same signal during a gray or red panel. Conversely, a bearish 5-minute signal during a green panel might be treated as a pullback or counter-trend trade rather than a trend reversal.
Limitations
This indicator is based solely on the relationship between price and a single moving average per timeframe. It does not measure momentum, volatility, support/resistance, volume, or other market structure; it is a trend-direction filter only.
The fixed moving average length (default 20 periods) may be too fast for daily or weekly timeframes and too slow for intraday timeframes. Traders must manually tune the MA length or use separate panels with different lengths for different timeframes; the script does not auto-scale.
Multi-timeframe analysis is subject to timeframe bias: the choice of four specific timeframes is arbitrary, and a different selection (e.g., 2-hour and 12-hour instead of 4-hour and daily) could yield different alignment patterns. The indicator does not account for session gaps, holidays, or extended market hours, which can distort MA values.
Alignment does not predict reversals. A four-timeframe green panel can persist for weeks during strong uptrends, then reverse sharply without warning signals from this tool. Traders may over-rely on alignment and miss early reversal cues from price action, divergence, or volatility spikes.
The indicator uses non-repainting request.security() calls at fixed timeframes and historical bars only, eliminating lookahead bias; however, if a user modifies the chart timeframe or reloads the script, historical panels may repaint slightly due to Pine Script's bar-merging behavior on non-standard timeframes.
Key definitions
Moving Average (MA): A smoothed price line that averages closing prices over a specified number of periods, used to identify trend direction and filter noise.
Bullish Alignment: A state in which price is trading above its moving average, interpreted as uptrend confirmation on that timeframe.
Bearish Alignment: A state in which price is trading below its moving average, interpreted as downtrend confirmation on that timeframe.
Multi-Timeframe Analysis: The practice of examining price action and indicators across multiple time horizons (e.g., 1-minute, hourly, daily) to identify convergent trends and reduce false signals.
Consensus: Full agreement across all selected timeframes; in this indicator, all four timeframes being bullish or all four being bearish.
References
-
TradingView, "Pine Script Language Reference: request.security()", TradingView Documentation. Https://www.tradingview.com/pine-script-reference/v6/#fun_request.security
-
TradingView, "Pine Script Language Reference: Moving Averages", TradingView Documentation. Https://www.tradingview.com/pine-script-reference/v6/#fun_ta.ema
-
Investopedia, "Moving Average (MA): Purpose, Formula, and Examples", Investopedia (2024). Https://www.investopedia.com/terms/m/movingaverage.asp
-
CFTC, "Multi-Timeframe Analysis in Futures Trading", Commodity Futures Trading Commission Educational Resources. (General best practices; no direct URL; cite as name only.)
Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.
Last reviewed by the PropLedger research pipeline: 2026-09-06. Educational research on historical data, not financial advice.
Keep reading
Premium and Discount Zones
Free open-source Pine Script indicator: premium and discount zones from a rolling range midpoint. Full code and a plain-English walkthrough.
Order Block Displacement Zones
Free open-source Pine Script indicator: order block zones with objective displacement rules. Full code and a plain-English walkthrough.
Liquidity Sweep Detector
Free open-source Pine Script indicator: liquidity sweep detector: prior high/low taken then reclaimed. Full code and a plain-English walkthrough.