Indicator · Pine Script v4 · On the chart

Madrid Moving Average Ribbon

by theonetrade

The Madrid Moving Average Ribbon calculates and plots a collection of moving averages directly on the price chart to create a ribbon visualization.

View on GitHub

GitHub stars34on the repository
Pine versionv4older, still runs
Lines of code164
Settings2inputs
LicenceMIT
Last update2 weeks ago8 Nov 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

164 lines of Pine Script v4 from assets/indicator/bit-exact/madrid_moving_average_ribbon_1JKqmEKy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

madrid_moving_average_ribbon_1JKqmEKy.pine
//@version=4

// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║                                                                              ║
// ║ © Madrid : 141017TH2251                                                      ║
// ║                                                                              ║
// ║ Rev. 210306SA1836 : Upgrade to Pinescript 4                                  ║
// ║                                                                              ║
// ║ Madrid Moving Average Ribbon                                                 ║
// ║                                                                              ║
// ║ This plots a moving average ribbon, either exponential or standard.          ║
// ║ This study is best viewed with a dark background.  It provides an easy       ║
// ║ and fast way to determine the trend direction and possible reversals.        ║
// ║                                                                              ║
// ║ Lime : Uptrend. Long trading                                                 ║
// ║ Green : Reentry (buy the dip) or downtrend reversal warning                  ║
// ║ Red : Downtrend. Short trading                                               ║
// ║ Maroon : Short Reentry (sell the peak) or uptrend reversal warning           ║
// ║                                                                              ║
// ║ To best determine if this is a reentry point or a trend reversal             ║
// ║ the MMARB (Madrid Moving Average Ribbon Bar) study is used.                  ║
// ║ This is the bar located at the bottom.  This bar signals when a              ║
// ║ current trend reentry is found (partially filled with opposite dark color)   ║
// ║ or when a trend reversal is ahead (filled with the opposite color.           ║
// ║                                                                              ║
// ║ This source code is subject to the terms of the Mozilla Public License 2.0   ║
// ║ at https://mozilla.org/MPL/2.0/                                              ║
// ║                                                                              ║
// ╚══════════════════════════════════════════════════════════════════════════════╝

study("Madrid Moving Average Ribbon", shorttitle="Madrid Ribbon", overlay=true)


// ╔══════════════════════════════════════╗
// ║                                      ║
// ║            CONSTANTS                 ║
// ║                                      ║
// ╚══════════════════════════════════════╝

PHI     = ( 1 + sqrt(5) ) / 2
PI   = 104348/33215

BULL = 1
BEAR = -1
NONE = 0

// ╔══════════════════════════════════════╗
// ║                                      ║
// ║            Colors                    ║
// ║                                      ║
// ╚══════════════════════════════════════╝


// v3 Style Gradient
GRN01 = #7CFC00, GRN02 = #32CD32, GRN03 = #228B22, GRN04 = #006400, GRN05 = #008000, GRN06=#093507
RED01 = #FF4500, RED02 = #FF0000, RED03 = #B22222, RED04 = #8B0000, RED05 = #800000, RED06=#330d06



// ──────────[ v3 Style Colors ]
AQUA    = #00FFFF
BLACK   = #000000
BLUE    = #0000FF
FUCHSIA = #FF00FF
GRAY    = #808080
GREEN   = #008000
LIME    = #00FF00
MAROON  = #800000
NAVY    = #000080
OLIVE   = #808000
ORANGE  = #FF7F00
PURPLE  = #800080
RUBI    = #FF0000
SILVER  = #C0C0C0
TEAL    = #008080
YELLOW  = #FFFF00
WHITE   = #FFFFFF 



// ╔══════════════════════════════════════╗
// ║                                      ║
// ║            functions ()              ║
// ║                                      ║
// ╚══════════════════════════════════════╝


// ──────────[ Moving Average Color ]
//  
maColor(_ma, _maRef) =>
    diffMA = change(_ma)
    macol = diffMA>=0 and _ma>_maRef ? LIME : diffMA<0 and _ma>_maRef ? MAROON : diffMA<=0 and _ma<_maRef ? RUBI : diffMA>=0 and _ma<_maRef ? GREEN : GRAY
            


// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║                                                                              ║
// ║                                main ( )                                      ║
// ║                                                                              ║
// ╚══════════════════════════════════════════════════════════════════════════════╝


// ────────────────────[ Input Parameters ]

_10   = input(false, '───────────[ Madrid Ribbon]───────────' )
i_exp = input(true ,  title="Expnential MA")




// ────────────────────[ Processing ]

src = close

