Indicator · Pine Script v4 · Own pane

MACD + RSI Robert's Version

by Rvannest

A Pine v4 indicator in a separate pane that combines MACD and RSI.

View on GitHub

GitHub stars1on the repository
Pine versionv4older, still runs
Lines of code52
Settings7inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago12 Feb 2024

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

52 lines of Pine Script v4 from MACDandRSI.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

MACDandRSI.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=4

// https://www.tradingview.com/script/7CFXv2my-MACD-RSI-Robert-s-Version/

study(title="MACD + RSI Robert's Version", shorttitle="MACD and RSI")

// MACD
src = input(title="Source", type=input.source, defval=close)
fast_length = input(title="MACD Fast Length", type=input.integer, defval=12)
slow_length = input(title="MACD Slow Length", type=input.integer, defval=26)
signal_length = input(title="MACD Signal Smoothing", type=input.integer, minval=1, maxval=50, defval=9)
sma_source = input(title="MACD Simple MA (Oscillator)", type=input.bool, defval=false)
sma_signal = input(title="MACD Simple MA (Signal Line)", type=input.bool, defval=false)

// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #e57373
col_macd = #0094ff
col_signal = #ff6a00

// Calculating
sma_1 = sma(src, fast_length)
ema_1 = ema(src, fast_length)
fast_ma = sma_source ? sma_1 : ema_1
sma_2 = sma(src, slow_length)
ema_2 = ema(src, slow_length)
slow_ma = sma_source ? sma_2 : ema_2
macd = fast_ma - slow_ma
sma_3 = sma(macd, signal_length)
ema_3 = ema(macd, signal_length)
signal = sma_signal ? sma_3 : ema_3
hist = (macd - signal)

plot(hist, title="Histogram", style=plot.style_columns, color=hist >= 0 ? hist[1] < hist ? col_grow_above : col_fall_above : hist[1] < hist ? col_grow_below : col_fall_below, transp=0)
plot(macd, title="MACD", color=col_macd, transp=0)
plot(signal, title="Signal", color=col_signal, transp=0)


// RSI
len = input(14, minval=1, title="RSI Length")
up = rma(max(change(src), 0), len)
down = rma(-min(change(src), 0), len)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
scale = 0.05
move = 0
plot((rsi - 50) * scale - move, color=color.yellow)
band1 = hline(20 * scale - move)
band0 = hline(-20 * scale - move)
fill(band1, band0, color=color.purple, transp=94)

Overview

MACD + RSI Robert's Version plots the standard MACD line, signal line and a four-colour histogram, with options to use simple instead of exponential averages for the oscillator and the signal. The RSI is rescaled and drawn as a yellow line around the zero level, with a shaded band between two reference lines. Source, MACD lengths and RSI length are adjustable. It displays momentum only and produces no buy or sell signals.

Details

Published by

Rvannest on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum

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
Sourcesourceclosesrc
MACD Fast Lengthint12fast_length
MACD Slow Lengthint26slow_length
MACD Signal Smoothingint9signal_length
MACD Simple MA (Oscillator)boolfalsesma_source
MACD Simple MA (Signal Line)boolfalsesma_signal
RSI Lengthint14len
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

Asymmetrical RSI

by everget
948 stars

Asymmetrical RSI is an indicator that computes a custom relative strength index from the rate of change of a user-selected source. It plots the resulting ARSI line in a separate pane with color coding that turns green above the overbought level and red below t

Indicator v4 Oscillators & momentum
Updated 11 days ago · GPL-3.0 GitHub repository of Asymmetrical RSI

This indicator calculates momentum setups based on the Relative Strength Index (RSI) and plots in a separate pane. It offers multiple scanning modes such as Continuous Break, Continuous Retracement, Flip Break, Flip Retracement, and both regular and hidden div

Indicator v6 Oscillators & momentumDivergence Repaints
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Indicator

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
261 stars

This indicator demonstrates an experimental graph-style scatter visualization within a separate pane using Pine Script arrays. It tracks two features across recent bars: the single-bar price change and a scaled 14-period Relative Strength Index. Values are loa

Indicator v4 Oscillators & momentum
Updated 4 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

KD指標

by TaichiS
219 stars

This script calculates and plots a Stochastic Oscillator (KD indicator) in a separate chart pane. It determines the fast stochastic value over a 9-period lookback, then applies a 3-period Simple Moving Average (SMA) to create the %K line, and a second 3-period

Indicator v4 Oscillators & momentum
Updated 5 years ago · None stated GitHub repository of KD指標

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