#ReversedEngineeredRSI_Upper_Lowerbands mod by LAR
#Modified by Chewie 9/4/2025
input colorbar = yes;
input length = 5;
input price = close;
input rsiValueob = 80.0;
input rsiValue = 70.0;
input rsiValue1 = 30.0;
input rsiValueos = 20.0;
input smoothingType = {default Wilders, EMA};
def coeff = rsiValue / (100 - rsiValue);
def chg = price - price[1];
def diff;
switch (smoothingType) {
case Wilders:
diff = (length - 1) * (WildersAverage(Max(-chg, 0), length) * coeff - WildersAverage(Max(chg, 0), length));
case EMA:
diff = (length - 1) * (ExpAverage(Max(-chg, 0), length) * coeff - ExpAverage(Max(chg, 0), length)) / 2;
}
def value = price + if diff >= 0 then diff else diff / coeff;
plot RevEngRSI = compoundValue(1, value[1], Double.NaN);
RevEngRSI.SetDefaultColor(Color.red);
def coeff1 = rsiValue1 / (100 - rsiValue1);
def chg1 = price - price[1];
def diff1;
switch (smoothingType) {
case Wilders:
diff1 = (length - 1) * (WildersAverage(Max(-chg1, 0), length) * coeff1 - WildersAverage(Max(chg1, 0), length));
case EMA:
diff1 = (length - 1) * (ExpAverage(Max(-chg1, 0), length) * coeff1 - ExpAverage(Max(chg1, 0), length)) / 2;
}
def value1 = price + if diff1 >= 0 then diff1 else diff1 / coeff1;
plot RevEngRSI1 = compoundValue(1, value1[1], Double.NaN);
RevEngRSI1.SetDefaultColor(Color.green);
input rsiValue2 = 50.0;
input smoothingType2 = {default Wilders, EMA};
def coeff2 = rsiValue2 / (100 - rsiValue2);
def chg2 = price - price[1];
def diff2;
switch (smoothingType2) {
case Wilders:
diff2 = (length - 1) * (WildersAverage(Max(-chg2, 0), length) * coeff2 - WildersAverage(Max(chg2, 0), length));
case EMA:
diff2 = (length - 1) * (ExpAverage(Max(-chg2, 0), length) * coeff2 - ExpAverage(Max(chg2, 0), length)) / 2;
}
def value2 = price + if diff2 >= 0 then diff2 else diff2 / coeff2;
plot RevEngRSI2 = compoundValue(1, value2[1], Double.NaN);
RevEngRSI2.SetDefaultColor(Color.yellow);
def coeffob = rsiValueob / (100 - rsiValueob);
def chgob = price - price[1];
def diffob;
switch (smoothingType2) {
case Wilders:
diffob = (length - 1) * (WildersAverage(Max(-chgob, 0), length) * coeffob - WildersAverage(Max(chgob, 0), length));
case EMA:
diffob = (length - 1) * (ExpAverage(Max(-chgob, 0), length) * coeffob - ExpAverage(Max(chgob, 0), length)) / 2; }
def valueob = price + if diffob >= 0 then diffob else diffob / coeffob;
plot RevEngRSIob = compoundValue(1, valueob[1], Double.NaN);
RevEngRSIob.SetDefaultColor(Color.magenta);
def coeffos = rsiValueos / (100 - rsiValueos);
def chgos = price - price[1];
def diffos;
switch (smoothingType2) {
case Wilders:
diffos = (length - 1) * (WildersAverage(Max(-chgos, 0), length) * coeffos - WildersAverage(Max(chgos, 0), length));
case EMA:
diffos = (length - 1) * (ExpAverage(Max(-chgos, 0), length) * coeffos - ExpAverage(Max(chgos, 0), length)) / 2; }
def valueos = price + if diffos >= 0 then diffos else diffos / coeffos;
plot RevEngRSIos = compoundValue(1, valueos[1], Double.NaN);
RevEngRSIos.SetDefaultColor(Color.cyan);
addcloud(revEngRSI,revEngRSIob,color.red,color.red);
AddCloud(revEngRSIos, data2 = RevEngRSI1, color2 = Color.green, color1 = Color.green);
def OS = close < RevEngRSI1;
def OB = close > RevEngRSI;
AssignPriceColor(if !ColorBar then Color.CURRENT else if OS then color.green else if OB then color.red else Color.gray);