# Overall Market Sentiment Lower Indicator for ThinkorSwim

##### Member
VIP
VIP Enthusiast
Simple to understand, when above 1 Overall Market is Bullish, below 1 Overall Market is Bearish

Code:
``````declare lower;
#Examples:"SPX", "COMP", "DJX", "SOX", "NDX", "OEX", "QQQ", "IWM", "TNX", "/ES", "/CL"

#plot FB = close("FB")/close("FB")[1];
def SPX = close("SPX") / close("SPX")[1];
def COMP = close("COMP") / close("COMP")[1];
def DJX = close("DJX") / close("DJX")[1];
def SOX = close("SOX") / close("SOX")[1];
def NDX = close("NDX") / close("NDX")[1];
def OEX = close("OEX") / close("OEX")[1];
def QQQ = close("QQQ") / close("QQQ")[1];

plot data = (SPX+COMP+DJX+SOX+NDX+OEX+QQQ)/7;``````

Last edited:

#### Rojo Grande

##### Active member
VIP
Anyway to adapt this for RSI?

#### mashume

##### Well-known member
VIP
Taking a swing...

Code:
``````# MARKET INDEX MOOD RSI
# From an Request by
# @ Rojo Grande
# and an idea from
#
# Coded by Mashume
# 2020-02-25 V01
#
declare lower;

input sold = 40;
input bought = 60;

def SPX = close("SPX") / close("SPX")[1];
def COMP = close("COMP") / close("COMP")[1];
def DJX = close("DJX") / close("DJX")[1];
def SOX = close("SOX") / close("SOX")[1];
def NDX = close("NDX") / close("NDX")[1];
def OEX = close("OEX") / close("OEX")[1];
def QQQ = close("QQQ") / close("QQQ")[1];

def data = (SPX+COMP+DJX+SOX+NDX+OEX+QQQ)/7;

plot noncommittal = 50;
noncommittal.setDefaultColor(color.gray);

plot rsi = rsi(price = data);
rsi.SetDefaultColor(Color.CYAN);
rsi.SetLineWeight(2);

plot morbid = sold;
morbid.SetDefaultColor(color.red);

plot exuberant = bought;
exuberant.SetDefaultColor(color.green);``````

Interesting ideas

-mashume

##### Member
Nice! This actually provides a good framework to creating very niche composites.

#### Rojo Grande

##### Active member
VIP
Thank you mashume, this is a good start. I did not word my question very well at all. I'm looking to graph the RSI average of stocks I watch. I subbed the ones I watch into the script you did above. I need to be able to change the length "7" and the average type "Wilders". Is this doable? I can only add alerts and arrows to things, not good at all with the rest. Thank you for your help.

#### horserider

##### Well-known member
VIP
Possibly add this for each symbol.Only need to set input one time.

input length = 7;

def price = spx;
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 rsispx = 50 * (ChgRatio + 1);

rsispx.SetDefaultColor(Color.CYAN);
rsispx.SetLineWeight(1);

#### mashume

##### Well-known member
VIP
Is this more what you had in mind?

Code:
``````# AVERAGE of RSIs FOR GROUP OF STOCKS
#
# useThinkScript
# 2020-02-26
# @mashume

declare lower;

input RSI_TYPE = {default WILDERS, SIMPLE, EXPONENTIAL};
input RSI_LENGTH = 14;

input OS = 40;
input OB = 60;

input ticker_1 = "SBUX";
input ticker_2 = "MSFT";
input ticker_3 = "AMZN";
input ticker_4 = "COST";
input ticker_5 = "FFIV";
input ticker_6 = "DAIO";
input ticker_7 = "MRNA";

