Indicator · Pine Script v6 · Own pane

Cardwell RSI Regime

by bader61888· code credited to Bader

Calculates the Relative Strength Index (RSI) to evaluate market regimes based on Andrew Cardwell's range rules in a separate pane.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code69
Settings3inputs
LicenceMIT
Last update4 weeks ago22 Oct 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

69 lines of Pine Script v6 from standalone/CardwellRSI_standalone.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

CardwellRSI_standalone.pine
//@version=6
// SPDX-License-Identifier: MIT
// © 2026 Bader Alrashdi — https://github.com/bader61888/saudi-pine-toolkit
indicator("Cardwell RSI Regime", shorttitle="CW RSI", overlay=false)

// Cardwell RSI range regime: 1 = bull range (RSI holds 40-80), -1 = bear range (RSI holds 20-60), 0 = neutral
cardwellRsiRange(series float src, simple int rsiLen, simple int lookback) =>
    float r = ta.rsi(src, rsiLen)
    float lo = ta.lowest(r, lookback)
    float hi = ta.highest(r, lookback)
    int regime = lo >= 40 ? 1 : hi <= 60 ? -1 : 0
    [r, regime]

// Cardwell reversals (confirmed pivotLen bars late). Positive: price higher low + RSI lower low. Negative: price lower high + RSI higher high.
rsiReversals(series float src, simple int rsiLen, simple int pivotLen) =>
    float r = ta.rsi(src, rsiLen)
    bool pl = not na(ta.pivotlow(r, pivotLen, pivotLen))
    bool ph = not na(ta.pivothigh(r, pivotLen, pivotLen))
    float prevRl = ta.valuewhen(pl, r[pivotLen], 1)
    float prevPl = ta.valuewhen(pl, low[pivotLen], 1)
    float prevRh = ta.valuewhen(ph, r[pivotLen], 1)
    float prevPh = ta.valuewhen(ph, high[pivotLen], 1)
    bool pos = pl and r[pivotLen] < prevRl and low[pivotLen] > prevPl
    bool neg = ph and r[pivotLen] > prevRh and high[pivotLen] < prevPh
    [pos, neg]

// Relative volume and relative bar spread vs their SMA
volumeSpread(simple int len) =>
    float spread = high - low
    float avgV = ta.sma(volume, len)
    float avgS = ta.sma(spread, len)
    float relVol = avgV > 0 ? volume / avgV : na
    float relSpread = avgS > 0 ? spread / avgS : na
    [relVol, relSpread]

// Simple Wyckoff spring / upthrust detector
wyckoffSpringUpthrust(simple int rangeLen, simple int volLen, simple float volMult) =>
    float rl = ta.lowest(low, rangeLen)[1]
    float rh = ta.highest(high, rangeLen)[1]
    float avgV = ta.sma(volume, volLen)
    bool hiVol = volume > avgV * volMult
    bool spring = low < rl and close > rl and hiVol
    bool upthrust = high > rh and close < rh and hiVol
    [spring, upthrust]

// True during Tadawul main session: Sun-Thu 10:00-15:00 Asia/Riyadh
inTadawulSession() =>
    int d = dayofweek(time, "Asia/Riyadh")
    int mins = hour(time, "Asia/Riyadh") * 60 + minute(time, "Asia/Riyadh")
    bool tradingDay = d == dayofweek.sunday or d == dayofweek.monday or d == dayofweek.tuesday or d == dayofweek.wednesday or d == dayofweek.thursday
    bool inHours = timeframe.isintraday ? (mins >= 600 and mins < 900) : true
    tradingDay and inHours

rsiLen = input.int(14, "RSI Length", minval=2)
lookback = input.int(20, "Regime Lookback", minval=5)
pivotLen = input.int(5, "Pivot Length", minval=1)

[r, regime] = cardwellRsiRange(close, rsiLen, lookback)
[pos, neg] = rsiReversals(close, rsiLen, pivotLen)

hline(80, "80", color=color.gray)
hline(60, "60", color=color.gray, linestyle=hline.style_dotted)
hline(40, "40", color=color.gray, linestyle=hline.style_dotted)
hline(20, "20", color=color.gray)
plot(r, "RSI", color=regime == 1 ? color.green : regime == -1 ? color.red : color.gray, linewidth=2)
plotshape(pos, "Positive Reversal", shape.triangleup, location.bottom, color.green, offset=-pivotLen, size=size.tiny)
plotshape(neg, "Negative Reversal", shape.triangledown, location.top, color.red, offset=-pivotLen, size=size.tiny)
alertcondition(pos, "Positive Reversal", "Cardwell positive RSI reversal")
alertcondition(neg, "Negative Reversal", "Cardwell negative RSI reversal")

Overview

Cardwell RSI Regime identifies a bullish regime when RSI holds above 40 over the lookback period and a bearish regime when RSI stays below 60. The script also detects positive reversals where price forms a higher low while RSI forms a lower low, and negative reversals where price forms a lower high while RSI forms a higher high. User settings control RSI length, regime lookback, and pivot detection length.

Details

Published by

bader61888 on GitHub

Code credit

Bader, as written in the script's header

Draws

Separate pane below the chart

Markets

Stocks

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

pinescriptsauditadawultechnical-analysistradingviewwyckoff

Settings

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

SettingTypeDefaultVariable
RSI Lengthint14rsiLen
Regime Lookbackint20lookback
Pivot Lengthint5pivotLen
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
947 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 5 weeks 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
408 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

[TVT] OBV with EMA

by namuan
321 stars

Calculates On-Balance Volume (OBV) alongside two Exponential Moving Averages (EMAs) applied directly to the cumulative OBV line. The indicator tracks volume flow relative to price movement and smooths it using short-term and longer-term EMAs to highlight volum

Indicator v6 VolumeOscillators & momentum
Updated 8 days ago · MIT GitHub repository of [TVT] OBV with EMA
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 5 years ago · None stated GitHub repository of Example: Graph Style - 4th Dimension RSI

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers