Stochastic RSI Heat Candles Overlay
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © noop42

//@version=5
indicator("Stochastic RSI Heat Candles Overlay", shorttitle="SRSI Heat Candles", overlay=true)

invert_colors = input.bool(title="Invert colors", defval=false, group='Color options')
color_style = input.string("R/G", options=["R/G", "G/B", "B/R"], title="Shading colors", group='Color options')
z_color = input.int(0, "Third Color", minval=0, maxval=255, group='Color options')
trans = input.int(0, "Transparency", minval=0, maxval=100, group='Color options')

color_value(value, transp=0) =>
    step = (255/100.0)
    d = value * step
    x = 0.0
    y = 0.0
    z = z_color
    if invert_colors
        x := value < 50 ? d : 127
        y := value < 50 ? 127: 255 - d
    else
        y := value < 50 ? d : 127
        x := value < 50 ? 127: 255 - d
    col = color.rgb(math.round(x), math.round(y), math.round(z), transp)
    if color_style == "B/R"
        col := color.rgb(math.round(y), math.round(z), math.round(x), transp)        
    if color_style == "G/B"
        col := color.rgb(math.round(z), math.round(x), math.round(y), transp)
    col

show_side = input.bool(false, "Show candle side", group='Options')
bullish_color = input.color(#10a9eb50, "Bullish Candle Mark", group='Color options')
bearish_color = input.color(#e0692850, "bearish Candle Mark", group='Color options')
mode = input.string("Color candles", options=["Color candles", "Border only"], title="Overlay style", group='Color options')

smoothK = input.int(3, "K", minval=1, group='Stochastic RSI')
smoothD = input.int(3, "D", minval=1, group='Stochastic RSI')
lengthRSI = input.int(14, "RSI Length", minval=1, group='Stochastic RSI')
lengthStoch = input.int(14, "Stochastic Length", minval=1, group='Stochastic RSI')
srsi_src = input(close, title="RSI Source", group='Stochastic RSI')

// Calculations SRSI
rsi = ta.rsi(srsi_src, lengthRSI)
k =  ta.sma(ta.stoch(rsi, rsi, rsi, lengthRSI), smoothK)
d = ta.sma(k, smoothD)
a = (k + d) / 2
ob = a > 80
os = a < 20
col = color_value(a, trans)
body_color = mode == "Border only" or mode == "Shape only"? #00000000 : col

plotcandle(open, high, low, close, color=body_color, wickcolor=col, bordercolor=col)
plotshape(ob or os ? 1 : 0, location=location.top, color=col, style=shape.circle)
plotshape(show_side and open < close ? 1 : 0, location=location.belowbar, color=bullish_color, style=shape.circle)

plotshape(show_side and open > close ? 1 : 0, location=location.abovebar, color=bearish_color, style=shape.circle)


