# @RolandoSantos
#study(title="TKP RSI BAR COLOR", overlay=true, shorttitle="TKP-RSI BC")
# converted by Sam4Cok@Samer800 - 01/2025
# Added Color Bar Options - Sam4Cok@Samer800 - 02/2025
input timeframe = AggregationPeriod.MIN;
input colorOptions = {Default "Gradient", "2 Tones", "Don't Color Bar"};
input signalType = {Default "Reversal Signal", "Trend Signal", "Don't Show"};
input src = FundamentalType.CLOSE;
input len = 14;
input overbought = 75;
input oversold = 25;
def na = DOuble.NaN;
def cap = GetAGgregationPeriod();
def tf = Max(cap, timeframe);
def gradient = colorOptions==colorOptions."Gradient";
def noColor = colorOptions==colorOptions."Don't Color Bar";
##// ~~ Gradient Coloring {
Script gradient_color {
input src = close;
input minVal = 10;
input maxVal = 400;
input loR = 173;
input loG = 216;
input loB = 230;
input hiR = 41;
input hiG = 98;
input hiB = 255;
def value = if isNaN(src) then 0 else src;
def clamped_value = max(min(value, maxVal), minVal);
def normalized_value = (clamped_value - minVal) / (maxVal - minVal);
def re = floor(loR + (hiR - loR) * normalized_value);
def gr = floor(loG + (hiG - loG) * normalized_value);
def bl = floor(loB + (hiB - loB) * normalized_value);
plot r = re;
plot g = gr;
plot b = bl;
}
def nRSI = rsi(Price = Fundamental(src, period = tf), length = len);
def colR = gradient_color(nRSI, oversold, overbought, 255, 0, 0, 0, 255, 0).r;
def colG = gradient_color(nRSI, oversold, overbought, 255, 0, 0, 0, 255, 0).g;
def colB = gradient_color(nRSI, oversold, overbought, 255, 0, 0, 0, 255, 0).b;
def crossUp;
def crossDn;
Switch (signalType) {
Case "Don't Show" :
crossUp = na;
crossDn = na;
Case "Trend Signal" :
crossUp = nRSI Crosses Above overbought;
crossDn = nRSI Crosses Below oversold;
Default :
crossUp = nRSI Crosses Above oversold;
crossDn = nRSI Crosses Below overbought;
}
plot sigUp = if !crossDn[1] and crossUp and !crossUp[1] then low else na;
plot sigDn = if !crossUp[1] and crossDn and !crossDn[1] then high else na;
sigUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
sigDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
sigUp.SetDefaultColor(Color.CYAN);
sigDn.SetDefaultColor(Color.MAGENTA);
#AssignPriceColor(if !colorBars then Color.CURRENT else CreateColor(colR,colG, colB));
AssignPriceColor(if noColor then Color.CURRENT else
if gradient then CreateColor(colR,colG, colB) else
if nRSI > 50 then Color.WHITE else Color.RED );
#-- END of CODE