The main fault in your code is that it does not even attempt to plot the ReverseEngineeringRSI.
Specifically, the line of code you label as RevEngRSI does not compute anything at all.
plot RevEngRSI = compoundValue(50, value[50], Double.NaN);
In fact if you try to load your code into a new chart study it will generate an error because you are trying to reference an undeclared variable named "value".
In order to plot the ReverseEngineeringRSI you need to include all of the code from that chart study along with lines of code to compute the moving average and then one more line of code to add the shading between those two plots.
The following section of code will provide a chart study that performs as you have requested:
input maLengthOne = 28;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input length = 14;
input price = close;
input rsiValue = 50.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);
plot maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
AddCloud(maOne, RevEngRSI, Color.CYAN, Color.MAGENTA);