Overall Market Sentiment Indicator for ThinkorSwim

@mashume, please accept my apologies for the sudden onslaught of dyslexia. I meant SRSI. Here is the code.

Code:
declare lower;

input len = 6; #changed from the setting of 20 per the instructions of the original author

def srsin;
def value1 = close - open;
def value2 = high - low;
def value3 = if value2 == 0 then 0
else value1 / value2;

srsin = Sum(value3, len);

plot srsi = srsin / len;
srsi.assignValueColor(if srsi > 0.05 then Color.GREEN
else if srsi<-0.05 then color.red
else color.yellow);

plot l1 = 0.38 ;
l1.SetDefaultColor(Color.DARK_RED);

plot l2 = -0.38;
l2.SetDefaultColor(Color.DARK_GREEN);

plot zline = 0;
zline.SetDefaultColor(Color.ORANGE);

Alert(SRSI crosses below 0, "", Alert.BAR, Sound.Bell);
Alert(SRSI crosses above 0, "", Alert.BAR, Sound.Bell);

#AddLabel(yes, "SRSI: " + SRSI, if SRSI > .05 then (Color.GREEN) else if SRSI < -.05 then (Color.RED) else Color.Yellow);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@mashume, please accept my apologies for the sudden onslaught of dyslexia. I meant SRSI. Here is the code.
No Problems,

Here's some code. It only seems to work on a daily chart for whatever reason... perhaps some one here can tell me why.

Code:
# AVERAGE of SRSIs FOR GROUP OF STOCKS
#
# useThinkScript
# 2020-07-24
# @mashume

script SRSI {
    input ticker = "SPY";
    input len = 6;
    def srsin;

    def value1 = close(ticker) - open(ticker);
    def value2 = high(ticker) - low(ticker);
    def value3 = if value2 == 0 then 0
                 else value1 / value2;

    srsin = Sum(value3, len);
    plot SRSI = srsin / len;
}


declare lower;

input OS = -0.2;
input OB = 0.2;

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 SRSI_1 = SRSI(ticker = ticker_1);
def SRSI_2 = SRSI(ticker = ticker_2);
def SRSI_3 = SRSI(ticker = ticker_3);
def SRSI_4 = SRSI(ticker = ticker_4);
def SRSI_5 = SRSI(ticker = ticker_5);
def SRSI_6 = SRSI(ticker = ticker_6);
def SRSI_7 = SRSI(ticker = ticker_7);


plot data = (SRSI_1 + SRSI_2 + SRSI_3 + SRSI_4 + SRSI_5 + SRSI_6 + SRSI_7) / 7;

plot zero = 0;
zero.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);

I made up the OS and OB levels. I'm not sure whether they're appropriate or not.

Trade 'em like you see 'em.

-mashume
 
@mashume Thank you again for your time and efforts. This is going to work my longer trades. Maybe someone here can work this for shorter time frames.
 
I personally use a very rudimentary indicator to estimate overall market sentiment or you can say current trend. I only trade SPX and have found the indicator originally presented here very useful by @Chemmy. I avoid trading against these sentiments at any point in time.

Here is my indicator to develop an understanding of the overall market. This is not very scientific perhaps.

Here is the code for Market Sentiment Record.
Code:
# fsk_market_sentiment  - Show over all market sentiments 
# 02-01-2023 - fskhan - Created
#   Show 4 Key ETFs/Indexes  and an aggregate of 24 key stocks, sectors and indexes to determine 
# overall market  sentiment.
# this to help determine  "SellPut" or "Sellput" signals from fsk_HighLowRangeToday should be considered.
# When label MSR (Market SentimentZoneOscillator Record) is RED and less than 50% 
# then general trend is Down, so consider "Sell Call"
# When label MSR (Market SentimentZoneOscillator Record) is GREEN and MORE than 50% 
# then General Trend is UP, so consider "Sell PUT"
# 
declare once_per_bar;
input Symbol_1 = "$VOLD";
input Symbol_2 = "$ADD";
input Symbol_3     = "UNH";
input Symbol_4     = "JPM";

input Symbol_5     = "SVXY";
input Symbol_6     = "SPY";
input Symbol_7     = "UDN";
input Symbol_8     = "TSLA";
input Symbol_9     = "INTC";
input Symbol_10    = "NVDA";
input Symbol_11    = "AAPL";
input Symbol_12    = "AMZN";
input Symbol_13    = "XLF";
input Symbol_14    = "XLE";
input Symbol_15    = "XLK";
input Symbol_16    = "XLP";
input Symbol_17    = "IYT";
input Symbol_18    = "BRK/B";
input Symbol_19    = "MSFT";
input Symbol_20    = "MGAM";
input Symbol_21    = "F";
input Symbol_22    = "SNAP";
input Symbol_23    = "AMD";
input Symbol_24    = "XOM";
input Symbol_25    = "GS";
input Symbol_26    = "META";
def ztotal = 26;

