Pine Script v5 · Indicator
Moving Average Ribbon
A Pine Script v5 indicator built on SMA or WMA or RMA or HMA or EMA (close, 20). It draws 4 lines on the price chart. It declares 2 alerts. 6 settings; defaults include Average type EMA, Source close and Length 1 20.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Moving Average Ribbon repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 300 of 300 bars.
- How many settings does Moving Average Ribbon have?
- 6
- Defaults include Average type EMA, Source close, Length 1 20.
- What alerts does Moving Average Ribbon have?
- 2
- Ribbon stacked up; Ribbon stacked down.
- Does Moving Average Ribbon run in Pine Script v6?
- Yes
- Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Moving Average Ribbon draw on the price chart?
- Yes
- It is declared with overlay = true.
BTCUSDT · 1D · default settings
- MA 1
- MA 2
- MA 3
- MA 4
- MA 1
- 82,813.50
- on the last bar
- MA 2
- 80,839.40
- on the last bar
- MA 3
- 77,373.10
- on the last bar
- MA 4
- 76,126.60
- on the last bar
The value of each line the script plots, on the last of 1,000 bars, with the default settings.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
Nothing to point out.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Average type | EMA | string · options ["SMA", "EMA", "WMA", "RMA", "HMA"] | ma1 ma2 ma3 ma4 |
| Source | close | source | ma1 ma2 ma3 ma4 |
| Length 1 | 20 | int · min 1 | ma1 |
| Length 2 | 50 | int · min 1 | ma2 |
| Length 3 | 100 | int · min 1 | ma3 |
| Length 4 | 200 | int · min 1 | ma4 |
What it calculates
- SMA / WMA / RMA / HMA / EMASource (close), Length 1 (20) · chosen by Average type
ma1 · line 17 - SMA / WMA / RMA / HMA / EMASource (close), Length 2 (50) · chosen by Average type
ma2 · line 23 - SMA / WMA / RMA / HMA / EMASource (close), Length 3 (100) · chosen by Average type
ma3 · line 29 - SMA / WMA / RMA / HMA / EMASource (close), Length 4 (200) · chosen by Average type
ma4 · line 35
Signal flow
How price data and settings reach what is drawn. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
What it draws
| Output | Call | Value | By default | Line |
|---|---|---|---|---|
| MA 1 | plot | ma1 | Shown | 45 |
| MA 2 | plot | ma2 | Shown | 46 |
| MA 3 | plot | ma3 | Shown | 47 |
| MA 4 | plot | ma4 | Shown | 48 |
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Ribbon stacked up | alertcondition | Moving averages are stacked in rising order | 50 |
| Ribbon stacked down | alertcondition | Moving averages are stacked in falling order | 51 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip or realtime-only state. Values move while a bar forms and settle when it closes, as every indicator's do.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets, each the most recent 1,000 bars.
| Market | MA 1 | MA 2 | MA 3 | MA 4 |
|---|---|---|---|---|
| BTCUSDT 1D | 82,813.50 | 80,839.40 | 77,373.10 | 76,126.60 |
| BTCUSDT 4h | 82,948.80 | 82,622.00 | 82,752.80 | 82,130.00 |
| ETHUSDT 1D | 2,498.61 | 2,482.29 | 2,363.94 | 2,317.10 |
| ETHUSDT 4h | 2,446.31 | 2,450.70 | 2,489.41 | 2,512.36 |
| SOLUSDT 1D | 108.71 | 106.84 | 100.19 | 98.08 |
| SOLUSDT 4h | 106.06 | 106.28 | 108.29 | 108.87 |
| BNBUSDT 1D | 743.50 | 733.58 | 703.47 | 688.68 |
| BNBUSDT 4h | 737.48 | 735.20 | 741.10 | 742.19 |
Each line's value on the last bar.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type |
|---|---|---|
| Smoothed Heikin Ashi Trend on Chart - TraderHalai BACKTEST by TraderHalai | sma ema hma rma | v5 strategy |
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy |
| RMI + Triple HMRSI + Double EVWRSI + TERSI + CMO Strategy by burgercrisis | rma hma ema | v4 strategy |
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © Zeal Terminal-//@version=5+//@version=6indicator("Moving Average Ribbon", shorttitle = "MA Ribbon", overlay = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 11 ms | Yes 1,000 bars in 33 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Written by Zeal Terminal and published under the Mozilla Public License 2.0.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Zeal Terminal//@version=5indicator("Moving Average Ribbon", shorttitle = "MA Ribbon", overlay = true) // Four moving averages of one type. The ribbon fans out in a trend and// tangles in a range.maType = input.string("EMA", "Average type", options = ["SMA", "EMA", "WMA", "RMA", "HMA"])src = input.source(close, "Source")len1 = input.int(20, "Length 1", minval = 1)len2 = input.int(50, "Length 2", minval = 1)len3 = input.int(100, "Length 3", minval = 1)len4 = input.int(200, "Length 4", minval = 1) // The type is a setting, so one branch runs on every bar and each average// keeps its own history.ma1 = switch maType "SMA" => ta.sma(src, len1) "WMA" => ta.wma(src, len1) "RMA" => ta.rma(src, len1) "HMA" => ta.hma(src, len1) => ta.ema(src, len1)ma2 = switch maType "SMA" => ta.sma(src, len2) "WMA" => ta.wma(src, len2) "RMA" => ta.rma(src, len2) "HMA" => ta.hma(src, len2) => ta.ema(src, len2)ma3 = switch maType "SMA" => ta.sma(src, len3) "WMA" => ta.wma(src, len3) "RMA" => ta.rma(src, len3) "HMA" => ta.hma(src, len3) => ta.ema(src, len3)ma4 = switch maType "SMA" => ta.sma(src, len4) "WMA" => ta.wma(src, len4) "RMA" => ta.rma(src, len4) "HMA" => ta.hma(src, len4) => ta.ema(src, len4) stacked = ma1 > ma2 and ma2 > ma3 and ma3 > ma4inverse = ma1 < ma2 and ma2 < ma3 and ma3 < ma4 plot(ma1, "MA 1", color = #4dd0e1, linewidth = 2)plot(ma2, "MA 2", color = #26a69a)plot(ma3, "MA 3", color = #ffb74d)plot(ma4, "MA 4", color = #ef5350, linewidth = 2) alertcondition(stacked and not stacked[1], "Ribbon stacked up", "Moving averages are stacked in rising order")alertcondition(inverse and not inverse[1], "Ribbon stacked down", "Moving averages are stacked in falling order")