Indicator · Pine Script v6 · Own pane

RSI

by TamTH-Dev· code credited to tamth_

This indicator calculates a Percentage Price Oscillator using fast and slow exponential moving averages to evaluate price momentum in a separate pane.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code215
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update5 weeks ago18 Sep 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

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

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

//@version=6
indicator("RSI", overlay = false, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_bars_back = 5000)

// -----------------------------------------------------------------------------
// Constants
// -----------------------------------------------------------------------------
color AQUA_COLOR       = #4CC9F0
color PURPLE_COLOR     = #3F37C9
color LIGHT_GRAY_COLOR = #364156

// -----------------------------------------------------------------------------
// Common Variables
// -----------------------------------------------------------------------------
series float src = close

// -----------------------------------------------------------------------------
// DRO – Dominant Cycle Calculation
// -----------------------------------------------------------------------------
var int   max_array_size   = 15
var float[] ziggyzags      = array.new_float(0)
var float[] zzl            = array.new_float(0)
var float[] cycles         = array.new_float(0)
var int   dir1             = 0
var int   lastPivot        = 0
var int   lastPivotDistance= 0
float     domcycle         = 0.0
int       fastLength       = 3
int       slowLength       = 50
int       zigPeriod        = 30

add_to_zigzag(ptr, value, bindex) =>
    array.unshift(ptr, bindex)
    array.unshift(ptr, value)
    if array.size(ptr) > max_array_size
        array.pop(ptr)
        array.pop(ptr)

update_zigzag(ptr, value, bindex, dir) =>
    if array.size(ptr) == 0
        add_to_zigzag(ptr, value, bindex)
    else
        if (dir == 1 and value > array.get(ptr, 0)) or (dir == -1 and value < array.get(ptr, 0))
            array.set(ptr, 0, value)
            array.set(ptr, 1, bindex)
        0.

float ppo = 100.0 * (ta.ema(src, fastLength) - ta.ema(src, slowLength)) / ta.ema(src, slowLength)

int   leftBars     = zigPeriod - 1
float ph           = ta.pivothigh(ppo, leftBars, 0)
float pl           = ta.pivotlow (ppo, leftBars, 0)
bool  isPivotHigh  = not na(ph) and ph == ppo
bool  isPivotLow   = not na(pl) and pl == ppo
float highs        = isPivotHigh ? ph : na
float lows         = isPivotLow  ? pl : na

iff_1 = bool(lows) and na(highs) ? -1 : dir1
dir1 := bool(highs) and na(lows) ? 1 : iff_1

dir1changed = ta.change(dir1)

if bool(highs) or bool(lows)
    if bool(dir1changed)
        add_to_zigzag(ziggyzags, dir1 == 1 ? highs : lows, bar_index)
    else
        update_zigzag(ziggyzags, dir1 == 1 ? highs : lows, bar_index, dir1)

float currentZigVal   = array.size(ziggyzags) >= 2 ? array.get(ziggyzags, 0) : na
int   currentZigPoint = array.size(ziggyzags) >= 2 ? int(array.get(ziggyzags, 1)) : na

var float prevZigVal   = na
var int   prevZigPoint = na
bool      zigChanged   = (currentZigVal != prevZigVal) or (currentZigPoint != prevZigPoint)

prevZigVal   := currentZigVal
prevZigPoint := currentZigPoint

if array.size(ziggyzags) >= 6 and zigChanged
    float val   = array.get(ziggyzags, 0)
    int   point = int(array.get(ziggyzags, 1))
    float val1  = array.get(ziggyzags, 2)
    int   point1= int(array.get(ziggyzags, 3))

    var float lastVal1   = na
    var int   lastPoint1 = na
    bool      pivotInnerChanged = (val1 != lastVal1) or (point1 != lastPoint1)

    lastVal1   := val1
    lastPoint1 := point1

    lastPivotDistance := point - lastPivot
    lastPivot         := point1

    if not pivotInnerChanged
        if array.size(zzl) > 1
            float lastDistance = array.get(zzl, 1)
        if array.size(zzl) > 0
            array.shift(zzl)
        0.
    else
        if array.size(zzl) > 0
            lastPivotDistance := point - lastPivot
            0
        else
            if array.size(zzl) > 0
                array.shift(zzl)
            0
        0.

    array.unshift(zzl, lastPivotDistance)

