Indicator · Pine Script v6 · Own pane

Connors RSI (CRSI)

by mihakralj

The Connors RSI indicator calculates a composite momentum oscillator as the average of standard RSI on the input source, RSI on directional price streaks, and percent rank of one-bar rate of change.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code127
Settings4inputs
LicenceApache-2.0
Last update4 weeks ago27 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

127 lines of Pine Script v6 from lib/oscillators/crsi/crsi.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

crsi.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Connors RSI (CRSI)", "CRSI", overlay=false)

//@function Calculates RSI using Wilder's smoothing with warmup compensation
//@param source Series to calculate RSI from
//@param period RSI lookback period
//@returns RSI value (0-100) with valid output from bar 1
rsi_calc(series float source, simple int period) =>
    if period <= 0
        runtime.error("Period must be greater than 0")

    float alpha = 1.0 / period
    float beta = 1.0 - alpha

    var float prevVal = na
    var float avgGain = 0.0
    var float avgLoss = 0.0
    var float e = 1.0
    var bool warmup = true

    float result = 50.0

    if not na(source)
        if na(prevVal)
            prevVal := source
        else
            float change = source - prevVal
            float gain = change > 0.0 ? change : 0.0
            float loss = change < 0.0 ? -change : 0.0
            prevVal := source

            avgGain := alpha * gain + beta * avgGain
            avgLoss := alpha * loss + beta * avgLoss

            if warmup
                e *= beta
                float c = e > 1e-10 ? 1.0 / (1.0 - e) : 1.0
                float aG = avgGain * c
                float aL = avgLoss * c
                float total = aG + aL
                result := total != 0.0 ? 100.0 * aG / total : 50.0
                if e <= 1e-10
                    warmup := false
            else
                float total = avgGain + avgLoss
                result := total != 0.0 ? 100.0 * avgGain / total : 50.0

    result

//@function Calculates Connors RSI as average of price RSI, streak RSI, and percent rank
//@param source Series to calculate from
//@param rsiPeriod Period for price RSI component
//@param streakPeriod Period for streak RSI component
//@param rankPeriod Lookback period for percent rank of ROC
//@returns Connors RSI value (0-100)
crsi(series float source, simple int rsiPeriod, simple int streakPeriod, simple int rankPeriod) =>
    if rsiPeriod <= 0 or streakPeriod <= 0 or rankPeriod <= 0
        runtime.error("All periods must be greater than 0")

    // Component 1: RSI of price
    float priceRsi = rsi_calc(source, rsiPeriod)

    // Component 2: Streak calculation + RSI of streak
    var float prevClose = na
    var float streak = 0.0

    if not na(source)
        if na(prevClose)
            streak := 0.0
        else if source > prevClose
            streak := streak >= 0.0 ? streak + 1.0 : 1.0
        else if source < prevClose
            streak := streak <= 0.0 ? streak - 1.0 : -1.0
        else
            streak := 0.0
        prevClose := source

    float streakRsi = rsi_calc(streak, streakPeriod)

    // Component 3: Percent rank of 1-bar ROC
    var float prevSrc = na
    var array<float> rocBuf = array.new_float(rankPeriod, na)
    var int rocHead = 0
    var int rocCount = 0

    float roc = 0.0
    if not na(source) and not na(prevSrc) and prevSrc != 0.0
        roc := (source - prevSrc) / prevSrc * 100.0
    if not na(source)
        prevSrc := source

    // Count how many HISTORICAL ROC values are strictly < current ROC
    // BEFORE storing current roc (Connors/Alvarez: "percentage of values the current return is greater than")
    int lessCount = 0
    for i = 0 to rocCount - 1
        float val = array.get(rocBuf, i)
        if not na(val) and val < roc
            lessCount += 1
    float pctRank = rocCount > 0 ? (float(lessCount) / float(rocCount)) * 100.0 : 50.0

    // Store current ROC after rank scan
    if na(array.get(rocBuf, rocHead))
        rocCount := math.min(rocCount + 1, rankPeriod)
    array.set(rocBuf, rocHead, roc)
    rocHead := (rocHead + 1) % rankPeriod

    // Connors RSI = average of three components
    float result = (priceRsi + streakRsi + pctRank) / 3.0
    math.max(0.0, math.min(100.0, result))

// ---------- Main loop ----------

// Inputs
i_source = input.source(close, "Source")
i_rsiPeriod = input.int(3, "RSI Period", minval=1, maxval=500)
i_streakPeriod = input.int(2, "Streak RSI Period", minval=1, maxval=500)
i_rankPeriod = input.int(100, "Percent Rank Period", minval=1, maxval=1000)

// Calculation
crsi_value = crsi(i_source, i_rsiPeriod, i_streakPeriod, i_rankPeriod)

// Plot
plot(crsi_value, "CRSI", color.new(color.yellow, 0), 2)
hline(70, "Overbought", color=color.gray, linestyle=hline.style_dotted)
hline(30, "Oversold", color=color.gray, linestyle=hline.style_dotted)

Overview

Connors RSI (CRSI) plots this value in a separate pane below the price chart. The source defaults to close but accepts any series. Main settings adjust the RSI lookback (default 3), streak period (default 2), and rank period (default 100). It serves as a versatile trend and momentum filter for various markets and timeframes.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

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.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
Sourcesourceclosei_source
RSI Periodint3i_rsiPeriod
Streak RSI Periodint2i_streakPeriod
Percent Rank Periodint100i_rankPeriod
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 10 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