Indicator · Pine Script v4 · Own pane

RSI + Slow Stochastic + MACD

by krosenfeld7

This indicator calculates and displays the Relative Strength Index, Slow Stochastic, and a normalized MACD line together in a separate pane.

View on GitHub

GitHub stars5on the repository
Pine versionv4older, still runs
Lines of code113
Settings15inputs
LicenceApache-2.0
Last update3 years ago12 May 2023

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

113 lines of Pine Script v4 from RSI+Slow_Stochastic+MACD/RSI+Slow_Stochastic+MACD.txt, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

RSI+Slow_Stochastic+MACD.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © krosenfeld7

//@version=4
study("RSI + Slow Stochastic + MACD", shorttitle="RSI + SS + MACD", overlay=false)

rsiOver = input(title="RSI Highline", type=input.integer, defval=70, minval=70, maxval=100)
rsiMid = input(title="RSI Midline", type=input.integer, defval=50, minval=30, maxval=70)
rsiUnder = input(title="RSI Lowline", type=input.integer, defval=30, maxval=30, minval=0)
maxDelay = input(title="Label+Indicator Delay", type=input.integer, defval=5, minval=0)
barsback = input(title="Lookback", type=input.integer, defval=3, minval=1)

// RSI Section
len1 = input(14, minval=1, title="RSI Length")
src1 = input(close, "RSI Source", type = input.source)
up = rma(max(change(src1), 0), len1)
down = rma(-min(change(src1), 0), len1)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=color.white, transp=0, linewidth=2)

band80 = hline(rsiOver + 10, "Upper Band", color=color.white, linewidth=1, linestyle=hline.style_dashed)
band50 = hline(rsiMid, "Middle Band", color=color.purple, linewidth=1, linestyle=hline.style_solid)
band20 = hline(rsiUnder - 10, "Lower Band", color=color.white, linewidth=1, linestyle=hline.style_dashed)
band70 = hline(rsiOver, "Upper Band", color=color.white, linewidth=1, linestyle=hline.style_dashed)
band30 = hline(rsiUnder, "Lower Band", color=color.white, linewidth=1, linestyle=hline.style_dashed)
fill(band50, band70, color=color.white, transp=90, title="Background")
fill(band30, band50, color=color.white, transp=90, title="Background")
fill(band70, band80, color=color.white, transp=80, title="Background")
fill(band20, band30, color=color.white, transp=80, title="Background")
fill(band80, hline(100, color=color.red, linestyle=hline.style_solid), color=color.red, transp=75, title="Background")
fill(hline(0, color=color.green, linestyle=hline.style_solid), band20, color=color.green, transp=75, title="Background")

rsiLong = rsi > rsiMid
rsiShort = rsi < rsiMid

rsiLongExitCondition = rsi > rsiOver
rsiShortExitCondition = rsi < rsiUnder

// Slow Stochastic
smoothK = input(14, minval=1), smoothD = input(3, minval=1)
k = sma(stoch(close, high, low, smoothK), 3)
d = sma(k, smoothD)
plot(k, color=color.blue, transp=0, linewidth=2)
plot(d, color=color.orange, transp=0, linewidth=2)

stoLong = k < rsiUnder and d < rsiUnder and crossover(k, d)
stoShort = k > rsiOver and d > rsiOver and crossunder(k, d)

stoLongExitCondition = k > rsiOver and d > rsiOver
stoShortExitCondition = k < rsiUnder and d < rsiUnder

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

// Calculating
fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)
slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)

plottableMacd = (macd / 10000) * 100 + 50
plottableSignal = (signal / 10000) * 100 + 50

plot(plottableMacd, title="MACD", color=color.green, transp=0, linewidth=2)
plot(plottableSignal, title="Signal", color=color.red, transp=0, linewidth=2)

macdLong = crossover(macd, signal)
macdShort = crossunder(macd, signal)

if barstate.isrealtime and (rsi < rsiUnder or (k < rsiUnder and d < rsiUnder))
    label.new(bar_index, 5, text="Oversold", color=color.new(color.white, transp=0), style=label.style_label_up)
else if barstate.isrealtime and (rsi > rsiOver or (k > rsiOver and d > rsiOver))
    label.new(bar_index, 95, text="Overbought", color=color.new(color.white, transp=0))

// Bullish (Long)
// RSI is above 50, trend is upwards
// Stochastic is in Oversold, cross up
// MACD crossing up
// Stop loss at last pivot low
// Exit when stochastic and rsi are overbought

longStopLoss = lowest(low, barsback)

tempLong = barssince(rsiLong) < maxDelay and barssince(stoLong) < maxDelay and barssince(macdLong) < maxDelay
longExitCondition = rsiLongExitCondition and stoLongExitCondition
long = tempLong ? 1 : 0

// Bearish (Short)
// RSI is below 50, trend is downwards
// Stochastic is in Overbought, cross down
// MACD crossing down
// Stop loss at last pivot high
// Exit when stochastic and rsi are oversold

shortStopLoss = highest(high, barsback)

tempShort = barssince(rsiShort) < maxDelay and barssince(stoShort) < maxDelay and barssince(macdShort) < maxDelay
shortExitCondition = rsiShortExitCondition and stoShortExitCondition
short = tempShort ? 1 : 0

if long and not long[1]
    label.new(bar_index, 5, text="Long", color=color.green, style=label.style_label_up)
if short and not short[1]
    label.new(bar_index, 95, text="Short", color=color.red, style=label.style_label_down)

// Alerts
alertcondition(long, title = "Long Signal", message = "Long @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")
alertcondition(short, title = "Short Signal", message = "Short @ {{timenow}}: {{ticker}} -> {{interval}}: {{close}}")

Overview

RSI + Slow Stochastic + MACD plots the oscillators alongside customizable overbought, middle, and oversold threshold levels with shaded background fills. Internal conditions monitor overbought or oversold extremes and Stochastic crossovers. Inputs allow traders to adjust oscillator lengths, source prices, and moving average calculation methods. Because this script is an informational indicator rather than an automated strategy, it does not include execution rules, stop loss parameters, or trade management.

Details

Published by

krosenfeld7 on GitHub

Type

Indicator, Pine Script v4

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.

Settings

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

SettingTypeDefaultVariable
RSI Highlineint70rsiOver
RSI Midlineint50rsiMid
RSI Lowlineint30rsiUnder
Label+Indicator Delayint5maxDelay
Lookbackint3barsback
RSI Lengthint14len1
RSI Sourcesourceclosesrc1
smoothKint14smoothK
smoothDint3smoothD
MACD Fast Lengthint12fast_length
MACD Slow Lengthint26slow_length
MACD Sourcesourceclosesrc
Show all 15 settings
SettingTypeDefaultVariable
Signal Smoothingint9signal_length
Simple MA (Oscillator)boolfalsesma_source
Simple MA (Signal Line)boolfalsesma_signal
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