Indicator · Pine Script v5 · Own pane

Moving Averages 3D

by regalouisei· code credited to LonesomeTheBlue

This indicator calculates ten sequential moving averages using either simple or exponential moving averages and renders them as a pseudo-three-dimensional grid in a separate pane.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code71
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago25 Feb 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

71 lines of Pine Script v5 from pinescript/editors_picks/moving-averages-3d.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

moving-averages-3d.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue

//@version=5
indicator("Moving Averages 3D", max_lines_count = 500)
matype = input.string(defval = 'SMA', title = 'Moving Average Type', options = ['EMA', 'SMA'])
len1 = input.int(defval = 10, title = 'Starting Length', minval = 5, inline = 'len')
step = input.int(defval = 5, title = 'Step', minval = 1, inline = 'len')
colorup = input.string(defval = 'Green', title = 'Colors', options = ['Green', 'Red', 'Blue'], inline = 'colors')
colordown = input.string(defval = 'Red', title = '', options = ['Green', 'Red', 'Blue'], inline = 'colors')
width = input.int(defval = 2, title = 'Width', minval = 1, maxval = 5)

var lines = array.new_line(500)
for x = 0 to array.size(lines) - 1
    line.delete(array.get(lines, x))

get_ma(length)=>
    (matype == 'EMA' ? ta.ema(close, length) : ta.sma(close, length))

var sma1 = array.new_float(50, na),     array.unshift(sma1, get_ma(len1 + 9 * step)), array.pop(sma1)
var sma2 = array.new_float(50, na),     array.unshift(sma2, get_ma(len1 + 8 * step)),  array.pop(sma2)
var sma3 = array.new_float(50, na),     array.unshift(sma3, get_ma(len1 + 7 * step)),  array.pop(sma3)
var sma4 = array.new_float(50, na),     array.unshift(sma4, get_ma(len1 + 6 * step)),  array.pop(sma4)
var sma5 = array.new_float(50, na),     array.unshift(sma5, get_ma(len1 + 5 * step)),  array.pop(sma5)
var sma6 = array.new_float(50, na),     array.unshift(sma6, get_ma(len1 + 4 * step)),  array.pop(sma6)
var sma7 = array.new_float(50, na),     array.unshift(sma7, get_ma(len1 + 3 * step)),  array.pop(sma7)
var sma8 = array.new_float(50, na),     array.unshift(sma8, get_ma(len1 + 2 * step)),  array.pop(sma8)
var sma9 = array.new_float(50, na),     array.unshift(sma9, get_ma(len1 + 1 * step)),  array.pop(sma9)
var sma10 = array.new_float(50, na),    array.unshift(sma10, get_ma(len1 + 0 * step)), array.pop(sma10)

get_array(array, element)=>
    array == 1 ? array.get(sma1, element) : 
     array == 2 ? array.get(sma2, element) : 
     array == 3 ? array.get(sma3, element) :
     array == 4 ? array.get(sma4, element) :
     array == 5 ? array.get(sma5, element) :
     array == 6 ? array.get(sma6, element) :
     array == 7 ? array.get(sma7, element) :
     array == 8 ? array.get(sma8, element) :
     array == 9 ? array.get(sma9, element) :
     array.get(sma10, element)

cwidth = (ta.highest(200) - ta.lowest(200)) / 200
cwidthcolor = (ta.highest(200) - ta.lowest(200)) / 4000
get_min_max(value)=>
    math.min(math.max(value, 0), 255)
    
get_color(value1, value2)=>
    diff = math.round((value2 - value1) / cwidthcolor)
    red = colorup == 'Red' ? get_min_max(128 + diff) : 
          colordown == 'Red' ? get_min_max(128 - diff) : 0
    green = colorup == 'Green' ? get_min_max(128 + diff) : 
          colordown == 'Green' ? get_min_max(128 - diff) : 0
    blue = colorup == 'Blue' ? get_min_max(128 + diff) : 
          colordown == 'Blue' ? get_min_max(128 - diff) : 0
    color.rgb(red, green, blue, 0)
    
base = array.get(sma1, 0)
if barstate.islast
    for x = 39 to 0
        b1 = base + x * cwidth
        b2 = base + (x + 1) * cwidth
        for y = 10 to 1
            array.set(lines, x + 40 * y, line.new(x1 = bar_index - 5 * (10 - y) - x * width, 
                                                  y1 = b1 + cwidth * y * 10 + get_array(y, x) - array.get(sma1, 0), 
                                                  x2 = bar_index - 5 * (10 - y) - x * width - width, 
                                                  y2 = b2 + cwidth * y * 10 + get_array(y, x + 1) - array.get(sma1, 0),
                                                  color = color.new(color.black, 50), style = line.style_dotted))
            
            if y < 10
                linefill.new(array.get(lines, x + 40 * y), array.get(lines, x + 40 * (y + 1)), color = get_color(get_array(y, x + 1), get_array(y, x)))

Overview

Moving Averages 3D projects recent price trends through an array of dynamically colored line drawings that update on the latest bar. Users can configure the moving average type, base length, step increment between successive lines, line width, and directional colors. The script functions purely as a visual representation without generating trading signals, and it renders only on the most recent bar without maintaining historical line plots.

Details

Published by

regalouisei on GitHub

Code credit

LonesomeTheBlue, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Moving averages, 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.

Settings

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

SettingTypeDefaultVariable
Moving Average TypestringSMAmatype
Starting Lengthint10len1
Stepint5step
ColorsstringGreencolorup
colordownstringRedcolordown
Widthint2width
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 4 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