Indicator · Pine Script v6 · Own pane

3D MACD Bar Plot [LuxAlgo]

by MeridianAlgo· code credited to LuxAlgo

This indicator projects a three-dimensional surface plot of multiple MACD calculations in a separate indicator pane.

View on GitHub

GitHub stars9on the repository
Pine versionv6current
Lines of code180
Settings12inputs
LicenceMIT
Last update4 months ago29 Jun 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

180 lines of Pine Script v6 from examples/3D_MACD_Bar_Plot_LuxAlgo.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

3D_MACD_Bar_Plot_LuxAlgo.pine
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=6
indicator("3D MACD Bar Plot [LuxAlgo]", "LuxAlgo - 3D MACD Bar Plot", overlay = false, max_lines_count = 500, max_labels_count = 500, max_polylines_count = 100)

//---------------------------------------------------------------------------------------------------------------------}
// Constants
//---------------------------------------------------------------------------------------------------------------------{


//---------------------------------------------------------------------------------------------------------------------}
// Inputs
//---------------------------------------------------------------------------------------------------------------------{
string GRID_GRP = 'Grid Configuration'
fastMinInput    = input.int(5,   'Fast Min Length', minval = 2, group = GRID_GRP)
fastMaxInput    = input.int(25,  'Fast Max Length', minval = 2, group = GRID_GRP)
fastStepInput   = input.int(5,   'Fast Step',       minval = 1, group = GRID_GRP)

slowMinInput    = input.int(10,  'Slow Min Length', minval = 2, group = GRID_GRP)
slowMaxInput    = input.int(50,  'Slow Max Length', minval = 2, group = GRID_GRP)
slowStepInput   = input.int(10,  'Slow Step',       minval = 1, group = GRID_GRP)

string PROJ_GRP = '3D Projection Settings'
yOffsetInput    = input.float(0.0, 'Y Baseline Price',               group = PROJ_GRP)
scaleXInput     = input.float(3.0, 'X Spacing (bars)',               group = PROJ_GRP)
scaleZInput     = input.float(5.0, 'Z Height (Relative to Y Spacing)', group = PROJ_GRP)

