```
# Smoothed RSI2
# Pensar
# Created early 2020
# Released 05.18.2021 - V.1.0
# This indicator is an simple variation of the Connors 2-period RSI.
# It uses the third price value back to smooth the RSI plot.
#https://usethinkscript.com/threads/multiple-time-frame-mtf-rsi-indicator-for-thinkorswim.616/page-2
declare lower;
input period = 2;
input over_bought = 90;
input over_sold = 10;
input idata = close;
input averageType = AverageType.WILDERS;
input length = 14;
input over_Bought_a = 80;
input over_Sold_a = 20;
input price = close;
input averageType_a = AverageType.WILDERS;
input length2 = 14;
input price2 = close;
input averageType2 = AverageType.WILDERS;
input agg = AggregationPeriod.DAY;
input MALength = 8;
input AverageType1 = AverageType.SIMPLE;
input length3 = 14;
input price3 = close;
input averageType3 = AverageType.WILDERS;
input agg3 = AggregationPeriod.WEEK;
def src_1 = ohlc4;
input len_1 = 9;
def len_2 = 2 * len_1;
def len_3 = 2 * len_2;
input Over_Bought1 = 70;
def MidLine = 50;
input Over_Sold1 = 30;
def NetChgAvg1 = ExpAverage(src_1 - src_1[1], len_1);
def TotChgAvg1 = ExpAverage(AbsValue(src_1 - src_1[1]), len_1);
def ChgRatio1 = if TotChgAvg1 != 0
then NetChgAvg1 / TotChgAvg1
else 0;
plot rsi1 = 50 * (ChgRatio1 + 1);
RSI1.DefineColor("Positive and Up", Color.GREEN);
RSI1.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI1.DefineColor("Negative and Down", Color.RED);
RSI1.DefineColor("Negative and Up", Color.DARK_RED);
RSI1.AssignValueColor(if RSI1 >= 50 then if RSI1 > RSI1[1] then RSI1.Color("Positive and Up") else RSI1.Color("Positive and Down") else if RSI1 < RSI1[1] then RSI1.Color("Negative and Down") else RSI1.Color("Negative and Up"));
RSI1.SetLineWeight(5);
def NetChgAvg2 = ExpAverage(src_1 - src_1[1], len_2);
def TotChgAvg2 = ExpAverage(AbsValue(src_1 - src_1[1]), len_2);
def ChgRatio2 = if TotChgAvg1 != 0
then NetChgAvg2 / TotChgAvg2
else 0;
plot rsi2 = 50 * (ChgRatio2 + 1);
def NetChgAvg3 = ExpAverage(src_1 - src_1[1], len_3);
def TotChgAvg3 = ExpAverage(AbsValue(src_1 - src_1[1]), len_3);
def ChgRatio3 = if TotChgAvg1 != 0
then NetChgAvg3 / TotChgAvg3
else 0;
plot rsi3 = 50 * (ChgRatio3 + 1);
plot middle_Line = MidLine;
plot Over_Bought_Line = Over_Bought1;
plot Over_Sold_Line = Over_Sold1;
plot Over_Bought_line1 = 90;
plot Over_sold_line1 = 10;
def NetChgAvg = MovingAverage(averageType, idata - idata[3], period);
def TotChgAvg = MovingAverage(averageType, AbsValue(idata - idata[3]), period);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
RSI.DefineColor("OverBought", Color.RED);
RSI.DefineColor("Normal", Color.white);
RSI.DefineColor("OverSold", Color.GREEN);
RSI.AssignValueColor(if RSI > over_bought then RSI.Color("OverBought")
else if RSI < over_sold then RSI.Color("OverSold")
else RSI.Color("Normal"));
RSI.SetLineWeight(4);
plot OverSold = over_sold;
plot OverBought = over_bought;
OverSold.SetDefaultColor(Color.GREEN);
OverSold.SetStyle(Curve.SHORT_DASH);
OverSold.SetLineWeight(3);
OverBought.SetDefaultColor(Color.RED);
OverBought.SetStyle(Curve.SHORT_DASH);
OverSold.SetLineWeight(3);
AddCloud(if RSI > OverBought then RSI else Double.NaN, OverBought, Color.RED, Color.RED);
AddCloud(if RSI < OverSold then RSI else Double.NaN, OverSold, Color.GREEN, Color.GREEN);
def NetChgAvg_a = MovingAverage(averageType_a, price - price[1], length);
def TotChgAvg_a = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio_a = if TotChgAvg_a != 0 then NetChgAvg_a / TotChgAvg_a else 0;
plot RSI_a = 50 * (ChgRatio + 1);
RSI_a.DefineColor("Positive and Up", Color.GREEN);
RSI_a.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI_a.DefineColor("Negative and Down", Color.RED);
RSI_a.DefineColor("Negative and Up", Color.DARK_RED);
RSI_a.AssignValueColor(if RSI_a >= 50 then if RSI_a > RSI_a[1] then RSI_a.Color("Positive and Up") else RSI_a.Color("Positive and Down") else if RSI_a < RSI_a[1] then RSI_a.Color("Negative and Down") else RSI_a.Color("Negative and Up"));
def c = close(period = agg);
def NetChgAvg2_a = MovingAverage(averageType2, c - c[1], length2);
def TotChgAvg2_a = MovingAverage(averageType2, AbsValue(c - c[1] ), length2);
def ChgRatio2_a = if TotChgAvg2_a != 0 then NetChgAvg2_a / TotChgAvg2_a else 0;
plot RSI2_a = 50 * (ChgRatio2 + 1);
RSI2_a.DefineColor("Positive and Up", Color.GREEN);
RSI2_a.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI2_a.DefineColor("Negative and Down", Color.RED);
RSI2_a.DefineColor("Negative and Up", Color.DARK_RED);
RSI2_a.AssignValueColor(if RSI2_a >= 50 then if RSI2_a > RSI2_a[1] then RSI2_a.Color("Positive and Up") else RSI2_a.Color("Positive and Down") else if RSI2_a < RSI2_a[1] then RSI2_a.Color("Negative and Down") else RSI2_a.Color("Negative and Up"));
RSI2_a.SetLineWeight(3);
def MA = MovingAverage(AverageType1, rsi2, MALength);
plot pMA = MA;
pMA.AssignValueColor(if PMA > PMA[1] then Color.green else Color.magenta);
PMA.SetLineWeight(2);
def c3 = close(period = agg3);
def NetChgAvg3_a = MovingAverage(averageType3, c3 - c3[1], length3);
def TotChgAvg3_a = MovingAverage(averageType3, AbsValue(c3 - c3[1]), length3);
def ChgRatio3_a = if TotChgAvg3_a != 0 then NetChgAvg3_a / TotChgAvg3_a else 0;
plot RSI3_a = 50 * (ChgRatio3 + 1);
RSI3_a.DefineColor("Positive and Up", Color.GREEN);
RSI3_a.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI3_a.DefineColor("Negative and Down", Color.RED);
RSI3_a.DefineColor("Negative and Up", Color.DARK_RED);
RSI3_a.AssignValueColor(if RSI3_a >= 50 then if RSI3_a > RSI3_a[1] then RSI3_a.Color("Positive and Up") else RSI3_a.Color("Positive and Down") else if RSI3_a < RSI3_a[1] then RSI3_a.Color("Negative and Down") else RSI3_a.Color("Negative and Up"));
RSI3_a.SetLineWeight(5);
#addCloud(RSI, RSI2, color.green, color.red);
```