Great question and thanks for providing a detailed explanation and a title that immediately helps the rest of our viewers to know exactly what to expect when they click on your post.
We have a similar solution posted here:
I will be using the code from that post as the basis for this solution. It only requires a few minor tweaks. However the solution to color the cloud based on the RSI being overbought or oversold may seem very complicated and confusing to some. The reason for this complication is that the AddCloud() statement does not permit us to conditionally set the colors. Which means we have to use two AddCloud() statements. One for the overbought condition and another for the oversold condition.
For those interested in learning the technical details about the AddCloud() statement I will provide a link to the official Thinkorswim documentation:
And if we want the end user to be able to adjust the colors we'll have to create some global colors. Details here:
Now let's see what the full solution looks like:
input length = 2;
input price = close;
input averageType = AverageType.WILDERS;
input overbought = 90;
input oversold = 10;
def rsi = RSI(length, overbought, oversold, price, averageType).RSI;
AddCloud(if rsi > overbought then high else Double.NaN,
if rsi > overbought then low else Double.NaN, GlobalColor("overbought"), Color.CURRENT);
AddCloud(if rsi < oversold then high else Double.NaN,
if rsi < oversold then low else Double.NaN, GlobalColor("oversold"), Color.CURRENT);
I have included a screenshot below to show the result. The default colors of dark green and dark red did not show up very well. So I adjusted the colors through the global settings to cyan and magenta. Clearly this needs a color scheme that makes it stand out from the colors of the candles.