def RSI_1 = RSI(price = close(ticker_1), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_2 = RSI(price = close(ticker_2), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_3 = RSI(price = close(ticker_3), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_4 = RSI(price = close(ticker_4), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_5 = RSI(price = close(ticker_5), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_6 = RSI(price = close(ticker_6), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_7 = RSI(price = close(ticker_7), "average type" = RSI_TYPE, length = RSI_LENGTH);

plot data = (RSI_1 + RSI_2 + RSI_3 + RSI_4 + RSI_5 + RSI_6 + RSI_7) / 7;

plot midline = 50;
midline.SetDefaultColor(Color.GRAY);

# plot rsi = rsi(price = data);
data.SetDefaultColor(Color.CYAN);
data.SetLineWeight(2);

plot oversold = OS;
oversold.SetDefaultColor(Color.RED);

plot overbought = OB;
overbought.SetDefaultColor(Color.GREEN);``````

You can copy and paste additional RSI_x lines, just be sure to have an input line for the ticker too.

Hope this is inline with what you were looking for.

mashume

#### Rojo Grande

##### Active member
VIP
Thank you Mashume, that is exactly what I was thinking of. Horserider, I thank you too for your time and effort. I've said it before, a GREAT site!!!!

#### mashume

##### Well-known member
VIP
BTW, this worked well on a daily chart, when I was writing it, but I see it shows gaps on an intrday chart. There's no code to handle errors or missing values.
YMMV

#### horserider

##### Well-known member
VIP
Ahh sorry thought you wanted to plot a comparison of the symbol plots. Looks like you wanted an average.

#### Rojo Grande

##### Active member
VIP
No apologies needed horserider. I have a hard time with expressing what it is i'm looking for, and besides you've helped me more than I can express. Mashume, just starting to find it's limitations and potential. Probably take a week at least to find where, and what it works best, but it's a good start for sure.

#### spm009

##### Member
Can anyone post up a screen shot?

#### mashume

##### Well-known member
VIP

Upper Lower is the original indicator posted near the top that is a single RSI of averaged index values,

Lower Lower is the averaged RSIs of the tickers listed.

Overbought/Oversold lines are simply what looked good to my eye.

-mashume

Last edited:

##### Member
VIP
VIP Enthusiast
This post alone has shown me the value of posting my indicator research here. You guy illuminated possibilities on this indicator I hadn't considered before. Thank you everyone that participated in this thread. Future ideas I now have with this indicator include doing volume analysis of entire industries as well as finding the champions of an industry by comparing these averages. Many more thoughts come to mind but anyway I am grateful and if I feel I have anything else unique to add to this I'll continue to add comments below. Thank you members for showing a newcomer to this site the cooperative research that goes on here

##### Member
VIP
VIP Enthusiast
Alright I want to say that I thought the multiple rsi post by horserider was brilliant so I went ahead and created it with 7 different stocks. Its a little more difficult since tos will not let me create functions so there is a lot of redundancy but it is still pretty neat. Here is the screenshot of what 7 stocks rsi look like followed by the code.

*Im not sure how to insert the labels stating which rsi line goes to what security, maybe one of you gurus could help?
Code:
``````# Multiple RSI Security Comparison
#
# Inspired by horserider
# 2020-02-27
#

declare lower;

input averageType = AverageType.WILDERS;
input length = 7;

input t1 = "EBAY"; #hint BLUE
input t2 = "WMT";  #hint CYAN
input t3 = "AMZN"; #hint LIGHT_GRAY
input t4 = "COST"; #hint DARK_ORANGE
input t5 = "BABA"; #hint PINK
input t6 = "BBY";  #hint VIOLET
input t7 = "TGT";  #hint YELLOW

def t1_vol = volume(t1);
def t2_vol = volume(t2);
def t3_vol = volume(t3);
def t4_vol = volume(t4);
def t5_vol = volume(t5);
def t6_vol = volume(t6);
def t7_vol = volume(t7);

def t1_o = open(t1);
def t2_o = open(t2);
def t3_o = open(t3);
def t4_o = open(t4);
def t5_o = open(t5);
def t6_o = open(t6);
def t7_o = open(t7);

def t1_h = high(t1);
def t2_h = high(t2);
def t3_h = high(t3);
def t4_h = high(t4);
def t5_h = high(t5);
def t6_h = high(t6);
def t7_h = high(t7);

def t1_l = low(t1);
def t2_l = low(t2);
def t3_l = low(t3);
def t4_l = low(t4);
def t5_l = low(t5);
def t6_l = low(t6);
def t7_l = low(t7);

def t1_c = close(t1);
def t2_c = close(t2);
def t3_c = close(t3);
def t4_c = close(t4);
def t5_c = close(t5);
def t6_c = close(t6);
def t7_c = close(t7);

#RSI Wrapper
def t1_NetChgAvg = MovingAverage(averageType, t1_c - t1_c[1], length);
def t1_TotChgAvg = MovingAverage(averageType, AbsValue(t1_c - t1_c[1]), length);
def t1_ChgRatio = if t1_TotChgAvg != 0 then t1_NetChgAvg / t1_TotChgAvg else 0;

def t2_NetChgAvg = MovingAverage(averageType, t2_c - t2_c[1], length);
def t2_TotChgAvg = MovingAverage(averageType, AbsValue(t2_c - t2_c[1]), length);
def t2_ChgRatio = if t2_TotChgAvg != 0 then t2_NetChgAvg / t2_TotChgAvg else 0;

def t3_NetChgAvg = MovingAverage(averageType, t3_c - t3_c[1], length);
def t3_TotChgAvg = MovingAverage(averageType, AbsValue(t3_c - t3_c[1]), length);
def t3_ChgRatio = if t3_TotChgAvg != 0 then t3_NetChgAvg / t3_TotChgAvg else 0;

def t4_NetChgAvg = MovingAverage(averageType, t4_c - t4_c[1], length);
def t4_TotChgAvg = MovingAverage(averageType, AbsValue(t4_c - t4_c[1]), length);
def t4_ChgRatio = if t4_TotChgAvg != 0 then t4_NetChgAvg / t4_TotChgAvg else 0;

def t5_NetChgAvg = MovingAverage(averageType, t5_c - t5_c[1], length);
def t5_TotChgAvg = MovingAverage(averageType, AbsValue(t5_c - t5_c[1]), length);
def t5_ChgRatio = if t5_TotChgAvg != 0 then t5_NetChgAvg / t5_TotChgAvg else 0;

def t6_NetChgAvg = MovingAverage(averageType, t6_c - t6_c[1], length);
def t6_TotChgAvg = MovingAverage(averageType, AbsValue(t6_c - t6_c[1]), length);
def t6_ChgRatio = if t6_TotChgAvg != 0 then t6_NetChgAvg / t6_TotChgAvg else 0;

def t7_NetChgAvg = MovingAverage(averageType, t7_c - t7_c[1], length);
def t7_TotChgAvg = MovingAverage(averageType, AbsValue(t7_c - t7_c[1]), length);
def t7_ChgRatio = if t7_TotChgAvg != 0 then t7_NetChgAvg / t7_TotChgAvg else 0;

plot t1_rsi = 50*(t1_ChgRatio+1);
plot t2_rsi = 50*(t2_ChgRatio+1);
plot t3_rsi = 50*(t3_ChgRatio+1);
plot t4_rsi = 50*(t4_ChgRatio+1);
plot t5_rsi = 50*(t5_ChgRatio+1);
plot t6_rsi = 50*(t6_ChgRatio+1);
plot t7_rsi = 50*(t7_ChgRatio+1);

t1_rsi.SetDefaultColor(Color.BLUE);
t2_rsi.SetDefaultColor(Color.CYAN);
t3_rsi.SetDefaultColor(Color.LIGHT_GRAY);
t4_rsi.SetDefaultColor(Color.DARK_ORANGE);
t5_rsi.SetDefaultColor(Color.PINK);
t6_rsi.SetDefaultColor(Color.VIOLET);
t7_rsi.SetDefaultColor(Color.YELLOW);``````

##### Member
That is super great work justAnotherTrader!
When the first code posted, I tried to adapt it to various
Pharma stocks with little success.
Glad you have the knowledge to do the code shows multiples

#### Rojo Grande

##### Active member
VIP
Hello @mashume,

Can this be adapted to do the same thing except for SRSI? Thank you.

##### Active member
2019 Donor
@mashume Very nice anyway to get this to work on intra day bars ?

#### Rojo Grande

##### Active member
VIP
Is this more what you had in mind?

Code:
``````# AVERAGE of RSIs FOR GROUP OF STOCKS
#
# useThinkScript
# 2020-02-26
# @mashume

declare lower;

input RSI_TYPE = {default WILDERS, SIMPLE, EXPONENTIAL};
input RSI_LENGTH = 14;

input OS = 40;
input OB = 60;

input ticker_1 = "SBUX";
input ticker_2 = "MSFT";
input ticker_3 = "AMZN";
input ticker_4 = "COST";
input ticker_5 = "FFIV";
input ticker_6 = "DAIO";
input ticker_7 = "MRNA";

def RSI_1 = RSI(price = close(ticker_1), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_2 = RSI(price = close(ticker_2), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_3 = RSI(price = close(ticker_3), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_4 = RSI(price = close(ticker_4), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_5 = RSI(price = close(ticker_5), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_6 = RSI(price = close(ticker_6), "average type" = RSI_TYPE, length = RSI_LENGTH);
def RSI_7 = RSI(price = close(ticker_7), "average type" = RSI_TYPE, length = RSI_LENGTH);

plot data = (RSI_1 + RSI_2 + RSI_3 + RSI_4 + RSI_5 + RSI_6 + RSI_7) / 7;

plot midline = 50;
midline.SetDefaultColor(Color.GRAY);

# plot rsi = rsi(price = data);
data.SetDefaultColor(Color.CYAN);
data.SetLineWeight(2);

plot oversold = OS;
oversold.SetDefaultColor(Color.RED);

plot overbought = OB;
overbought.SetDefaultColor(Color.GREEN);``````

You can copy and paste additional RSI_x lines, just be sure to have an input line for the ticker too.

Hope this is inline with what you were looking for.

mashume
Hello mashume,
Can this be adapted for the RSRI indicator?

#### mashume

##### Well-known member
VIP
Hello mashume,
Can this be adapted for the RSRI indicator?
If I knew what the RSRI indicator was, perhaps. Do you have some code?

-mashume

## 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?