Indicator · Pine Script v6 · Own pane

MTF MA bands + RSI

by InNoobWeTrust

This indicator plots multi-timeframe moving average bands alongside a Relative Strength Index in a separate pane.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code305
Settings30inputs
LicenceNone statedfile: MPL-2.0
Last updatetoday28 Oct 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

305 lines of Pine Script v6 from .innoobwetrust/life_hacks/tradingview/mtf_ma_+_rsi.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

mtf_ma_+_rsi.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © InNoobWeTrust

//@version=6
indicator("MTF MA bands + RSI", overlay=false)

//=============================================================================
// MTF MA bands
//=============================================================================

// Types
//-----------------------------------------------------------------------------{
enum MaType
    sma = 'SMA'
    wma = 'WMA'
    ema = 'EMA'

type MaTf
    bool enable
    string tf
    MaType t
    int len
    float ma
    float ma_filled
    float h_ma
    float h_ma_filled
    float l_ma
    float l_ma_filled
    color clr
    color band_clr
//-----------------------------------------------------------------------------}

// Const
//-----------------------------------------------------------------------------{
const int TF_SIZE = 7
//-----------------------------------------------------------------------------{

// Helper functions
//-----------------------------------------------------------------------------{
ma(MaType t, src, int len) =>
    switch t
        MaType.sma => ta.sma(src, len)
        MaType.wma => ta.wma(src, len)
        MaType.ema => ta.ema(src, len)

ma_tf(series string tf, MaType t, src, int len) =>
    request.security(syminfo.tickerid, tf, ma(t, src, len))

// Smoothing MA Calculation
rsi_ma(source, length, MAtype) =>
    switch MAtype
        "SMA"                   => ta.sma(source, length)
        "SMA + Bollinger Bands" => ta.sma(source, length)
        "EMA"                   => ta.ema(source, length)
        "SMMA (RMA)"            => ta.rma(source, length)
        "WMA"                   => ta.wma(source, length)
        "VWMA"                  => ta.vwma(source, length)
//-----------------------------------------------------------------------------}

