```
# RSI with Standard Deviation_Channels
# Horserider 2/5/2020
declare lower;
#RSI
input length = 14;
input price = close;
input averageType = AverageType.WILDERS;
def NetChgAvg = MovingAverage(averageType, price - price[1], length);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
plot RSI = 50 * (ChgRatio + 1);
#
RSI.DefineColor("Positive and Up", Color.GREEN);
RSI.DefineColor("Positive and Down", Color.DARK_GREEN);
RSI.DefineColor("Negative and Down", Color.RED);
RSI.DefineColor("Negative and Up", Color.DARK_RED);
RSI.AssignValueColor(if RSI >= 50 then if RSI > RSI[1] then RSI.Color("Positive and Up") else RSI.Color("Positive and Down") else if RSI < RSI[1] then RSI.Color("Negative and Down") else RSI.Color("Negative and Up"));
####################################
input deviations = 2.0;
input fullRange = Yes;
input lengthsd = 21;
def regression;
def stdDeviation;
if (fullRange) {
regression = InertiaAll(rsi);
stdDeviation = stdevAll(rsi);
} else {
regression = InertiaAll(rsi, lengthsd);
stdDeviation = stdevAll(rsi, lengthsd);
}
plot UpperLine = regression + deviations * stdDeviation;
plot MiddleLine = regression;
plot LowerLine = regression - deviations * stdDeviation;
UpperLine.SetDefaultColor(GetColor(2));
MiddleLine.SetDefaultColor(GetColor(8));
LowerLine.SetDefaultColor(GetColor(6));
input deviations2 =1.30;
input fullRange2 = Yes;
input lengthsd2 = 21;
def regression2;
def stdDeviation2;
if (fullRange) {
regression2 = InertiaAll(rsi);
stdDeviation2 = stdevAll(rsi);
} else {
regression2 = InertiaAll(rsi, lengthsd2);
stdDeviation2 = stdevAll(rsi, lengthsd2);
}
plot UpperLine2 = regression2 + deviations2 * stdDeviation2;
plot MiddleLine2 = regression2;
plot LowerLine2 = regression2 - deviations2 * stdDeviation2;
UpperLine2.SetDefaultColor(GetColor(3));
MiddleLine2.SetDefaultColor(GetColor(8));
LowerLine2.SetDefaultColor(GetColor(7));
#########################################
input AverageTypeBB = {default SMA, EMA};
input displaceBB = 0;
input lengthBB = 5;
plot midline ;
switch (AverageTypeBB) {
case SMA:
midline = reference BollingerBands(RSI, displaceBB, lengthBB , averageType = AverageType.EXPONENTIAL).Midline;
case EMA:
midline = reference BollingerBands(RSI, displaceBB, lengthBB, averageType = AverageType.EXPONENTIAL).Midline;
}
midline.SetDefaultColor(GetColor(3));
```