if array.size(zzl) > max_array_size
    array.pop(zzl)

if array.size(zzl) > 3
    array.clear(cycles)
    for i = 1 to array.size(zzl) - 2
        float z1 = array.get(zzl, i)
        float z2 = array.get(zzl, i + 1)
        cycles.push(z1 + z2)
    domcycle := array.median(cycles)

// -----------------------------------------------------------------------------
// Adaptive RSI
// -----------------------------------------------------------------------------
int   adaptiveLen  = int(na(domcycle) or domcycle <= 0 ? 21 : domcycle)
float crsi         = 0.0
int   cyclelen     = adaptiveLen / 2
int   vibration    = 10
float leveling     = 10.0
int   cyclicmemory = adaptiveLen * 2

float torque     = 2.0 / (vibration + 1)
float phasingLag = (vibration - 1) / 2.0

var float up = 0.0
up := (math.max(ta.change(src), 0) + (cyclelen - 1) * nz(up[1])) / cyclelen

var float down = 0.0
down := (-math.min(ta.change(src), 0) + (cyclelen - 1) * nz(down[1])) / cyclelen

float rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)

crsi := torque * (2 * rsi - rsi[phasingLag]) + (1 - torque) * nz(crsi[1])

float lmax = -999999.0
float lmin =  999999.0

for i = 0 to cyclicmemory - 1
    if nz(crsi[i], -999999.0) > lmax
        lmax := nz(crsi[i])
        lmax
    else
        if nz(crsi[i], 999999.0) < lmin
            lmin := nz(crsi[i])
            lmin

float mstep = (lmax - lmin) / 100
float aperc = leveling / 100

float db = 0.0
for steps = 0 to 100
    float testvalue = lmin + mstep * steps
    float above     = 0
    float below     = 0

    for m = 0 to cyclicmemory - 1
        below := below + (crsi[m] < testvalue ? 1 : 0)
        below

    float ratio = below / cyclicmemory

    if ratio >= aperc
        db := testvalue
        break
    else
        continue

float ub = 0.0
for steps = 0 to 100
    float testvalue = lmax - mstep * steps
    float above     = 0

    for m = 0 to cyclicmemory - 1
        above := above + (crsi[m] >= testvalue ? 1 : 0)
        above

    float ratio = above / cyclicmemory

    if ratio >= aperc
        ub := testvalue
        break
    else
        continue

// -----------------------------------------------------------------------------
// Render
// -----------------------------------------------------------------------------
hline(30, color = color.new(LIGHT_GRAY_COLOR, 50), linestyle = hline.style_dashed)
hline(50, color = color.new(LIGHT_GRAY_COLOR, 30), linestyle = hline.style_dashed)
hline(70, color = color.new(LIGHT_GRAY_COLOR, 50), linestyle = hline.style_dashed)

plot(db,   "Low Band",  color = PURPLE_COLOR, display = display.pane)
plot(ub,   "High Band", color = PURPLE_COLOR, display = display.pane)
plot(crsi, "RSI",       color = AQUA_COLOR,   display = display.pane)

// -----------------------------------------------------------------------------
// Alert Conditions
// -----------------------------------------------------------------------------
alertcondition(ta.cross(crsi, db),  title="CRSI Crosses Low Band",  message="CRSI crossed the Low Band")
alertcondition(ta.cross(crsi, ub),  title="CRSI Crosses High Band", message="CRSI crossed the High Band")
alertcondition(ta.cross(crsi, 50),  title="CRSI Crosses 50",       message="CRSI crossed 50")

Overview

RSI identifies dynamic pivot highs and lows along the oscillator line and constructs a zigzag array to determine dominant cycle periods. The calculation updates pivot positions and cycle distances dynamically across bars without relying on user-configurable inputs.

Details

Published by

TamTH-Dev on GitHub

Code credit

tamth_, as written in the script's header

Type

Indicator, Pine Script v6

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.

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