def zct_0  = 0;


script zUpDown {
    input zsymbol = "";
    input zCount = 0;
    input zinverse = double.Nan;
    def Length = 0;
    def aggr = AggregationPeriod.DAY;


    def todayopen = (open(zsymbol, period = aggr));
    def curclose = (close(zsymbol, period = aggr));


    plot rUpdown = 
                if IsNan(zinverse)  
                  then 
                    if (curclose[0]) > (todayopen[Length])  then yes else no
                  else
                  if (curclose[0]) < (todayopen[Length])  then yes else no ;
    plot rCount = if IsNan(zinverse)  
                  then 
                    if (curclose[0]) > (todayopen[Length])  then zCount + 1 else zCount + 0
                  else
                  if (curclose[0]) < (todayopen[Length])  then zCount + 1 else zCount + 0  ;
#    plot rcount = zinverse *  zrCount;


} # end zUpDown

# count of up downs
#def zct_yc = zUpDown("spy", zct_0).yc ;
#def zct_to = zUpDown("spy", zct_0).to ;

#AddLabel(yes, zct_yc    ,   Color.GREEN  );
#AddLabel(yes, zct_to    ,   Color.GREEN  );


def zct_1 = zUpDown(Symbol_1, zct_0).rCount ;
def zct_2 = zUpDown(Symbol_2, zct_1).rCount ;

#def t1 = zUpDown(Symbol_2, zct_0).topen;
#addlabel(yes, t1    ,   Color.GREEN  );
#def t2 = zUpDown(Symbol_2, zct_0).tclose;
#addlabel(yes, t2    ,   Color.GREEN  );

def zct_3  = zUpDown(Symbol_3  , zct_2 ).rCount ;
# $PCSP is reverse 
def zct_4  = zUpDown(Symbol_4  , zct_3 ).rCount ;
def zct_5  = zUpDown(Symbol_5  , zct_4 ).rCount ;
def zct_6  = zUpDown(Symbol_6  , zct_5 ).rCount ;
def zct_7  = zUpDown(Symbol_7  , zct_6 ).rCount ;
def zct_8  = zUpDown(Symbol_8  , zct_7 ).rCount ;
def zct_9  = zUpDown(Symbol_9  , zct_8 ).rCount ;
def zct_10 = zUpDown(Symbol_10 , zct_9 ).rCount ;
def zct_11 = zUpDown(Symbol_11 , zct_10).rCount ;
def zct_12 = zUpDown(Symbol_12 , zct_11).rCount ;
def zct_13 = zUpDown(Symbol_13 , zct_12).rCount ;
def zct_14 = zUpDown(Symbol_14 , zct_13).rCount ;
def zct_15 = zUpDown(Symbol_15 , zct_14).rCount ;
def zct_16 = zUpDown(Symbol_16 , zct_15).rCount ;
def zct_17 = zUpDown(Symbol_17 , zct_16).rCount ;
def zct_18 = zUpDown(Symbol_18 , zct_17).rCount ;
def zct_19 = zUpDown(Symbol_19 , zct_18).rCount ;
def zct_20 = zUpDown(Symbol_20 , zct_19).rCount ;
def zct_21 = zUpDown(Symbol_21 , zct_20).rCount ;
def zct_22 = zUpDown(Symbol_22 , zct_21).rCount ;
def zct_23 = zUpDown(Symbol_23 , zct_22).rCount ;
def zct_24 = zUpDown(Symbol_24 , zct_23).rCount ;
def zct_25 = zUpDown(Symbol_25 , zct_24).rCount ;
def zct_26 = zUpDown(Symbol_25 , zct_25).rCount ;

def zct_zct = zct_26;
#AddLabel(yes, zct_yc    ,   Color.GREEN  );
# Updown
def ste_1 = zUpDown(Symbol_1, zct_0).rUpdown ;
def ste_2 = zUpDown(Symbol_2, zct_1).rUpdown ;
def ste_3  = zUpDown(Symbol_3  , zct_2 ).rUpdown ;
def ste_4  = zUpDown(Symbol_4  , zct_3, 1 ).rUpdown ;