ma05  = i_exp ? ema(src, 05) : sma(src, 05)
ma10  = i_exp ? ema(src, 10) : sma(src, 10)
ma15  = i_exp ? ema(src, 15) : sma(src, 15)
ma20  = i_exp ? ema(src, 20) : sma(src, 20)
ma25  = i_exp ? ema(src, 25) : sma(src, 25)
ma30  = i_exp ? ema(src, 30) : sma(src, 30)
ma35  = i_exp ? ema(src, 35) : sma(src, 35)
ma40  = i_exp ? ema(src, 40) : sma(src, 40)
ma45  = i_exp ? ema(src, 45) : sma(src, 45)
ma50  = i_exp ? ema(src, 50) : sma(src, 50)
ma55  = i_exp ? ema(src, 55) : sma(src, 55)
ma60  = i_exp ? ema(src, 60) : sma(src, 60)
ma65  = i_exp ? ema(src, 65) : sma(src, 65)
ma70  = i_exp ? ema(src, 70) : sma(src, 70)
ma75  = i_exp ? ema(src, 75) : sma(src, 75)
ma80  = i_exp ? ema(src, 80) : sma(src, 80)
ma85  = i_exp ? ema(src, 85) : sma(src, 85)
ma90  = i_exp ? ema(src, 90) : sma(src, 90)
ma100 = i_exp ? ema(src, 100): sma(src, 100)



// ────────────────────[ Plot ]
//
plot( ma05, color=maColor(ma05,ma100), style=plot.style_line, title="MMA05", linewidth=3)
plot( ma10, color=maColor(ma10,ma100), style=plot.style_line, title="MMA10", linewidth=1)
plot( ma15, color=maColor(ma15,ma100), style=plot.style_line, title="MMA15", linewidth=1)
plot( ma20, color=maColor(ma20,ma100), style=plot.style_line, title="MMA20", linewidth=1)
plot( ma25, color=maColor(ma25,ma100), style=plot.style_line, title="MMA25", linewidth=1)
plot( ma30, color=maColor(ma30,ma100), style=plot.style_line, title="MMA30", linewidth=1)
plot( ma35, color=maColor(ma35,ma100), style=plot.style_line, title="MMA35", linewidth=1)
plot( ma40, color=maColor(ma40,ma100), style=plot.style_line, title="MMA40", linewidth=1)
plot( ma45, color=maColor(ma45,ma100), style=plot.style_line, title="MMA45", linewidth=1)
plot( ma50, color=maColor(ma50,ma100), style=plot.style_line, title="MMA50", linewidth=1)
plot( ma55, color=maColor(ma55,ma100), style=plot.style_line, title="MMA55", linewidth=1)
plot( ma60, color=maColor(ma60,ma100), style=plot.style_line, title="MMA60", linewidth=1)
plot( ma65, color=maColor(ma65,ma100), style=plot.style_line, title="MMA65", linewidth=1)
plot( ma70, color=maColor(ma70,ma100), style=plot.style_line, title="MMA70", linewidth=1)
plot( ma75, color=maColor(ma75,ma100), style=plot.style_line, title="MMA75", linewidth=1)
plot( ma80, color=maColor(ma80,ma100), style=plot.style_line, title="MMA80", linewidth=1)
plot( ma85, color=maColor(ma85,ma100), style=plot.style_line, title="MMA85", linewidth=1)
plot( ma90, color=maColor(ma90,ma100), style=plot.style_line, title="MMA90", linewidth=3)



// ╔══════════════════════════════════════════════════════════════════════════════╗
// ║                                                                              ║
// ║                That's all Folks !                                            ║
// ║                                                                              ║
// ╚══════════════════════════════════════════════════════════════════════════════╝

Overview

Users can toggle between exponential and simple moving averages using the inputs. The ribbon changes colors across different shades of green and red to help traders identify prevailing trend direction, potential pullback re-entry opportunities, and upcoming trend reversal warnings.

Details

Published by

theonetrade on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

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

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

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

SettingTypeDefaultVariable
───────────[ Madrid Ribbon]───────────boolfalse_10
Expnential MAbooltruei_exp
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

947 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 5 weeks ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
368 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
321 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 8 days ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 4 weeks ago · MIT GitHub repository of NVDA Trend Ribbon
257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 2 months ago · None stated GitHub repository of Donald SPX - Options Trading
228 stars

This indicator computes moving average and RSI bias signals across the current timeframe and four higher timeframes. It sums biases from the MA and RSI to derive an overall bullish or bearish signal. The results appear in a configurable table that displays eac

Indicator v6 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Template

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers