# RSI Bands For ThinkOrSwim

#### kd312

##### New member
Hi,

//@version=3
study("RSI Bands 30-50-70", shorttitle="RSI Bands 30-50-70", overlay=true)

length = input(14, title="RSI Length")

seventy = 70
fifty = 50
thirty = 30

ep = 2 * length - 1
auc = ema( max( close - close[1], 0 ), ep )
adc = ema( max( close[1] - close, 0 ), ep )

x1 = (length - 1) * ( adc * thirty / (100-thirty) - auc)
thirtyrsi = iff( x1 >= 0, close + x1, close + x1 * (100-thirty)/thirty )

x7 = (length - 1) * ( adc * seventy / (100-seventy) - auc)
seventyrsi = iff( x7 >= 0, close + x7, close + x7 * (100-seventy)/seventy )

x13 = (length - 1) * ( adc * fifty / (100-fifty) - auc)
fiftyrsi = iff( x13 >= 0, close + x13, close + x13 * (100-fifty)/fifty )

thirtyrsiplot = plot( thirtyrsi, title="30", color=#00FF00, linewidth=3)

fiftyrsiplot = plot( fiftyrsi, title="50", color=#5280E9, linewidth=2)

seventyrsiplot = plot( seventyrsi, title="70", color=#FE0301, linewidth=3)

@kd312 Try this

Ruby:
``````#RSI_BAND
#Convered by @SuryaKiranC
#Reqested by @kd312

input     length = 14;

input    seventy = 70;
def        fifty = 50;
input     thirty = 30;

def ep = 2 * length - 1;

def auc = ExpAverage(max (close - close[1],0),ep);
def adc = ExpAverage(max (close[1] - close,0),ep);

def x1 = (length - 1) * (adc * thirty / (100-thirty) - auc);
plot thirtyrsi = if(x1 >= 0, close + x1, close + x1 * (100 - thirty)/thirty);
thirtyrsi.SetDefaultColor(CreateColor(0, 255, 0));

def x7 = (length - 1) * (adc * seventy / (100-seventy) - auc);
plot seventyrsi = if(x7 >= 0, close + x7, close + x7 * (100-seventy)/seventy);
seventyrsi.SetDefaultColor(CreateColor(82, 128, 233));

def x13 = (length - 1) * (adc * fifty / (100-fifty) - auc);
plot fiftyrsi = if(x13 >= 0, close + x13, close + x13 * (100-fifty)/fifty);
fiftyrsi.SetDefaultColor(CreateColor(254, 3, 1));
#End``````

Last edited:
RSI 60/40 strategy
@Ahmar824 If I haven't said this earlier, I am saying it now, Always love your video and explanation of what you need and what you found. This is very helpful.

Now to the matter at hand, I have customized the code for you, so your can set the band High and Low to what you want, not that 60-40 isn't great.

Below Code is for chart frame with labels.

Ruby:
``````#RSI_BAND
#Convered by @SuryaKiranC
#Reqested by @kd312

input length = 14;
input high_B = 60;
def    mid_B = 50;
input  low_B = 40;

def ep = 2 * length - 1;

def auc = ExpAverage(max (close - close[1],0),ep);
def adc = ExpAverage(max (close[1] - close,0),ep);

def x1 = (length - 1) * (adc * low_B / (100-low_B) - auc);
plot lowrsi = if(x1 >= 0, close + x1, close + x1 * (100 - low_B)/low_B);
lowrsi.SetDefaultColor(CreateColor(0, 255, 0));

def x7 = (length - 1) * (adc * high_B / (100-high_B) - auc);
plot highrsi = if(x7 >= 0, close + x7, close + x7 * (100-high_B)/high_B);
highrsi.SetDefaultColor(CreateColor(82, 128, 233));

def x13 = (length - 1) * (adc * mid_B / (100-mid_B) - auc);
plot midrsi = if(x13 >= 0, close + x13, close + x13 * (100-mid_B)/mid_B);
midrsi.SetDefaultColor(CreateColor(254, 3, 1));

plot DClose = close(period = "DAY");
DClose.SetPaintingStrategy(PaintingStrategy.DASHES);

AddLabel(!isNan(midrsi),if GetAggregationPeriod() == aggregationPeriod.MONTH then "M"
else if GetAggregationPeriod() == aggregationPeriod.WEEK then "W"
else if GetAggregationPeriod() == aggregationPeriod.FOUR_DAYS then "4D"
else if GetAggregationPeriod() == aggregationPeriod.THREE_DAYS then "3D"
else if GetAggregationPeriod() == aggregationPeriod.TWO_DAYS then "2D"
else if GetAggregationPeriod() == aggregationPeriod.DAY then "D"
else if GetAggregationPeriod() == aggregationPeriod.FOUR_HOURS then "4H"
else if GetAggregationPeriod() == aggregationPeriod.TWO_HOURS then "2H"
else if GetAggregationPeriod() == aggregationPeriod.HOUR then "60m"
else if GetAggregationPeriod() == aggregationPeriod.THIRTY_MIN then "30m"
else if GetAggregationPeriod() == aggregationPeriod.TWENTY_MIN then "20m"
else if GetAggregationPeriod() == aggregationPeriod.FIFTEEN_MIN then "15m"
else if GetAggregationPeriod() == aggregationPeriod.TEN_MIN then "10m"
else if GetAggregationPeriod() == aggregationPeriod.FIVE_MIN then "5m"
else if GetAggregationPeriod() == aggregationPeriod.FOUR_MIN then "4m"
else if GetAggregationPeriod() == aggregationPeriod.THREE_MIN then "3m"
else if GetAggregationPeriod() == aggregationPeriod.TWO_MIN then "2m"
else if GetAggregationPeriod() == aggregationPeriod.MIN then "1m"
else "",Color.GRAY);
AddLabel(yes,highrsi + " ",(CreateColor(82, 128, 233)));
AddLabel(yes,midrsi + " ",(CreateColor(254, 3, 1)));
AddLabel(yes,lowrsi + " ",(CreateColor(0, 255, 0)));
#End``````

To address another matter, for the higherFrames labels only, Would you be willing to add 2nd script, multiple times, depends on how many higher frames you want to see? if so here is the code, Just add and set each instance of the code to a different frame, only chart frame and higher will display labels.

Ruby:
``````#RSI_BAND_HF
#Convered by @SuryaKiranC
#Reqested by @kd312
#Enhancements requested by @Ahmar824

input length = 14;

input high_B = 60;
def    mid_B = 50;
input  low_B = 40;

input aP = AggregationPeriod.FIFTEEN_MIN;

Script RSI_BAND {
input length = 14;

input high_B = 60;
def    mid_B = 50;
input  low_B = 40;

input aP = AggregationPeriod.FIFTEEN_MIN;

def ep = 2 * length - 1;

def auc = ExpAverage(max(close(period = aP) - close(period = aP)[1],0),ep);
def adc = ExpAverage(max(close(period = aP)[1] - close(period = aP),0),ep);

def x1 = (length - 1) * (adc * low_B / (100 - low_B) - auc);
plot lowrsi = if(x1 >= 0, close(period = aP) + x1, close(period = aP) + x1 * (100-low_B)/low_B);

def x7 = (length - 1) * (adc * high_B / (100 - high_B) - auc);
plot highrsi = if(x7 >= 0, close(period = aP) + x7, close(period = aP) + x7 * (100-high_B)/high_B);

def x13 = (length - 1) * (adc * mid_B / (100-mid_B) - auc);
plot  midrsi = if(x13 >= 0, close(period = aP) + x13, close(period = aP) + x13 * (100 - mid_B)/mid_B);

};

def highrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).highrsi;
def  midrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).midrsi;
def  lowrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).lowrsi;