AddLabel(!IsNaN(zct_1 ), Symbol_1   , if ste_1 and  close(Symbol_1 , period = AggregationPeriod.DAY) > (open(Symbol_1 , period = AggregationPeriod.DAY))  then Color.GREEN else  Color.RED );
AddLabel(!IsNaN(zct_2 ), Symbol_2   , if ste_2  and  (close(Symbol_2 , period = AggregationPeriod.DAY)) > (open(Symbol_2 , period = AggregationPeriod.DAY))  then Color.GREEN else  Color.RED );
#AddLabel(!IsNaN(zct_2 ), Symbol_3   , if ste_3  and  close(Symbol_3 , period = AggregationPeriod.DAY) > (open(Symbol_3 , period = AggregationPeriod.DAY))   then Color.GREEN else  Color.RED );
#AddLabel(!IsNaN(zct_2 ), Symbol_4   , if ste_4  and  close(Symbol_4 , period = AggregationPeriod.DAY) > (open(Symbol_4 , period = AggregationPeriod.DAY))   then Color.GREEN else  Color.RED );

def zpct = Round(100 * (zct_zct / ztotal), 2)  ;
AddLabel(yes, "MSR: " + Round(100 * (zct_zct / ztotal), 2)  + "% (" + zct_zct + "/" + ztotal + ")"  , if zpct > 68  then Color.LIGHT_GREEN else  if zpct  < 60 then Color.PINK else Color.YELLOW);



#EOF
 
Last edited:
I personally use a very rudimentary indicator to estimate overall market sentiment or you can say current trend. I only trade SPX and have found the indicator originally presented here very useful by @Chemmy. I avoid trading against these sentiments at any point in time.

Here is my indicator to develop an understanding of the overall market. This is not very scientific perhaps.

Here is the code for Market Sentiment Record.
Code:
# fsk_market_sentiment  - Show over all market sentiments
# 02-01-2023 - fskhan - Created
#   Show 4 Key ETFs/Indexes  and an aggregate of 24 key stocks, sectors and indexes to determine
# overall market  sentiment.
# this to help determine  "SellPut" or "Sellput" signals from fsk_HighLowRangeToday should be considered.
# When label MSR (Market SentimentZoneOscillator Record) is RED and less than 50%
# then general trend is Down, so consider "Sell Call"
# When label MSR (Market SentimentZoneOscillator Record) is GREEN and MORE than 50%
# then General Trend is UP, so consider "Sell PUT"
#

input Symbol_1 = "$VOLD";
input Symbol_2 = "$ADD";
input Symbol_3     = "$SP500MUP";
input Symbol_4     = "$PCN";
input Symbol_5     = "SVXY";
input Symbol_6     = "SPY";
input Symbol_7     = "UDN";
input Symbol_8     = "META";
input Symbol_9     = "INTC";
input Symbol_10    = "NVDA";
input Symbol_11    = "AAPL";
input Symbol_12    = "AMZN";
input Symbol_13    = "XLF";
input Symbol_14    = "XLE";
input Symbol_15    = "XLK";
input Symbol_16    = "XLP";
input Symbol_17    = "IYT";
input Symbol_18    = "VZ";
input Symbol_19    = "TSLA";
input Symbol_20    = "MGAM";
input Symbol_21    = "F";
input Symbol_22    = "SNAP";
input Symbol_23    = "AMD";
input Symbol_24    = "XOM";

def zct_0  = 0;

script zUpDown {
    input zsymbol = "";
    input zCount = 0;

    def todayopen = open(zsymbol, period = AggregationPeriod.DAY);
    def curclose = close(zsymbol, period = AggregationPeriod.DAY);

    plot rUpdown = if curclose > todayopen then yes else no;
    plot rCount = if curclose > todayopen then zCount + 1 else zCount + 0;


} # end zUpDown


 
# count of up downs
def zct_1 = zUpDown(Symbol_1, zct_0).rCount ;
def zct_2 = zUpDown(Symbol_2, zct_1).rCount ;
def zct_3  = zUpDown(Symbol_3  , zct_2 ).rCount ;
def zct_4  = zUpDown(Symbol_4  , zct_3 ).rCount ;
def zct_5  = zUpDown(Symbol_5  , zct_4 ).rCount ;
def zct_6  = zUpDown(Symbol_6  , zct_5 ).rCount ;
def zct_7  = zUpDown(Symbol_7  , zct_6 ).rCount ;
def zct_8  = zUpDown(Symbol_8  , zct_7 ).rCount ;
def zct_9  = zUpDown(Symbol_9  , zct_8 ).rCount ;
def zct_10 = zUpDown(Symbol_10 , zct_9 ).rCount ;
def zct_11 = zUpDown(Symbol_11 , zct_10).rCount ;
def zct_12 = zUpDown(Symbol_12 , zct_11).rCount ;
def zct_13 = zUpDown(Symbol_13 , zct_12).rCount ;
def zct_14 = zUpDown(Symbol_14 , zct_13).rCount ;
def zct_15 = zUpDown(Symbol_15 , zct_14).rCount ;
def zct_16 = zUpDown(Symbol_16 , zct_15).rCount ;
def zct_17 = zUpDown(Symbol_17 , zct_16).rCount ;
def zct_18 = zUpDown(Symbol_18 , zct_17).rCount ;
def zct_19 = zUpDown(Symbol_19 , zct_18).rCount ;
def zct_20 = zUpDown(Symbol_20 , zct_19).rCount ;
def zct_21 = zUpDown(Symbol_21 , zct_20).rCount ;
def zct_22 = zUpDown(Symbol_22 , zct_21).rCount ;
def zct_23 = zUpDown(Symbol_23 , zct_22).rCount ;
def zct_24 = zUpDown(Symbol_24 , zct_23).rCount ;

