//@version=6
indicator("Candle Count RSI", overlay=false)
////////////////////////////////////////////////////////////////////////////////
// === INPUTS
////////////////////////////////////////////////////////////////////////////////
///////////////////////////
// === Core Settings === //
///////////////////////////
length = input.int(32, "RSI Length", group="Core Settings",
tooltip="The lookback period for RSI calculations. Used for both the standard
RSI (based on price magnitude) and Candle Count RSI (based on the count of
bullish/bearish candles).")
//////////////////////////
// === Standard RSI === //
//////////////////////////
showStandard = input.bool(true, "Standard RSI", inline="color", group="Standard
RSI",
tooltip="Enables plotting of the classic RSI line, calculated using price
momentum. This version accounts for the size of price changes, not just
direction.")
standardColor = input.color(color.white, "", inline="color", group="Standard RSI",
tooltip="Standard RSI Line Color.")
showStandardGlow = input.bool(true, "Show Glow", inline="stdglow", group="Standard
RSI",
tooltip="Toggle the thick glow line behind the Standard RSI.")
standardColorGlow = input.color(color.new(color.white, 70), "", inline="stdglow",
group="Standard RSI",
tooltip="Glow line color for the Standard RSI. Use a semi-transparent version
of the line color.")
smoothStandard = input.bool(true, "Smoothing? --- Amount →", inline="rsi",
group="Standard RSI",
tooltip="Enables smoothing of the standard RSI line to reduce choppiness and
emphasize trend bias.")
smoothLenStandard = input.int(8, "", inline="rsi", group="Standard RSI", minval=1,
tooltip="Smoothing length for the standard RSI. Uses WMA smoothing for added
responsiveness.")
//////////////////////////////
// === Candle Count RSI === //
//////////////////////////////
showCandle = input.bool(true, "Candle Count RSI", inline="ccColor", group="Candle
RSI",
tooltip="Enables plotting of the Candle Count RSI, which is calculated based
on the frequency of candles closing above or below their open. This version ignores
price magnitude and focuses only on directional consistency.")
candleCountColor = input.color(color.fuchsia, "", inline="ccColor", group="Candle
RSI",
tooltip="Candle Count RSI Line Color.")
showCandleGlow = input.bool(true, "Show Glow", inline="candleglow", group="Candle
RSI",
tooltip="Toggle the thick glow line behind the Candle Count RSI.")
candleCountColorGlow = input.color(color.new(color.fuchsia, 70), "",
inline="candleglow", group="Candle RSI",
tooltip="Glow line color for the Candle Count RSI. Use a semi-transparent
version of the line color.")
smoothCandle = input.bool(true, "Smoothing? --- Amount →", inline="ccrsi",
group="Candle RSI",
tooltip="Enables smoothing for the Candle Count RSI line to reduce noise and
enhance directionality.")
smoothLenCandle = input.int(8, "", inline="ccrsi", group="Candle RSI", minval=1,
tooltip="Smoothing length for the Candle Count RSI. Uses WMA smoothing for
better directional signal.")
////////////////////////////////////
// === RSI Glow Visualization === //
////////////////////////////////////
masterGlowToggle = input.bool(true, "Enable All Glows", group="Glow Visuals",
tooltip="Turns all glow effects on or off—including line glows, background
glows, and divergence glows.")
showGlow = input.bool(true, "RSI Glow Zones", group="Glow Visuals",
tooltip="Displays a background glow on the main chart when Candle RSI crosses
above or below 50. Helps visualize directional bias from the RSI logic.")
showSubpaneGlow = input.bool(true, "Indicator", group="Glow Visuals",
tooltip="Shows the RSI glow background behind the indicator in the subpane.")
showChartGlow = input.bool(false, "Main Chart", group="Glow Visuals",
tooltip="Shows the RSI glow background on the main chart (price panel).")
glowStrengthMult = input.float(5.0, "Glow Intensity", group="Glow Visuals",
minval=1, maxval=20,
tooltip="Controls the fade strength of the RSI glow. Higher values cause more
aggressive fade as Candle RSI diverges from 50.")
bullGlowColor = input.color(color.green, "Bull", inline="glow", group="Glow
Visuals",
tooltip="Color for glow when Candle RSI is above 50, indicating directional
bias toward bullish activity.")
bearGlowColor = input.color(color.red, "Bear", inline="glow", group="Glow Visuals",
tooltip="Color for glow when Candle RSI is below 50, indicating directional
bias toward bearish activity.")
//////////////////////////////
// === Divergence Zones === //
//////////////////////////////
showDivBG = input.bool(true, "Divergence Backgrounds", group="Divergence Zones",
tooltip="Enables background fills when divergence conditions are detected
between the Candle RSI and standard RSI. Useful for catching subtle market
inflection points.")
divTransp = input.int(80, "Transparency", step=10, minval=0, maxval=100,
group="Divergence Zones",
tooltip="Transparency level for divergence background fills. Lower values are
more opaque, higher values are more transparent.")
showDivSubpane = input.bool(true, "Indicator", group="Divergence Zones",
tooltip="Shows divergence background fill in the RSI indicator subpane.")
showDivChart = input.bool(false, "Main Chart", group="Divergence Zones",
tooltip="Shows divergence background fill on the main price chart.")
bullDivColor = input.color(color.orange, "Bull", inline="div", group="Divergence
Zones",
tooltip="Background color for bullish divergence: Candle RSI shows strength
(>50), but standard RSI is weak (<45). Indicates early accumulation or hidden
buying pressure.")
bearDivColor = input.color(color.blue, "Bear", inline="div", group="Divergence
Zones",
tooltip="Background color for bearish divergence: Candle RSI shows weakness
(<50), but standard RSI is elevated (>55). Indicates stealth distribution or fading
momentum.")
bullDivThresh = input.float(45.0, "Bullish RSI Threshold", step=0.5,
group="Divergence Zones",
tooltip="Standard RSI must be BELOW this value while Candle RSI is ABOVE 50 to
trigger a bullish divergence signal.")
bearDivThresh = input.float(55.0, "Bearish RSI Threshold", step=0.5,
group="Divergence Zones",
tooltip="Standard RSI must be ABOVE this value while Candle RSI is BELOW 50 to
trigger a bearish divergence signal.")
///////////////////////////////////
// === Directional Histogram === //
///////////////////////////////////
showDirectionHistogram = input.bool(true, "Show Directional Histogram",
group="Directional Histogram",
tooltip="Displays a histogram centered at 50 showing the distance between
Candle Count RSI and Standard RSI. Colored based on directional agreement.")
histBullColor = input.color(color.lime, "Bullish Agreement", inline="hist",
group="Directional Histogram",
tooltip="Color when both RSI lines are rising together.")
histBearColor = input.color(color.red, "Bearish Agreement", inline="hist",
group="Directional Histogram",
tooltip="Color when both RSI lines are falling together.")
histNeutralColor = input.color(color.yellow, "Conflict", inline="hist",
group="Directional Histogram",
tooltip="Color when RSI lines are moving in opposite directions.")
histTransparency = input.int(70, "Transparency", minval=0, maxval=100, step=5,
group="Directional Histogram",
tooltip="Transparency of the directional histogram fill.")
//////////////////////////
// === STANDARD RSI === //
//////////////////////////
rawRSI = ta.rsi(close, length)
rsi = smoothStandard ? ta.wma(rawRSI, smoothLenStandard) : rawRSI
///////////////////////////////////////////////
// === Candle Count Streak Amplified RSI === //
///////////////////////////////////////////////
up = close > open ? 1.0 : 0.0
down = close < open ? 1.0 : 0.0
avgUp = ta.rma(up, length)
avgDown = ta.rma(down, length)
rs = avgDown == 0 ? na : avgUp / avgDown
rawCandleRSI = avgDown == 0 ? 100 : 100 - (100 / (1 + rs))
// === Streak Length Tracking
var int greenStreak = 0
var int redStreak = 0
if close > open
greenStreak := nz(greenStreak[1]) + 1
redStreak := 0
else if close < open
redStreak := nz(redStreak[1]) + 1
greenStreak := 0
else
greenStreak := nz(greenStreak[1])
redStreak := nz(redStreak[1])
// === Apply Amplification
streakLength = close > open ? greenStreak : redStreak
streakMult = 1 + math.min(streakLength, 10) * 0.05 // e.g., 1.0–1.5 for streaks 0–
10
// === Amplified Candle RSI
candleRSI_unsmoothed = rawCandleRSI > 50
? 50 + (rawCandleRSI - 50) * streakMult
: 50 - (50 - rawCandleRSI) * streakMult
// === Final Smoothed Candle RSI
candleRSI = smoothCandle ? ta.wma(candleRSI_unsmoothed, smoothLenCandle) :
candleRSI_unsmoothed
//////////////////////////////////////////////////////////////
// === MACD-Style Histogram: Candle RSI vs Standard RSI === //
//////////////////////////////////////////////////////////////
// === Directional Histogram Logic
candleSlope = candleRSI - candleRSI[1]
standardSlope = rsi - rsi[1]
rsiDelta = candleRSI - rsi
// === Color Logic with Inputs
histColor = candleSlope > 0 and standardSlope > 0 ? color.new(histBullColor,
histTransparency) :
candleSlope < 0 and standardSlope < 0 ? color.new(histBearColor,
histTransparency) :
color.new(histNeutralColor, histTransparency)
// === Plot Histogram Centered at 50 (when enabled)
histTop = showDirectionHistogram ? rsiDelta + 50 : na
histLine = plot(histTop, title="Directional Histogram Top", color=na)
histBase = plot(showDirectionHistogram ? 50 : na, title="Directional Histogram
Base", color=na)
fill(histLine, histBase, color=showDirectionHistogram ? histColor : na,
title="Directional Histogram Fill")
//////////////////////////////////////////
// === GLOW BACKGROUND (Main Chart) === //
//////////////////////////////////////////
// === Dynamic Fade Logic Based on Distance from 50
bullFadeStrength = candleRSI > 50 ? 100 - math.min((candleRSI - 50) *
glowStrengthMult, 100) : na
bearFadeStrength = candleRSI < 50 ? 100 - math.min((50 - candleRSI) *
glowStrengthMult, 100) : na
// --- Subpane Glow
bgcolor(masterGlowToggle and showGlow and showSubpaneGlow and not
na(bullFadeStrength) ? color.new(bullGlowColor, bullFadeStrength) : na,
title="Bullish Candle RSI Subpane Glow")
bgcolor(masterGlowToggle and showGlow and showSubpaneGlow and not
na(bearFadeStrength) ? color.new(bearGlowColor, bearFadeStrength) : na,
title="Bearish Candle RSI Subpane Glow")
// --- Main Chart Glow
bgcolor(masterGlowToggle and showGlow and showChartGlow and not
na(bullFadeStrength) ? color.new(bullGlowColor, bullFadeStrength) : na,
title="Bullish Candle RSI Chart Glow", force_overlay=true)
bgcolor(masterGlowToggle and showGlow and showChartGlow and not
na(bearFadeStrength) ? color.new(bearGlowColor, bearFadeStrength) : na,
title="Bearish Candle RSI Chart Glow", force_overlay=true)
////////////////////////////////////////////////
// === DIVERGENCE CONDITIONS + BACKGROUND === //
////////////////////////////////////////////////
bullDiv = candleRSI > 50 and rsi < bullDivThresh
bearDiv = candleRSI < 50 and rsi > bearDivThresh
// --- Subpane Divergence Glows
bgcolor(masterGlowToggle and showDivBG and showDivSubpane and bullDiv ?
color.new(bullDivColor, divTransp) : na, title="Bullish Divergence Subpane BG")
bgcolor(masterGlowToggle and showDivBG and showDivSubpane and bearDiv ?
color.new(bearDivColor, divTransp) : na, title="Bearish Divergence Subpane BG")
// --- Main Chart Divergence Glows
bgcolor(masterGlowToggle and showDivBG and showDivChart and bullDiv ?
color.new(bullDivColor, divTransp) : na, title="Bullish Divergence Chart BG",
force_overlay=true)
bgcolor(masterGlowToggle and showDivBG and showDivChart and bearDiv ?
color.new(bearDivColor, divTransp) : na, title="Bearish Divergence Chart BG",
force_overlay=true)
///////////////////////
// === RSI PLOTS === //
///////////////////////
plot(showStandard ? rsi : na, title="Standard RSI", color=standardColor, linewidth=
1)
plot(masterGlowToggle and showStandardGlow ? rsi : na, title="Standard RSI Glow",
color=standardColorGlow, linewidth=5)
plot(showCandle ? candleRSI : na, title="Candle Count RSI",
color=candleCountColor, linewidth= 1)
plot(masterGlowToggle and showCandleGlow ? candleRSI : na, title="Candle Count
RSI Glow", color=candleCountColorGlow, linewidth=5)
///////////////////////////////
// === HORIZONATAL LINES === //
///////////////////////////////
// === OVERBOUGHT GLOW HLINES ===
hline(70, "Overbought", color=color.red, linestyle=hline.style_solid)
hline(masterGlowToggle ? 70 : na, "Mid 70 Glow", color=color.new(color.red, 60),
linewidth=9, linestyle=hline.style_solid)
hline(masterGlowToggle ? 70 : na, "High 70 Glow", color=color.new(color.red, 70),
linewidth=18, linestyle=hline.style_solid)
// === BIAS LINE ===
hline(50, "Bias Midline", color=color.gray, linestyle=hline.style_dotted)
// === OVERSOLD GLOW HLINES ===
hline(masterGlowToggle ? 30 : na, "High 30 Glow", color=color.new(color.green, 70),
linewidth=18, linestyle=hline.style_solid)
hline(masterGlowToggle ? 30 : na, "Mid 30 Glow", color=color.new(color.green, 60),
linewidth=9, linestyle=hline.style_solid)
hline(30, "Oversold", color=color.green, linestyle=hline.style_solid)