AddLabel(!isNan(midrsi),if aP == aggregationPeriod.MONTH then "M"
else if aP == aggregationPeriod.WEEK then "W"
else if aP == aggregationPeriod.FOUR_DAYS then "4D"
else if aP == aggregationPeriod.THREE_DAYS then "3D"
else if aP == aggregationPeriod.TWO_DAYS then "2D"
else if aP == aggregationPeriod.DAY then "D"
else if aP == aggregationPeriod.FOUR_HOURS then "4H"
else if aP == aggregationPeriod.TWO_HOURS then "2H"
else if aP == aggregationPeriod.HOUR then "60m"
else if aP == aggregationPeriod.THIRTY_MIN then "30m"
else if aP == aggregationPeriod.TWENTY_MIN then "20m"
else if aP == aggregationPeriod.FIFTEEN_MIN then "15m"
else if aP == aggregationPeriod.TEN_MIN then "10m"
else if aP == aggregationPeriod.FIVE_MIN then "5m"
else if aP == aggregationPeriod.FOUR_MIN then "4m"
else if aP == aggregationPeriod.THREE_MIN then "3m"
else if aP == aggregationPeriod.TWO_MIN then "2m"
else if aP == aggregationPeriod.MIN then "1m"
else "",Color.GRAY);
AddLabel(yes,highrsi + " ",(CreateColor(82, 128, 233)));
AddLabel(yes,midrsi + " ",(CreateColor(254, 3, 1)));
AddLabel(yes,lowrsi + " ",(CreateColor(0, 255, 0)));
#End``````

Now, when you get a chance, can you test this RSI_BAND 60-40 on 15m and/or 30m frames? My interest in those frames are the 30m being th last frame that can divide the trading hours candles equally for equity, and 15 for some ETF that trades extra 15m.

Last edited:
To address another matter, for the higherFrames labels only, Would you be willing to add 2nd script, multiple times, depends on how many higher frames you want to see? if so here is the code, Just add and set each instance of the code to a different frame, only chart frame and higher will display labels.

Ruby:
#RSI_BAND_HF
#Convered by @SuryaKiranC
#Reqested by @kd312
#Enhancements requested by @Ahmar824

input length = 14;

input high_B = 60;
def mid_B = 50;
input low_B = 40;

input aP = AggregationPeriod.FIFTEEN_MIN;

Script RSI_BAND {
input length = 14;

input high_B = 60;
def mid_B = 50;
input low_B = 40;

input aP = AggregationPeriod.FIFTEEN_MIN;

def ep = 2 * length - 1;

def auc = ExpAverage(max(close(period = aP) - close(period = aP)[1],0),ep);
def adc = ExpAverage(max(close(period = aP)[1] - close(period = aP),0),ep);

def x1 = (length - 1) * (adc * low_B / (100 - low_B) - auc);
plot lowrsi = if(x1 >= 0, close(period = aP) + x1, close(period = aP) + x1 * (100-low_B)/low_B);

def x7 = (length - 1) * (adc * high_B / (100 - high_B) - auc);
plot highrsi = if(x7 >= 0, close(period = aP) + x7, close(period = aP) + x7 * (100-high_B)/high_B);

def x13 = (length - 1) * (adc * mid_B / (100-mid_B) - auc);
plot midrsi = if(x13 >= 0, close(period = aP) + x13, close(period = aP) + x13 * (100 - mid_B)/mid_B);

};

def highrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).highrsi;
def midrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).midrsi;
def lowrsi = RSI_BAND(length = length,high_B = high_B,low_B = low_B,aP = aP).lowrsi;

AddLabel(!isNan(midrsi),if aP == aggregationPeriod.MONTH then "M"
else if aP == aggregationPeriod.WEEK then "W"
else if aP == aggregationPeriod.FOUR_DAYS then "4D"
else if aP == aggregationPeriod.THREE_DAYS then "3D"
else if aP == aggregationPeriod.TWO_DAYS then "2D"
else if aP == aggregationPeriod.DAY then "D"
else if aP == aggregationPeriod.FOUR_HOURS then "4H"
else if aP == aggregationPeriod.TWO_HOURS then "2H"
else if aP == aggregationPeriod.HOUR then "60m"
else if aP == aggregationPeriod.THIRTY_MIN then "30m"
else if aP == aggregationPeriod.TWENTY_MIN then "20m"
else if aP == aggregationPeriod.FIFTEEN_MIN then "15m"
else if aP == aggregationPeriod.TEN_MIN then "10m"
else if aP == aggregationPeriod.FIVE_MIN then "5m"
else if aP == aggregationPeriod.FOUR_MIN then "4m"
else if aP == aggregationPeriod.THREE_MIN then "3m"
else if aP == aggregationPeriod.TWO_MIN then "2m"
else if aP == aggregationPeriod.MIN then "1m"
else "",Color.GRAY);
AddLabel(yes,highrsi + " ",(CreateColor(82, 128, 233)));
AddLabel(yes,midrsi + " ",(CreateColor(254, 3, 1)));
AddLabel(yes,lowrsi + " ",(CreateColor(0, 255, 0)));
#End

Now, when you get a chance, can you test this RSI_BAND 60-40 on 15m and/or 30m frames? My interest in those frames are the 30m being th last frame that can divide the trading hours candles equally for equity, and 15 for some ETF that trades extra 15m.

Thank you again!

Last edited by a moderator:
@kd312 Try this

Ruby:
``````#RSI_BAND
#Convered by @SuryaKiranC
#Reqested by @kd312

input     length = 14;

input    seventy = 70;
def        fifty = 50;
input     thirty = 30;

def ep = 2 * length - 1;

def auc = ExpAverage(max (close - close[1],0),ep);
def adc = ExpAverage(max (close[1] - close,0),ep);

def x1 = (length - 1) * (adc * thirty / (100-thirty) - auc);
plot thirtyrsi = if(x1 >= 0, close + x1, close + x1 * (100 - thirty)/thirty);
thirtyrsi.SetDefaultColor(CreateColor(0, 255, 0));

def x7 = (length - 1) * (adc * seventy / (100-seventy) - auc);
plot seventyrsi = if(x7 >= 0, close + x7, close + x7 * (100-seventy)/seventy);
seventyrsi.SetDefaultColor(CreateColor(82, 128, 233));

def x13 = (length - 1) * (adc * fifty / (100-fifty) - auc);
plot fiftyrsi = if(x13 >= 0, close + x13, close + x13 * (100-fifty)/fifty);
fiftyrsi.SetDefaultColor(CreateColor(254, 3, 1));
#End``````
If someone wants to change the 70 to 75 let's say they don't have to change anything else right?

If someone wants to change the 70 to 75 let's say they don't have to change anything else right?
correct, you don't have to change code. You can set it in the properties.

Last edited:
Hello, Does anyone have an RSI indicator that also have a bollinger band in it for thinkorswim and is willing to share? I found the below code on Tradingview
that does come with one but I don't use Tradingview anymore. Or, If someone could convert this to Thinkorswim please, I will really appreciate it. Thanks a ton!

//
// @author Erionis
// RSI with Bollinger Bands. Dynamic Oversold/Overbought levels
study(title = "RSI with Bollinger Bands [Erionis]", shorttitle="RSI and BB [Erionis]")
source = hlc3
length = input(14, minval=1), mult = input(2.0, minval=0.001, maxval=50)
DrawRSI_f=input(false, title="Draw RSI?", type=bool)
DrawMFI_f=input(true, title="Draw MFI?", type=bool)
HighlightBreaches=input(true, title="Highlight Oversold/Overbought?", type=bool)
upLine = input(70, minval=50, maxval=90, title="Upper Line Value?")
lowLine = input(30, minval=10, maxval=50, title="Lower Line Value?")
sml = input(true, title="Show Mid Line?")
DrawMFI = (not DrawMFI_f) and (not DrawRSI_f) ? true : DrawMFI_f
DrawRSI = (DrawMFI_f and DrawRSI_f) ? false : DrawRSI_f
// RSI
rsi_s = DrawRSI ? rsi(source, length) : na
plot(DrawRSI ? rsi_s : na, color=maroon, linewidth=2)
plot(upLine, title= "Upper Line", style=solid, linewidth=3, color=red)
plot(lowLine, title= "Lower Line", style=solid, linewidth=3, color=lime)
plot(sml and 50 ? 50 : na, title="Mid Line", style=linebr, linewidth=2, color=gray)
// MFI
upper_s = DrawMFI ? sum(volume * (change(source) <= 0 ? 0 : source), length) : na
lower_s = DrawMFI ? sum(volume * (change(source) >= 0 ? 0 : source), length) : na
mf = DrawMFI ? rsi(upper_s, lower_s) : na
plot(DrawMFI ? mf : na, color=green, linewidth=2)

// Draw BB on indices
bb_s = DrawRSI ? rsi_s : DrawMFI ? mf : na
basis = sma(bb_s, length)
dev = mult * stdev(bb_s, length)
upper = basis + dev
lower = basis - dev
plot(basis, color=red)
p1 = plot(upper, color=blue)
p2 = plot(lower, color=blue)
fill(p1,p2, blue)
b_color = (bb_s > upper) ? red : (bb_s < lower) ? green : na
bgcolor(HighlightBreaches ? b_color : na)

Last edited by a moderator:

87k+ Posts
291 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?