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

//@version=5

//---------------Stochastic RSI Heatmap-----------------


indicator(title="Stochastic RSI Heatmap", overlay=true,  shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=false)

// Stochastic RSI settings
var string GRP1       = '══════════   Settings   ══════════'
smoothK = input.int(3, "K", minval=1, group=GRP1)
smoothD = input.int(3, "D", minval=1, group=GRP1)
lengthRSI = input.int(14, "RSI Length", minval=1, group=GRP1)
lengthStoch = input.int(14, "Stochastic Length", minval=1, group=GRP1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

// BUY ZONE levels

var string GRP2       = '══════════   BUY ZONE   ══════════'
BuyStoRSI1 = input.int (defval = 20, title="Oversold Zone 1", minval=1, maxval=100, group=GRP2) 
BuyStoRSI2 = input.int (defval = 15, title="Oversold Zone 2", minval=1, maxval=100, group=GRP2) 
BuyStoRSI3 = input.int (defval = 10, title="Oversold Zone 3", minval=1, maxval=100, group=GRP2) 
BuyStoRSI4 = input.int (defval = 5, title="Oversold Zone 4", minval=1, maxval=100, group=GRP2) 

//  SELL ZONE levels

var string GRP3       = '══════════   SELL ZONE   ══════════'
SellStoRSI1 = input.int (defval = 80, title="Overbought Zone 1", minval=1, maxval=100, group=GRP3)
SellStoRSI2 = input.int (defval = 85, title="Overbought Zone 2", minval=1, maxval=100, group=GRP3)
SellStoRSI3 = input.int (defval = 90, title="Overbought Zone 3", minval=1, maxval=100, group=GRP3)
SellStoRSI4 = input.int (defval = 95, title="Overbought Zone 4", minval=1, maxval=100, group=GRP3)



// Calculations
BUY1 = k < BuyStoRSI1 and d < BuyStoRSI1
BUY2 = k < BuyStoRSI2 and d < BuyStoRSI2
BUY3 = k < BuyStoRSI3 and d < BuyStoRSI3
BUY4 = k < BuyStoRSI4 and d < BuyStoRSI4

SELL1 = k > SellStoRSI1 and d > SellStoRSI1
SELL2 = k > SellStoRSI2 and d > SellStoRSI2
SELL3 = k > SellStoRSI3 and d > SellStoRSI3
SELL4 = k > SellStoRSI4 and d > SellStoRSI4

// Colors

bgcolor (BUY1 ? color.new(color.blue,65) : na, title= "Background StoRSI Oversold Zone 1") 
bgcolor (BUY2 ? color.new(color.blue,65) : na, title= "Background StoRSI Oversold Zone 2") 
bgcolor (BUY3 ? color.new(color.blue,55) : na, title= "Background StoRSI Oversold Zone 3") 
bgcolor (BUY4 ? color.new(color.blue,1) : na, title= "Background StoRSI Oversold Zone 4")  

bgcolor (SELL1 ? color.new(color.fuchsia,75) : na, title= "Background StoRSI Overbought Zone 1") 
bgcolor (SELL2 ? color.new(color.fuchsia,65) : na, title= "Background StoRSI Overbought Zone 2") 
bgcolor (SELL3 ? color.new(color.fuchsia,55) : na, title= "Background StoRSI Overbought Zone 3") 
bgcolor (SELL4 ? color.new(color.fuchsia,1) : na, title= "Background StoRSI Overbought Zone 4") 