string STYLE_GRP = 'Style'
bullColorInput   = input.color(#089981, 'Bullish Color', group = STYLE_GRP)
bearColorInput   = input.color(#f23645, 'Bearish Color', group = STYLE_GRP)
gridColorInput   = input.color(#808080, 'Grid Color',    group = STYLE_GRP)

//---------------------------------------------------------------------------------------------------------------------}
// Calculations
//---------------------------------------------------------------------------------------------------------------------{
var emaStates     = map.new<int, float>()
var uniqueLengths = array.new_int()

if bar_index == 0
    for f = fastMinInput to fastMaxInput by fastStepInput
        if not uniqueLengths.includes(f)
            uniqueLengths.push(f)
    for s = slowMinInput to slowMaxInput by slowStepInput
        if not uniqueLengths.includes(s)
            uniqueLengths.push(s)

for length in uniqueLengths
    float alpha   = 2.0 / (length + 1.0)
    float prevEma = emaStates.get(length)
    
    if na(prevEma)
        emaStates.put(length, close)
    else
        emaStates.put(length, close * alpha + prevEma * (1.0 - alpha))

//---------------------------------------------------------------------------------------------------------------------}
// Functions
//---------------------------------------------------------------------------------------------------------------------{
// Continuous snaking path for a grid (Rows then Columns)
generateGridPath(matrix<chart.point> pts, int rows, int cols) =>
    array<chart.point> path = array.new<chart.point>()
    // 1. Traverse Rows (Snaking)
    for r = 0 to rows - 1
        if r % 2 == 0
            for c = 0 to cols - 1
                path.push(pts.get(r, c))
        else
            for c = cols - 1 to 0
                path.push(pts.get(r, c))
    
    // 2. Traverse Columns (Snaking, starting from current corner)
    int currC = (rows - 1) % 2 == 0 ? cols - 1 : 0
    if currC == cols - 1
        for c = cols - 1 to 0
            int colIdx = cols - 1 - c
            if colIdx % 2 == 0
                for r = rows - 1 to 0
                    path.push(pts.get(r, c))
            else
                for r = 0 to rows - 1
                    path.push(pts.get(r, c))
    else
        for c = 0 to cols - 1
            if c % 2 == 0
                for r = rows - 1 to 0
                    path.push(pts.get(r, c))
            else
                for r = 0 to rows - 1
                    path.push(pts.get(r, c))
    path

//---------------------------------------------------------------------------------------------------------------------}
// Drawing Storage & Cleanup
//---------------------------------------------------------------------------------------------------------------------{
var linesArray     = array.new<line>()
var labelsArray    = array.new<label>()
var polylinesArray = array.new<polyline>()

if barstate.islast
    // 1. Cleanup old drawings
    while array.size(linesArray) > 0
        line.delete(array.pop(linesArray))
    while array.size(labelsArray) > 0
        label.delete(array.pop(labelsArray))
    while array.size(polylinesArray) > 0
        polyline.delete(array.pop(polylinesArray))

    // 2. Base coordinates
    float basePrice = yOffsetInput
    int   baseBar   = bar_index
    float yStep     = 1.0
    
    // 3. Normalization logic
    float macdMax = 0.0
    for f = fastMinInput to fastMaxInput by fastStepInput
        for s = slowMinInput to slowMaxInput by slowStepInput
            float val = math.abs(emaStates.get(f) - emaStates.get(s))
            if val > macdMax
                macdMax := val
    
    float zMultiplier = macdMax != 0 ? (scaleZInput * yStep) / macdMax : 1.0
    
    // 4. Grid dimensions and matrices
    int fCount = 0
    for f = fastMinInput to fastMaxInput by fastStepInput
        fCount += 1
    int sCount = 0
    for s = slowMinInput to slowMaxInput by slowStepInput
        sCount += 1
        
    int maxDepth = math.max(1, (fCount - 1) + (sCount - 1))
    
    matrix<chart.point> topPoints  = matrix.new<chart.point>(fCount, sCount)
    matrix<chart.point> basePoints = matrix.new<chart.point>(fCount, sCount)
    
    int i = 0
    for f = fastMinInput to fastMaxInput by fastStepInput
        int j = 0
        for s = slowMinInput to slowMaxInput by slowStepInput
            float fEma = emaStates.get(f)
            float sEma = emaStates.get(s)
            float macd = fEma - sEma
            
            float depthFactor = (i + j) / maxDepth
            float barTransp   = 10 + (depthFactor * 70)
            int   barWidth    = int(6 - (5 * depthFactor))

            int screenX  = baseBar + int((i - j) * scaleXInput)
            float screenYB = basePrice + (i + j) * yStep
            float screenYT = screenYB + macd * zMultiplier
            
            chart.point pBase = chart.point.from_index(screenX, screenYB)
            chart.point pTop  = chart.point.from_index(screenX, screenYT)
            
            topPoints.set(i, j, pTop)
            basePoints.set(i, j, pBase)
            
            color barCol = macd >= 0 ? bullColorInput : bearColorInput
            linesArray.push(line.new(pBase, pTop, color = color.new(barCol, barTransp), width = barWidth))
            if i == 0 and j == 0
                labelsArray.push(label.new(pBase, "Origin (F" + str.tostring(f) + ", S" + str.tostring(s) + ")", style = label.style_label_up, textcolor = chart.fg_color, color = #00000000, size = size.small))
            
            if j == 0 and i == fCount - 1
                labelsArray.push(label.new(pBase, "Fast Axis (F" + str.tostring(f) + ")", style = label.style_label_left, textcolor = chart.fg_color, color = #00000000, size = size.small))
            
            if i == 0 and j == sCount - 1
                labelsArray.push(label.new(pBase, "Slow Axis (S" + str.tostring(s) + ")", style = label.style_label_right, textcolor = chart.fg_color, color = #00000000, size = size.small))

            j += 1
        i += 1
        
    // 5. Draw Grid and Surface using Single Polylines
    array<chart.point> surfacePath = generateGridPath(topPoints, fCount, sCount)
    array<chart.point> gridPath    = generateGridPath(basePoints, fCount, sCount)

    polylinesArray.push(polyline.new(surfacePath, line_color = color.new(gridColorInput, 40)))
    polylinesArray.push(polyline.new(gridPath,    line_color = color.new(gridColorInput, 70)))

//---------------------------------------------------------------------------------------------------------------------}

Overview

3D MACD Bar Plot [LuxAlgo] calculates exponential moving averages across ranges of fast and slow periods defined by user-selected minimum, maximum, and step parameters. The script then builds a grid of points using continuous polyline paths to render a 3D visual mesh. Inputs allow full control over EMA length ranges, baseline price offsets, spatial spacing, height scaling, and bullish/bearish color schemes.

Details

Published by

MeridianAlgo on GitHub

Code credit

LuxAlgo, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Moving averages

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

code-converterconverterjavascriptpinescripttranspilercode-reviewmeridianalgocode-conversionpinescript-algorithms

Settings

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

SettingTypeDefaultVariable
Fast Min Lengthint5fastMinInput
Fast Max Lengthint25fastMaxInput
Fast Stepint5fastStepInput
Slow Min Lengthint10slowMinInput
Slow Max Lengthint50slowMaxInput
Slow Stepint10slowStepInput
Y Baseline Pricefloat0.0yOffsetInput
X Spacing (bars)float3.0scaleXInput
Z Height (Relative to Y Spacing)float5.0scaleZInput
Bullish Colorcolor#089981bullColorInput
Bearish Colorcolor#f23645bearColorInput
Grid Colorcolor#808080gridColorInput
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

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

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

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
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

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