Indicator · Pine Script v6 · Own pane

MACD Support and Resistance [ChartPrime]

by theonetrade· code credited to ChartPrime

Calculates a MACD oscillator using customizable fast, slow, and signal lengths with SMA or EMA options.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code125
Settings8inputs
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

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

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

//@version=6
indicator(title="MACD Support and Resistance [ChartPrime]", shorttitle="MACD S/R [ChartPrime]")


// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{

fast_length = input(title = "Fast Length", defval = 12)
slow_length = input(title = "Slow Length", defval = 26)
src = input(title = "Source", defval = close)
signal_length = input.int(title = "Signal Smoothing",  minval = 1, maxval = 50, defval = 9, display = display.data_window)
sma_source = input.string(title = "Oscillator MA Type",  defval = "EMA", options = ["SMA", "EMA"], display = display.data_window)
sma_signal = input.string(title = "Signal Line MA Type", defval = "EMA", options = ["SMA", "EMA"], display = display.data_window)

col_up = input.color(#2962FF, "", inline = "color")
col_dn = input.color(#FF6D00, "", inline = "color")


// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{

fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)

macd_col = macd > signal ? col_up : col_dn

type level 
    bool issupport
    float lvl 
    int start


var s_r_levels = array.new<level>()

if ta.crossunder(macd, signal)
    max = array.new<float>()

    for i = 0 to 5
        h = high[i]
        max.push(h)

    for i = 0 to 5
        h = high[i]
        if h == max.max()

            sr = level.new(false, max.max(), bar_index-i)
            s_r_levels.push(sr)


if ta.crossover(macd, signal)
    min = array.new<float>()

    for i = 0 to 5
        l = low[i]
        min.push(l)

    for i = 0 to 5
        l = low[i]
        if l == min.min()

            sr = level.new(true, min.min(), bar_index-i)
            s_r_levels.push(sr)

// Max amount of Levels 20
if s_r_levels.size() > 20
    s_r_levels.shift()

// Remove crossed levels
if s_r_levels.size() > 0
    
    for i = 0 to s_r_levels.size() - 1

        sr = s_r_levels.get(i)
        start = sr.start 
        is_sup = sr.issupport
        level_ = sr.lvl

        if bar_index > start and is_sup and low < level_
            s_r_levels.remove(s_r_levels.indexof(sr))

        if bar_index > start and not is_sup and high > level_
            s_r_levels.remove(s_r_levels.indexof(sr))



// --------------------------------------------------------------------------------------------------------------------}
// 📌 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{

    for sr in s_r_levels 

        start = sr.start 
        is_sup = sr.issupport
        level_ = sr.lvl

        col = is_sup ? col_up : col_dn

        line.new(start, level_, bar_index, level_, color = col, force_overlay = true)

        label.new(start, level_, "", style = label.style_diamond, color = col, force_overlay = true, size = size.tiny)
        label.delete(label.new(bar_index, level_, str.tostring(level_), style = label.style_label_left, color = col, force_overlay = true, size = size.small)[1])


hline(0, "Zero Line", color = color.new(#787B86, 30))

pm = plot(macd,   title = "MACD",   color = macd_col, display = display.none)
ps = plot(signal, title = "Signal", color = macd_col, linewidth = 2)

fill(pm, ps, color.new(macd_col, 70))


plotshape(ta.crossover(macd, signal) ? signal : float(na), "Macd UP", style = shape.diamond, location = location.absolute, size = size.tiny, color = macd_col)
plotshape(ta.crossunder(macd, signal) ? signal : float(na), "Macd DN", style = shape.diamond, location = location.absolute, size = size.tiny, color = macd_col)

plot(ta.highest(macd, 100), "Local high", color = bar_index % 5 == 0 or bar_index % 4 == 0 or bar_index % 3 == 0 ? na : color.new(#787B86, 30))
plot(ta.lowest(macd, 100), "Local Low", color = bar_index % 5 == 0 or bar_index % 4 == 0 or bar_index % 3 == 0 ? na : color.new(#787B86, 30))

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

Overview

When MACD crossovers or crossunders occur, the indicator identifies local swing highs or lows across recent bars to establish support and resistance levels on the chart. Up to 20 active levels are tracked, and lines are automatically removed once price breaks through them.

Details

Published by

theonetrade on GitHub

Code credit

ChartPrime, as written in the script's header

Draws

Separate pane below the 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
Fast Lengthint12fast_length
Slow Lengthint26slow_length
Sourcesourceclosesrc
Signal Smoothingint9signal_length
Oscillator MA TypestringEMAsma_source
Signal Line MA TypestringEMAsma_signal
col_upcolor#2962FFcol_up
col_dncolor#FF6D00col_dn
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

114 stars

This indicator combines a scaled Forecast Oscillator with a Point of Force state detector. The Forecast Oscillator calculates the percentage deviation of price from its linear regression curve and normalizes the output between 0 and 1, plotting a line in a sep

Indicator v4 Oscillators & momentumSupport & resistance Repaints

CCI DC

by be-thomas
65 stars

This indicator plots the Commodity Channel Index in a separate pane and surrounds it with a Donchian channel whose lookback length changes with volatility. It measures volatility as a ratio of short and long ATR values, then ranks that ratio and shortens or le

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 weeks ago · GPL-3.0 GitHub repository of CCI DC

WaveTrend 3D

by nersent
29 stars

WaveTrend 3D is a redesigned oscillator that implements the classic WaveTrend algorithm with kernel-based regression for trend reversal confirmation and multi-timeframe support. It calculates a smoothed oscillator line and displays a symmetrical three-dimensio

Indicator v5 Oscillators & momentumDivergence
Updated 1 year ago · Custom licence GitHub repository of WaveTrend 3D

Benso Pendulum

by benso87
24 stars

Benso Pendulum is an indicator that plots a customizable Relative Strength Index (RSI) oscillator in a separate pane on the price chart. It calculates the RSI using the specified source and period, applying dynamic colors that change based on overbought and ov

Indicator v5 Oscillators & momentumSupport & resistance
Updated 4 years ago · MPL-2.0 GitHub repository of Benso Pendulum

QFA Pro Elite Refined

by JasonTeixeira
11 stars

This indicator plots a smoothed fear index in a separate pane. It measures how far the current low sits below the highest close over a lookback, scales that reading by an ATR percentile, and smooths it with a zero-lag EMA. A volatility regime raises or lowers

Indicator v6 Oscillators & momentumVolatility & bands
Updated 5 weeks ago · Custom licence GitHub repository of QFA Pro Elite Refined

More Oscillators & momentum 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