Madrid Bull Bear Sentiment For ThinkOrSwim

ApeX Predator

Well-known member
Madrid Bull Bear Sentiment provides the overall bull bear sentiment. It will be nice to have ThinkorSwim version. Thank you very much for your help.

Here is the link of the indicator with Pinescript.
@petergluis Try this and let me know.

#Madrid Bull Bear Sentiment
#Coverted by @SuryaKiranC
#Requested by @petergluis
#Requested at
#Original Source

declare lower;
declare real_size;
input src = close;
input len = 18;

def OB = 76.4;
def OS = 23.6;

input smooth = yes;
input lowerBand = 5;

script nz {
    input data = 0;
    def ret_val = if isNaN(data) then 0 else data;
    plot return = ret_val;

script ssFilter {
    input price = close;
    input lowerBand = 5;
    def PI= 3.14159265358979;

    def angle = sqrt(2) *PI/lowerBand;
    def a1= exp(-angle);
    def b1 = 2*a1*cos(angle);
    def c2 = b1;
    def c3 = -a1*a1;
    def c1 = 1 - c2 -c3;
    def filt = c1*(price + nz(price[1]))/2 + c2*nz(filt[1]) + c3*nz(filt[2]);
    plot c = filt;

script sentiment {
    input lowerBand = 5;
    input len = 18;
    input src = close;
    def lowest = lowest(src,len);
    def highest = highest(src,len);
    def diffBull = (src-lowest)*100/lowest;
    def diffBear = (highest-src)*100/highest;
    def bbs = diffBull*100/(diffBear + diffBull);

plot bbSentiment = ssFilter(bbs,lowerBand = lowerBand);

plot sentiment = sentiment(len = len);

plot OverBought = OB ;
plot mid = 50;
plot OverSold = OS;
AddCloud(sentiment,lowestall(sentiment), Color.GREEN);
AddCloud(highestall(sentiment),sentiment, Color.RED);

Add the below code at the end of the main study script. For scan set a custom study filter, with MadridBulBearSentiment()."Bear" or MadridBulBearSentiment()."Bull" as a string.

def Bull = if sentiment > OverSold and sentiment > sentiment[1] then 1 else Double.NaN;
def Bear = if sentiment < OverBought and sentiment < sentiment[1] then -1 else Double.NaN;

plot scan = (Bull or Bear);

If you want audible alerts, add the following too.

input audibleAlerts = yes;

Alert(audibleAlerts and Bull, "Sentiment Bullish", Alert.BAR, Sound.Ding);
Alert(audibleAlerts and Bear, "Sentiment Bearish", Alert.BAR, Sound.Ring);
Last edited:


Well-known member
It is very nice. Thank you very much for this wonderful job. I would like to know whether you can have a scan feature based on this indicator.
How, out of curiosity, are you using this... primary signals, confirmation, it looks interesting but there isn't much around on how it's being used. Any thoughts you'd want to share with us all?



Active member
I often use it to find when a stock or an ETF to reach short-term bottoms or tops. I modified this indicator by adding more signal lines so that we detect whether the uptrend can continue. I will learn how to insert images to this reply later as I tried a couple of times and failed by using inserting icon above.

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
256 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.