# Updown
def ste_1 = zUpDown(Symbol_1, zct_0).rUpdown ;
def ste_2 = zUpDown(Symbol_2, zct_1).rUpdown ;
def ste_3  = zUpDown(Symbol_3  , zct_2 ).rUpdown ;
def ste_4  = zUpDown(Symbol_4  , zct_3 ).rUpdown ;
def ste_5  = zUpDown(Symbol_5  , zct_4 ).rUpdown ;
def ste_6  = zUpDown(Symbol_6  , zct_5 ).rUpdown ;
def ste_7  = zUpDown(Symbol_7  , zct_6 ).rUpdown ;
def ste_8  = zUpDown(Symbol_8  , zct_7 ).rUpdown ;
def ste_9  = zUpDown(Symbol_9  , zct_8 ).rUpdown ;
def ste_10 = zUpDown(Symbol_10 , zct_9 ).rUpdown ;
def ste_11 = zUpDown(Symbol_11 , zct_10).rUpdown ;
def ste_12 = zUpDown(Symbol_12 , zct_11).rUpdown ;
def ste_13 = zUpDown(Symbol_13 , zct_12).rUpdown ;
def ste_14 = zUpDown(Symbol_14 , zct_13).rUpdown ;
def ste_15 = zUpDown(Symbol_15 , zct_14).rUpdown ;
def ste_16 = zUpDown(Symbol_16 , zct_15).rUpdown ;
def ste_17 = zUpDown(Symbol_17 , zct_16).rUpdown ;
def ste_18 = zUpDown(Symbol_18 , zct_17).rUpdown ;
def ste_19 = zUpDown(Symbol_19 , zct_18).rUpdown ;
def ste_20 = zUpDown(Symbol_20 , zct_19).rUpdown ;
def ste_21 = zUpDown(Symbol_21 , zct_20).rUpdown ;
def ste_22 = zUpDown(Symbol_22 , zct_21).rUpdown ;
def ste_23 = zUpDown(Symbol_23 , zct_22).rUpdown ;
def ste_24 = zUpDown(Symbol_24 , zct_23).rUpdown ;
def ztotal = 24;
AddLabel(!IsNan(zct_1 ), Symbol_1   , if ste_1 and  close(Symbol_1 , period = AggregationPeriod.DAY) > 0  then Color.GREEN else  Color.RED );
AddLabel(!IsNan(zct_2 ), Symbol_2   , if ste_2  and  close(Symbol_2 , period = AggregationPeriod.DAY) > 0  then Color.GREEN else  Color.RED );
AddLabel(!IsNan(zct_2 ), Symbol_3   , if ste_3  and  close(Symbol_3 , period = AggregationPeriod.DAY) > 0  then Color.GREEN else  Color.RED );
AddLabel(!IsNan(zct_2 ), Symbol_4   , if ste_4  and  close(Symbol_4 , period = AggregationPeriod.DAY) > 0  then Color.GREEN else  Color.RED );

AddLabel(yes, "MSR: " + Round(100 * (zct_24 / ztotal), 2)  + "% (" + zct_24 + "/" + ztotal + ")"  , if zct_24 > 12  then Color.GREEN else  Color.RED );



#EOF
@Chemmy @samer800 @fskhan Is it possible to get histogram view of MSR by which we can see MSR values throughout the day?
 
Hello, Can someone tell me how this can be used to create conditional order like if MSR % is > 50 buy ? Currently this script shows up in study but not displaying any input value/parameters. Sorry don't know much about scripting. Any help is appreciated. Thanks.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
450 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top