Indicator · Pine Script v5 · Own pane

Benso Pendulum

by benso87

Benso Pendulum is an indicator that plots a customizable Relative Strength Index (RSI) oscillator in a separate pane on the price chart.

View on GitHub

GitHub stars24on the repository
Pine versionv5runs as is
Lines of code179
Settings40inputs
LicenceMPL-2.0
Last update4 years ago5 Oct 2022

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

179 lines of Pine Script v5 from Benso Pendulum.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Benso Pendulum.pine
//@version=5
//
// Author: benso87
// benso87.com
//
// Credit to Nick Guerrero (on YouTube) for the Jupiter Pendulum
// That indicator wasn't quite what I wanted, so I made this
//
indicator(title='Benso Pendulum', shorttitle='Bepu', format=format.price, precision=2, timeframe='', timeframe_gaps=true, max_bars_back=500)

// Inputs
ma(source, length, type) =>
    switch type
        'SMA' => ta.sma(source, length)
        'EMA' => ta.ema(source, length)

rsiSource = input.source(close, 'Source', group='RSI Settings')
rsiPeriod = input.int(14, minval=1, title='Period', group='RSI Settings')

rsiWidth = input.int(4, title='Line Width', minval=1, maxval=4, group='RSI Style', inline='1')
rsiDynColors = input.bool(true, title='Dynamic RSI Colors', group='RSI Style', inline='2')
rsiDefColor = input.color(#008eff, title='Default', group='RSI Style', inline='3')
rsiHighColor = input.color(#ff0014, title='High', group='RSI Style', inline='3')
rsiLowColor = input.color(#0bff00, title='Low', group='RSI Style', inline='3')

tagHigh = input.int(75, title='Tag High', inline='high', group='Tag Lines')
tagHighColor = input.color(#0bff00, title='', inline='high', group='Tag Lines')
tagLow = input.int(25, title='Tag Low', inline='low', group='Tag Lines')
tagLowColor = input.color(#ff0014, title='', inline='low', group='Tag Lines')
tagWidth = input.int(2, title='Line Width', group='Tag Lines')
showRecentTag = input.bool(true, title='Indicate Most Recent Tag', group='Tag Lines')
recentTagOffset = input.int(3, title='Indicator Offset', group='Tag Lines')
recentTagTransp = input.int(70, title='Indicator Transparency', minval=0, maxval=100, group='Tag Lines')
recentLineStyleStr = input.string('Line', title='Line Style', options=['Line', 'Circles'], group='Tag Lines')

obLevel = input.int(80, title='Overbought Level', minval=0, maxval=100, group='Overbought/Oversold Levels', inline='ob')
obColor = input.color(color.new(color.red, transp=80), title='', group='Overbought/Oversold Levels', inline='ob')
osLevel = input.int(20, title='Oversold Level', minval=0, maxval=100, group='Overbought/Oversold Levels', inline='os')
osColor = input.color(color.new(color.green, transp=80), title='', group='Overbought/Oversold Levels', inline='os')

plotFast = input.bool(false, title='Show', group='Fast RSI')
fastSource = input.source(close, title='Source', group='Fast RSI')
fastPeriod = input.int(6, title='Period', minval=1, group='Fast RSI')
fastSmooth = input.int(2, title='Smoothing', minval=1, group='Fast RSI')
fastType = input.string('EMA', title='Smooth Type', options=['EMA', 'SMA'], group='Fast RSI')

plotStoch = input.bool(false, title='Show', group='Stochastic')
stochSource = input.source(close, title='Source', group='Stochastic')
periodK = input.int(14, title='K', minval=1, group='Stochastic')
periodD = input.int(3, title='D', minval=1, group='Stochastic')
smoothK = input.int(3, title='K Smoothing', minval=1, group='Stochastic')
smoothD = input.int(3, title='D Smoothing', minval=1, group='Stochastic')
plotStochRSI = input.bool(false, title='Show Stoch RSI', group='Stochastic')
stochRSILength = input.int(14, title='Stoch RSI Length', minval=1, group='Stochastic')

showMACD = input.bool(false, title='Show MACD Histogram', group='MACD')
macdColor = input.color(color.new(color.gray, transp=80), title='Color', group='MACD')
macdSource = input.source(close, title='Source', group='MACD')
macdFastLength = input.int(14, title='Fast Length', minval=1, group='MACD')
macdSlowLength = input.int(26, title='Slow Length', minval=1, group='MACD')
macdSigLength = input.int(9, title='Signal Length', minval=1, maxval=50, group='MACD')
macdMASrcType = input.string('EMA', title='Oscillator Type', options=['EMA', 'SMA'], group='MACD')
macdMASigType = input.string('EMA', title='Signal Line Type', options=['EMA', 'SMA'], group='MACD')

showVBC = input.bool(false, title='Color Bars Based On Volume', group='Volume Bar Colors', inline='0')
showBuy = input.bool(true, title='High Buy Volume', inline='1', group='Volume Bar Colors')
highBuyColor = input.color(color.yellow, title='', inline='1', group='Volume Bar Colors')
showSell = input.bool(true, title='High Sell Volume', inline='2', group='Volume Bar Colors')
highSellColor = input.color(color.orange, title='', inline='2', group='Volume Bar Colors')
bsRatio = input.float(2, title='Buy/Sell Ratio (2 = 200%)', inline='3', group='Volume Bar Colors')
volRatio = input.float(2, title='Total Volume Ratio (2 = 200%)', inline='3', group='Volume Bar Colors')
volPeriod = input.int(20, title='Volume Moving Average', inline='4', group='Volume Bar Colors')


//////////////////////////////////////////////////////////////
// Calculations

// RSI calculations
rsi = ta.rsi(rsiSource, rsiPeriod)
rsiColor = rsiDynColors and rsi > 50 ? rsiHighColor : rsiDynColors and rsi < 50 ? rsiLowColor : rsiDefColor

// Most recent tag calculations
f_plotStyle (S) =>
    switch S
        'Solid' => plot.style_line
        'Circles' => plot.style_circles
        'Diamond' => plot.style_stepline_diamond
        'Cross' => plot.style_cross


recentLineStyle = f_plotStyle(recentLineStyleStr)
recentTagHighLocation = tagHigh + recentTagOffset
recentTagLowLocation = tagLow - recentTagOffset

var string recentTag = na
if rsi >= tagHigh
    recentTag := 'h'
else if rsi <= tagLow
    recentTag := 'l'

noColor = color.new(color.white, transp=100)
recentTagHighColor = recentTag == 'h' ? color.new(tagHighColor, transp=100 - recentTagTransp) : noColor
recentTagLowColor = recentTag == 'l' ? color.new(tagLowColor, transp=100 - recentTagTransp) : noColor

// Fast RSI calculations
fastRSI = ma(ta.rsi(fastSource, fastPeriod), fastSmooth, fastType)

// Stochastic calculations
k = ta.sma(ta.stoch(stochSource, high, low, periodK), smoothK)
d = ta.sma(k, periodD)

// Stoch RSI
kRSI = ta.sma(ta.stoch(rsi, rsi, rsi, stochRSILength), smoothK)
dRSI = ta.sma(kRSI, smoothD)

// MACD calculations
macdFast = ma(macdSource, macdFastLength, macdMASrcType)
macdSlow = ma(macdSource, macdSlowLength, macdMASrcType)
macd = macdFast - macdSlow

macdSignal = ma(macd, macdSigLength, macdMASigType)
macdHist = macd - macdSignal

// Overbought/Oversold calculations
fastRSIOb = fastRSI >= obLevel
fastRSIOs = fastRSI <= osLevel
kOb = k >= obLevel
kOs = k <= osLevel
kRSIOb = kRSI >= obLevel
kRSIOs = kRSI <= osLevel

obSignal = fastRSIOb and kOb and kRSIOb
osSignal = fastRSIOs and kOs and kRSIOs

// Overbought/Oversold background colors
backgroundColor = obSignal ? obColor : osSignal? osColor : na

// Volume bar color calculations
buyVol = high == low ? 0 : volume * (close - low) / (high - low)
sellVol = high == low ? 0 : volume * (high - close) / (high - low)

highVol = volume >= volRatio * ta.sma(volume, volPeriod)

highBuy = showVBC and showBuy and highVol ? buyVol >= (bsRatio * buyVol[1]) and buyVol > sellVol : na
highSell = showVBC and showSell and highVol ? sellVol >= (bsRatio * sellVol[1]) and sellVol > buyVol : na


//////////////////////////////////////////////////////////////
// Plots

// RSI
plot(rsi, 'RSI', color=rsiColor, linewidth=rsiWidth)

// Stoch, Stoch RSI, and Fast RSI
plot(plotStoch ? k : na, title='k', color=color.red)
plot(plotStochRSI ? kRSI : na, title='kRSI', color=color.blue)
plot(plotFast ? fastRSI : na, title='fast RSI', color=color.yellow)

// Tag lines
rsiTagHigh = hline(tagHigh, title='Tag High', color=tagHighColor, linestyle=hline.style_solid, linewidth=tagWidth)
rsiTagLow = hline(tagLow, title='Tag Low', color=tagLowColor, linestyle=hline.style_solid, linewidth=tagWidth)
rsiMidLine = hline(50, title='Mid Line', color=color.new(#aaaaaa, transp=50), linestyle=hline.style_dashed)
plot(showRecentTag ? recentTagHighLocation : na, color=recentTagHighColor, linewidth=1, style=recentLineStyle)
plot(showRecentTag ? recentTagLowLocation : na, color=recentTagLowColor, linewidth=1, style=recentLineStyle)

// MACD
plot(showMACD ? macdHist + 50 : na, title='MACD', style=plot.style_area, color=macdColor, histbase=50)

// Volume bar colors
barcolor(highBuy ? highBuyColor : highSell ? highSellColor : na)

// Background color
bgcolor(backgroundColor)

//////////////////////////////////////////////////////////////
// Alerts

alertcondition(obSignal, title='Overbought', message='Overbought pendulum conditions')
alertcondition(osSignal, title='Oversold', message='Oversold pendulum conditions')

Overview

Benso Pendulum calculates the RSI using the specified source and period, applying dynamic colors that change based on overbought and oversold thresholds. Horizontal lines mark the high and low tag levels, with an option to indicate the most recent tag. The indicator also offers optional fast RSI and stochastic oscillator calculations for additional momentum analysis. Users can adjust line widths, colors, smoothing parameters, and other settings to tailor the display. It provides signals through crossing levels and color changes in the RSI plot.

Details

Published by

benso87 on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Support & resistance

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
SourcesourceclosersiSource
Periodint14rsiPeriod
Line Widthint4rsiWidth
Dynamic RSI ColorsbooltruersiDynColors
Defaultcolor#008effrsiDefColor
Highcolor#ff0014rsiHighColor
Lowcolor#0bff00rsiLowColor
Tag Highint75tagHigh
tagHighColorcolor#0bff00tagHighColor
Tag Lowint25tagLow
tagLowColorcolor#ff0014tagLowColor
Line Widthint2tagWidth
Show all 40 settings
SettingTypeDefaultVariable
Indicate Most Recent TagbooltrueshowRecentTag
Indicator Offsetint3recentTagOffset
Indicator Transparencyint70recentTagTransp
Line StylestringLinerecentLineStyleStr
Overbought Levelint80obLevel
obColorcolorcolor.new(color.red, transp=80)obColor
Oversold Levelint20osLevel
osColorcolorcolor.new(color.green, transp=80)osColor
ShowboolfalseplotFast
SourcesourceclosefastSource
Periodint6fastPeriod
Smoothingint2fastSmooth
Smooth TypestringEMAfastType
ShowboolfalseplotStoch
SourcesourceclosestochSource
Kint14periodK
Dint3periodD
K Smoothingint3smoothK
D Smoothingint3smoothD
Show Stoch RSIboolfalseplotStochRSI
Stoch RSI Lengthint14stochRSILength
Show MACD HistogramboolfalseshowMACD
Colorcolorcolor.new(color.gray, transp=80)macdColor
SourcesourceclosemacdSource
Fast Lengthint14macdFastLength
Slow Lengthint26macdSlowLength
Signal Lengthint9macdSigLength
Oscillator TypestringEMAmacdMASrcType
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 days 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 11 months ago · Custom licence GitHub repository of WaveTrend 3D
9 stars

This indicator plots currency strength values for EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD and optionally XAU or XAG on a separate pane. It computes strength by comparing current pair closes to daily closes using broker-specific data from OANDA, FX or FOREXCOM.

Indicator v4 Oscillators & momentumSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of 4th Dimension Currency Strength

The indicator scores whether a counter-move against the dominant structure is maturing and whether price has started turning back. It plots a composite score in a separate pane from weighted context, correction maturity, and exhaustion, scaled by trigger and a

Indicator v6 TrendOscillators & momentum
Updated yesterday · MIT GitHub repository of Directional Probability Engine v2 [WavesUnchained]

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