// Input
//-----------------------------------------------------------------------------{
ma1_grp = '► MA1'
ma1_enable = input.bool(true, 'Enable', group = ma1_grp)
ma1_type = input.enum(MaType.ema, 'MA type', group = ma1_grp)
ma1_len = input.int(34, 'Length', group = ma1_grp)
ma1_color = input.color(color.new(#FFD921,50), 'Color', group = ma1_grp)
ma1_band_color = input.color(color.new(#FFD921,80), 'Band Color', group = ma1_grp)
ma1_tf = input.timeframe('', 'Timeframe', group = ma1_grp)

ma2_grp = '► MA2'
ma2_enable = input.bool(true, 'Enable', group = ma2_grp)
ma2_type = input.enum(MaType.ema, 'MA type', group = ma2_grp)
ma2_len = input.int(34, 'Length', group = ma2_grp)
ma2_color = input.color(color.new(#DDA059,50), 'Color', group = ma2_grp)
ma2_band_color = input.color(color.new(#DDA059,80), 'Band Color', group = ma2_grp)
ma2_tf = input.timeframe('5', 'Timeframe', group = ma2_grp)

ma3_grp = '► MA3'
ma3_enable = input.bool(true, 'Enable', group = ma3_grp)
ma3_type = input.enum(MaType.ema, 'MA type', group = ma3_grp)
ma3_len = input.int(34, 'Length', group = ma3_grp)
ma3_color = input.color(color.new(#AA585B,50), 'Color', group = ma3_grp)
ma3_band_color = input.color(color.new(#AA585B,80), 'Band Color', group = ma3_grp)
ma3_tf = input.timeframe('30', 'Timeframe', group = ma3_grp)

ma4_grp = '► MA4'
ma4_enable = input.bool(true, 'Enable', group = ma4_grp)
ma4_type = input.enum(MaType.ema, 'MA type', group = ma4_grp)
ma4_len = input.int(34, 'Length', group = ma4_grp)
ma4_color = input.color(color.new(#B52121,50), 'Color', group = ma4_grp)
ma4_band_color = input.color(color.new(#B52121,80), 'Band Color', group = ma4_grp)
ma4_tf = input.timeframe('240', 'Timeframe', group = ma4_grp)

rsi_grp = '► RSI'
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group=rsi_grp)
rsiSourceInput = input.source(close, "Source", group=rsi_grp)
calculateDivergence = input.bool(false, title="Calculate Divergence", group=rsi_grp, display = display.data_window, tooltip = "Calculating divergences is needed in order for divergence alerts to fire.")

// Smoothing MA inputs
rsi_smoothing_grp = "► Smoothing RSI MA"
TT_BB = "Only applies when 'SMA + Bollinger Bands' is selected. Determines the distance between the SMA and the bands."
maTypeInput = input.string("SMA", "Type", options = ["None", "SMA", "SMA + Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = rsi_smoothing_grp, display = display.data_window)
var isBB = maTypeInput == "SMA + Bollinger Bands"
maLengthInput = input.int(14, "Length", group = rsi_smoothing_grp, display = display.data_window, active = maTypeInput != "None")
bbMultInput = input.float(2.0, "BB StdDev", minval = 0.001, maxval = 50, step = 0.5, tooltip = TT_BB, group = rsi_smoothing_grp, display = display.data_window, active = isBB)
var enableMA = maTypeInput != "None"
//-----------------------------------------------------------------------------}

// Calculation
//-----------------------------------------------------------------------------{

// Constructor
newMa(int idx) =>
    enable = switch idx
        0 => ma1_enable
        1 => ma2_enable
        2 => ma3_enable
        3 => ma4_enable
    tf = switch idx
        0 => ma1_tf
        1 => ma2_tf
        2 => ma3_tf
        3 => ma4_tf
    t = switch idx
        0 => ma1_type
        1 => ma2_type
        2 => ma3_type
        3 => ma4_type
    len = switch idx
        0 => ma1_len
        1 => ma2_len
        2 => ma3_len
        3 => ma4_len
    clr = switch idx
        0 => ma1_color
        1 => ma2_color
        2 => ma3_color
        3 => ma4_color
    band_clr = switch idx
        0 => ma1_band_color
        1 => ma2_band_color
        2 => ma3_band_color
        3 => ma4_band_color
    ma = enable ? ma_tf(tf,t,close,len) : na
    ma_filled = ta.valuewhen(not na(ma), ma, 0)
    h_ma = enable ? ma_tf(tf,t,high,len) : na
    h_ma_filled = ta.valuewhen(not na(h_ma), h_ma, 0)
    l_ma = enable ? ma_tf(tf,t,low,len) : na
    l_ma_filled = ta.valuewhen(not na(l_ma), l_ma, 0)
    MaTf.new(enable,tf,t,len,ma,ma_filled,h_ma,h_ma_filled,l_ma,l_ma_filled,clr,band_clr)

// EMA data
MaTf[] ma_data = array.new<MaTf>()
ma_data.push(newMa(0))
ma_data.push(newMa(1))
ma_data.push(newMa(2))
ma_data.push(newMa(3))
ma_data.push(newMa(4))

// RSI
change = ta.change(rsiSourceInput)
up = ta.rma(math.max(change, 0), rsiLengthInput)
down = ta.rma(-math.min(change, 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

// Smoothing MA
smoothingMA = enableMA ? rsi_ma(rsi, maLengthInput, maTypeInput) : na
smoothingStDev = isBB ? ta.stdev(rsi, maLengthInput) * bbMultInput : na

// Divergence
lookbackRight = 5
lookbackLeft = 5
rangeUpper = 60
rangeLower = 5
bearColor = color.red
bullColor = color.green
textColor = color.white
noneColor = color.new(color.white, 100)

_inRange(bool cond) =>
    bars = ta.barssince(cond)
    rangeLower <= bars and bars <= rangeUpper

plFound = false
phFound = false

bullCond = false
bearCond = false

rsiLBR = rsi[lookbackRight]

if calculateDivergence
    //------------------------------------------------------------------------------
    // Regular Bullish
    // rsi: Higher Low
    plFound := not na(ta.pivotlow(rsi, lookbackLeft, lookbackRight))    
    rsiHL = rsiLBR > ta.valuewhen(plFound, rsiLBR, 1) and _inRange(plFound[1])
    // Price: Lower Low
    lowLBR = low[lookbackRight]
    priceLL = lowLBR < ta.valuewhen(plFound, lowLBR, 1)
    bullCond := priceLL and rsiHL and plFound

    //------------------------------------------------------------------------------
    // Regular Bearish
    // rsi: Lower High
    phFound := not na(ta.pivothigh(rsi, lookbackLeft, lookbackRight))
    rsiLH = rsiLBR < ta.valuewhen(phFound, rsiLBR, 1) and _inRange(phFound[1])
    // Price: Higher High
    highLBR = high[lookbackRight]
    priceHH = highLBR > ta.valuewhen(phFound, highLBR, 1)
    bearCond := priceHH and rsiLH and phFound
//-----------------------------------------------------------------------------}

// Plot
//-----------------------------------------------------------------------------{

// MA1
ma1 = ma_data.get(0)
ma1_plt = plot(ma1.ma_filled,'MA1',ma1.clr,force_overlay = true)
ma1_h_plt = plot(ma1.h_ma_filled,'MA1 high',ma1.band_clr,force_overlay = true)
ma1_l_plt = plot(ma1.l_ma_filled,'MA1 low',ma1.band_clr,force_overlay = true)
fill(ma1_h_plt,ma1_l_plt,ma1.band_clr)

// MA2
ma2 = ma_data.get(1)
ma2_plt = plot(ma2.ma_filled,'MA2',ma2.clr,force_overlay = true)
ma2_h_plt = plot(ma2.h_ma_filled,'MA2 high',ma2.band_clr,force_overlay = true)
ma2_l_plt = plot(ma2.l_ma_filled,'MA2 low',ma2.band_clr,force_overlay = true)
fill(ma2_h_plt,ma2_l_plt,ma2.band_clr)

// MA3
ma3 = ma_data.get(2)
ma3_plt = plot(ma3.ma_filled,'MA3',ma3.clr,force_overlay = true)
ma3_h_plt = plot(ma3.h_ma_filled,'MA3 high',ma3.band_clr,force_overlay = true)
ma3_l_plt = plot(ma3.l_ma_filled,'MA3 low',ma3.band_clr,force_overlay = true)
fill(ma3_h_plt,ma3_l_plt,ma3.band_clr)

// MA4
ma4 = ma_data.get(3)
ma4_plt = plot(ma4.ma_filled,'MA4',ma4.clr,force_overlay = true)
ma4_h_plt = plot(ma4.h_ma_filled,'MA4 high',ma4.band_clr,force_overlay = true)
ma4_l_plt = plot(ma4.l_ma_filled,'MA4 low',ma4.band_clr,force_overlay = true)
fill(ma4_h_plt,ma4_l_plt,ma4.band_clr)

// RSI
rsiPlot = plot(rsi, "RSI", color=#7E57C2)
rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
midLinePlot = plot(50, color = na, editable = false, display = display.none)
fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100),  title = "Overbought Gradient Fill")
fill(rsiPlot, midLinePlot, 30,  0,  top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0),      title = "Oversold Gradient Fill")

// Smoothing MA plots
plot(smoothingMA, "RSI-based MA", color=color.yellow, display = enableMA ? display.all : display.none, editable = enableMA)
bbUpperBand = plot(smoothingMA + smoothingStDev, title = "Upper Bollinger Band", color=color.green, display = isBB ? display.all : display.none, editable = isBB)
bbLowerBand = plot(smoothingMA - smoothingStDev, title = "Lower Bollinger Band", color=color.green, display = isBB ? display.all : display.none, editable = isBB)
fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill", display = isBB ? display.all : display.none, editable = isBB)

// Divergence
plot(
     plFound   ? rsiLBR : na,
     offset    = -lookbackRight,
     title     = "Regular Bullish",
     linewidth = 2,
     color     = (bullCond ? bullColor : noneColor),
     display   = display.pane,
     editable  = calculateDivergence)

plotshape(
     bullCond  ? rsiLBR : na,
     offset    = -lookbackRight,
     title     = "Regular Bullish Label",
     text      = " Bull ",
     style     = shape.labelup,
     location  = location.absolute,
     color     = bullColor,
     textcolor = textColor,
     display   = display.pane,
     editable  = calculateDivergence)

plot(
     phFound   ? rsiLBR : na,
     offset    = -lookbackRight,
     title     = "Regular Bearish",
     linewidth = 2,
     color     = (bearCond ? bearColor : noneColor),
     display   = display.pane,
     editable  = calculateDivergence)

plotshape(
     bearCond  ? rsiLBR : na,
     offset    = -lookbackRight,
     title     = "Regular Bearish Label",
     text      = " Bear ",
     style     = shape.labeldown,
     location  = location.absolute,
     color     = bearColor,
     textcolor = textColor,
     display   = display.pane,
     editable  = calculateDivergence)

// alertcondition(bullCond, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
// alertcondition(bearCond, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')

Overview

MTF MA bands + RSI calculates up to four configurable moving averages across different timeframes, offering selectable types such as SMA, EMA, and WMA with colored bands. It also computes an RSI oscillator featuring customizable smoothing methods, optional Bollinger Bands, and divergence tracking. The indicator provides visual momentum and trend alignment cues rather than automated trading signals. Higher-timeframe calculations update dynamically on historical and developing bars.

Details

Published by

InNoobWeTrust on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages, Divergence, Trend

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.

Topics

dotfiles

Settings

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

SettingTypeDefaultVariable
Enablebooltruema1_enable
MA typeenumMaType.emama1_type
Lengthint34ma1_len
Colorcolorcolor.new(#FFD921,50)ma1_color
Band Colorcolorcolor.new(#FFD921,80)ma1_band_color
Timeframetimeframema1_tf
Enablebooltruema2_enable
MA typeenumMaType.emama2_type
Lengthint34ma2_len
Colorcolorcolor.new(#DDA059,50)ma2_color
Band Colorcolorcolor.new(#DDA059,80)ma2_band_color
Timeframetimeframe5ma2_tf
Show all 30 settings
SettingTypeDefaultVariable
Enablebooltruema3_enable
MA typeenumMaType.emama3_type
Lengthint34ma3_len
Colorcolorcolor.new(#AA585B,50)ma3_color
Band Colorcolorcolor.new(#AA585B,80)ma3_band_color
Timeframetimeframe30ma3_tf
Enablebooltruema4_enable
MA typeenumMaType.emama4_type
Lengthint34ma4_len
Colorcolorcolor.new(#B52121,50)ma4_color
Band Colorcolorcolor.new(#B52121,80)ma4_band_color
Timeframetimeframe240ma4_tf
RSI Lengthint14rsiLengthInput
SourcesourceclosersiSourceInput
Calculate DivergenceboolfalsecalculateDivergence
TypestringSMAmaTypeInput
Lengthint14maLengthInput
BB StdDevfloat2.0bbMultInput
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

This indicator evaluates how price relates to one selected moving-average family rather than treating a crossover as a signal. It scores trend quality, historical respect of the average, extension, compression, acceleration, and exhaustion, then plots a relati

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]
5 stars

This indicator overlays multiple technical analysis tools onto the price chart to evaluate trend direction and trade setups. It computes an exponential moving average, a smoothed Stochastic RSI, a custom Williams Alligator using smoothed moving averages with o

Indicator v4 TrendMoving averages
Updated 3 years ago · Apache-2.0 GitHub repository of 200 EMA + Alligator + Stochastic

Fractals with Divergence Scanner is an overlay indicator that combines Exponential Moving Averages, an eight-line EMA ribbon cloud, and WaveTrend divergence analysis. It calculates baseline EMA trends alongside WaveTrend oscillators to detect regular and hidde

Indicator v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of Fractals with Divergence Scanner
2 stars

ARPS Ultimate MultiStrategy Trading combines multiple technical indicators into a single chart overlay. It calculates and plots trend lines, moving averages, Ichimoku cloud components, Williams Alligator lines, and Fibonacci support and resistance levels direc

Indicator v4 TrendOscillators & momentum
Updated 6 months ago · None stated GitHub repository of ARPS Ultimate MultiStrategy Trading

Complexity Trender

by panzmoravylab
2 stars

Complexity Trender is an indicator that combines EMA crossovers, RSI momentum, Stochastic signals, Bollinger Bands, ADX trend strength, volume analysis, and divergence detection to identify trends. It plots labels, trend lines, and a summary table directly on

Indicator v6 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Complexity Trender

This multi-timeframe indicator combines higher-timeframe trend analysis, MACD divergence detection, and short-term oscillator timing to identify trading opportunities on GBPJPY. It evaluates trend direction using a 4-hour EMA, locates MACD divergences with Zig

Indicator v6 DivergenceOscillators & momentum

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