Indicator · Pine Script v5 · Own pane

RSI Oscillator (Hotch)

by rajatjpatel· code credited to Hotchachachaaa

A separate-pane trend oscillator built from two smoothed moving averages, 21 and 315 bars by default.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code100
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago18 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

100 lines of Pine Script v5 from RSI-Oscollator.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

RSI-Oscollator.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Hotchachachaaa
//Credit to PheonixBinary for use of the dynamic coloring in "The Arty" (I believe he found it in another indicator but I do not know wich one), modified to use as a lower indicator/trend indicator. 

//@version=5
indicator("RSI Oscillator")


f_c_gradientRelative(_source, _min, _max, _c_bear, _c_bull) =>
    // float _source: input signal
    // float _min   : minimum range of input signal.
    // float _max   : maximum range of input signal.
    // color _c_bear: bear color at `_min` level.
    // color _c_bull: bull color at `_max` level.
    // Dependency: `f_colorNew()`
    var float _center = _min + (_max - _min) / 2
    color _return = _source >= _center ? 
      color.from_gradient(_source, _center, _max, color.new(_c_bull, 100), color.new(_c_bull, 0)) : 
      color.from_gradient(_source, _min, _center, color.new(_c_bear, 0), color.new(_c_bear, 100))



len1 = input.int(21, minval=1, title="Length1")
src1 = close
smma1 = 0.0
smma1 := na(smma1[1]) ? ta.sma(src1, len1) : (smma1[1] * (len1 - 1) + src1) / len1

len2 = input.int(315, minval=1, title="Length2")
src2 = close
smma2 = 0.0
smma2 := na(smma2[1]) ? ta.sma(src2, len2) : (smma2[1] * (len2 - 1) + src2) / len2

MA1 = smma1
MA2 = smma2






length1 = 10
beta1   = 1
alpha1  = 1
var b1 = array.new_float(0)


if barstate.isfirst
    for i = 0 to length1-1
        x = i/(length1-1)
        w = math.pow(x,alpha1-1)*math.pow(1-x,beta1-1)
        array.push(b1,w)
den1 = array.sum(b1)
//----

sum1 = 0.
for i = 0 to length1-1
    sum1 := sum1 + MA1[i]*array.get(b1,i)
filt1 = sum1/den1
os1 = ta.rsi(filt1,length1)/100

length2 = 10
beta2   = 1
alpha2  = 1
var b2 = array.new_float(0)

if barstate.isfirst
    for i = 0 to length2-1
        x = i/(length2-1)
        w = math.pow(x,alpha2-1)*math.pow(1-x,beta2-1)
        array.push(b2,w)
den2 = array.sum(b2)
//----

sum2 = 0.
for i = 0 to length2-1
    sum2 := sum2 + MA2[i]*array.get(b2,i)
filt2 = sum2/den2
os2 = ta.rsi(filt2,length2)/100


modRSIValue1 = os1*199
modRSIValue2 = os2*199

color dynColor1 = f_c_gradientRelative(modRSIValue1, 0, 200, #FF1100,#30FF85)
color dynColor2 = f_c_gradientRelative(modRSIValue2, 0, 200, #6C3483 ,#2874A6 )

plot(modRSIValue1, "3rd color 1", #FF5500, 2)
plot(modRSIValue1, "dynamic color calc1", dynColor1, 2)

plot(modRSIValue2, "3rd color 2", #5D6D7E, 2)
plot(modRSIValue2, "dynamic color calc2", dynColor2, 2)

hline(197, title="OB line",color= color.gray, linestyle= hline.style_dashed)
hline(3, title= "OS line",color= color.gray, linestyle= hline.style_dashed)

alertcondition(ta.crossover(modRSIValue1,197), title= "OB Alert", message= "Bullish Trend")
alertcondition(ta.crossunder(modRSIValue1,197), title= "ExitOB Alert", message= "Exit Bullish Trend")

alertcondition(ta.crossunder(modRSIValue1,3), title= "OS Alert", message= "Bearish Trend")
alertcondition(ta.crossover(modRSIValue1,3), title= "Exit OS Alert", message= "Exit Bearish Trend")

Overview

Each average is passed through a weighted filter and then an RSI, and the result is scaled to a range of roughly 0 to 200. Two lines are drawn with dynamic gradient colors, with dashed overbought and oversold guides near the extremes. Four alert conditions fire when the faster line crosses those guides. Both average lengths are adjustable.

Details

Published by

rajatjpatel on GitHub

Code credit

Hotchachachaaa, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend

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
Length1int21len1
Length2int315len2
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 11 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

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

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
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

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