//@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)
import bader61888/SaudiTA/1 as sta
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] = sta.cardwellRsiRange(close, rsiLen, lookback)
[pos, neg] = sta.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")