Whaley Breadth Thrust For ThinkOrSwim

Chrys

New member
Plus
The author states: The Whaley Breadth Thrust Indicator (WBT) is a momentum-based technical indicator designed to identify the strength of market trends. It measures the market's breadth by comparing advancing stocks to declining stocks, providing insights into whether a market is in a bullish, neutral, or bearish state. This script calculates the indicator based on the advancing and declining U.S. stocks; however, it can be expanded to other markets as well.

Thresholds:
0.30: Indicates a strongly bearish market.
0.40: A bearish threshold; crossing below suggests bearish momentum.
0.60: A bullish threshold; crossing above suggests bullish momentum.
0.70: Indicates a strongly bullish market.

8sO2Sa1.png



Here is the original Tradingview code:
https://www.tradingview.com/script/Ino0OEgK-Whaley-Breadth-Thrust-Indicator/

For the new ThinkOrSwim code, you must scroll down to the next post
 
Last edited by a moderator:

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

check the below:

CSS:
#// Indicator for TOS
#//Published by @Mysterysauce
#indicator("Whaley Breadth Thrust Indicator", overlay=false)
# Converted by Sam4Cok@Samer800    - 01/2025
declare lower;

input timeframe = AggregationPeriod.MIN; #('D', 'Timeframe')
input smoothingType = AverageType.SIMPLE;
input smoothingLength = 5; #, "Period for WBT")  // Period is set to 5 days as per the article
input adv = "$ADVA"; # "Symbol for Advances"
input dec = "$DECA"; # "Symbol for Declines"
input SignificantHighThreshold = 0.6366;
input SignificantLowThreshold = 0.2905;

def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);
#// Inputs for advancing and declining stocks
def advances = close(adv, Period = tf);
def declines = close(dec, Period = tf);

#// Breadth Thrust Ratio (BTR) Calculation
def btr = advances / (advances + declines + 0.001); #  // ADT = Advances / (Advances + Declines)

#// Calculate the simple moving average of BTR over the specified period
def wbt = MovingAverage(smoothingType, btr, smoothingLength);

#// Plot WBT
plot wbtI = if !last then wbt else na; # "WBT"
wbtI.SetLineWeight(2);
wbtI.SetDefaultColor(Color.CYAN);

#// Significant Thresholds based on the article
plot h_19_05 = if last then na else SignificantLowThreshold;  # "Significant Low Threshold"
plot h_73_66 = if last then na else SignificantHighThreshold; # "Significant High Threshold"
plot hline50 = if last then na else 0.50; #, "Mid Line", color=color.aqua
h_19_05.SetDefaultColor(Color.GREEN);
h_73_66.SetDefaultColor(Color.RED);
hline50.SetStyle(Curve.SHORT_DASH);
hline50.SetDefaultColor(Color.GRAY);
h_19_05.SetPaintingStrategy(PaintingStrategy.DASHES);
h_73_66.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Horizontal lines and fills
def hline30 = if last then na else 0.30; # "Min Threshold"
def hline40 = if last then na else 0.40; # "Lower Threshold"
def hline60 = if last then na else 0.60; # "Upper Threshold"
def hline70 = if last then na else 0.70; # "Max Threshold"

AddCloud(hline70, hline60, Color.PLUM, Color.PLUM, yes);
AddCloud(hline40, hline30, Color.PLUM, Color.PLUM, yes);

#-- background

#// Highlighting significant ADT readings
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def os = wbt > SignificantHighThreshold;
def ob =  wbt < SignificantLowThreshold;

AddCloud(if (os or os[-1]) then pos else na, neg, Color.DARK_RED);
AddCloud(if (ob or ob[-1]) then pos else na, neg, Color.DARK_GREEN);


#-- END of CODE
 
@Chrys : I was working on the conversion when @samer800 posted his...

I just happen to notice that his version has the exchange hard-coded to the AMEX...It may be preferable to look at the Breadth Thrust for the exchange that your stock trades on...As a result, I've taken the liberty of updating adding the script with the Exchange option for your review...

Code:
#// Indicator for TOS
#//Published by @Mysterysauce
#indicator("Whaley Breadth Thrust Indicator", overlay=false)
# Converted by Sam4Cok@Samer800 - 01/2025
declare lower;

input timeframe = AggregationPeriod.MIN; #('D', 'Timeframe')
input smoothingType = AverageType.SIMPLE;
input smoothingLength = 5; #, "Period for WBT")  // Period is set to 5 days as per the article
#input adv = "$ADVA"; # "Symbol for Advances"
#input dec = "$DECA"; # "Symbol for Declines"
input SignificantHighThreshold = 0.6366;
input SignificantLowThreshold = 0.2905;
input exchange = {NYSE, NASDAQ, default AMEX};

def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);

#// Inputs for advancing and declining stocks
def advances;
def declines;
switch (exchange) {
case NYSE:
    advances = close("$ADVN", Period = tf);
    declines = close("$DECN", Period = tf);
case NASDAQ:
    advances = close("$ADVN/Q", Period = tf);
    declines = close("$DECN/Q", Period = tf);
case AMEX:
    advances = close("$ADVA", Period = tf);
    declines = close("$DECA", Period = tf);
}

#// Breadth Thrust Ratio (BTR) Calculation
def btr = advances / (advances + declines + 0.001); #  // ADT = Advances / (Advances + Declines)

#// Calculate the simple moving average of BTR over the specified period
def wbt = MovingAverage(smoothingType, btr, smoothingLength);

#// Plot WBT
plot wbtI = if !last then wbt else na; # "WBT"
wbtI.SetLineWeight(2);
wbtI.SetDefaultColor(Color.CYAN);

#// Significant Thresholds based on the article
plot h_19_05 = if last then na else SignificantLowThreshold;  # "Significant Low Threshold"
plot h_73_66 = if last then na else SignificantHighThreshold; # "Significant High Threshold"
plot hline50 = if last then na else 0.50; #, "Mid Line", color=color.aqua
h_19_05.SetDefaultColor(Color.GREEN);
h_73_66.SetDefaultColor(Color.RED);
hline50.SetStyle(Curve.SHORT_DASH);
hline50.SetDefaultColor(Color.GRAY);
h_19_05.SetPaintingStrategy(PaintingStrategy.DASHES);
h_73_66.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Horizontal lines and fills
def hline30 = if last then na else 0.30; # "Min Threshold"
def hline40 = if last then na else 0.40; # "Lower Threshold"
def hline60 = if last then na else 0.60; # "Upper Threshold"
def hline70 = if last then na else 0.70; # "Max Threshold"

AddCloud(hline70, hline60, Color.PLUM, Color.PLUM, yes);
AddCloud(hline40, hline30, Color.PLUM, Color.PLUM, yes);

#-- background

#// Highlighting significant ADT readings
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def os = wbt > SignificantHighThreshold;
def ob =  wbt < SignificantLowThreshold;

AddCloud(if (os or os[-1]) then pos else na, neg, Color.DARK_RED);
AddCloud(if (ob or ob[-1]) then pos else na, neg, Color.DARK_GREEN);


#-- END of CODE

#Source 1: https://www.tradingview.com/script/Ino0OEgK-Whaley-Breadth-Thrust-Indicator/
#Source 2: https://www.tradingview.com/pine/?id=PUB;754411c6279947fcb701b266d6ee65fa
#Source 3: https://lindaraschke.net/wp-content/uploads/Whaley-Breadth-THrust.pdf

Hope this helps...

Good Luck and Good Trading :cool:
 
@Chrys : I was working on the conversion when @samer800 posted his...

I just happen to notice that his version has the exchange hard-coded to the AMEX...It may be preferable to look at the Breadth Thrust for the exchange that your stock trades on...As a result, I've taken the liberty of updating adding the script with the Exchange option for your review...

Code:
#// Indicator for TOS
#//Published by @Mysterysauce
#indicator("Whaley Breadth Thrust Indicator", overlay=false)
# Converted by Sam4Cok@Samer800 - 01/2025
declare lower;

input timeframe = AggregationPeriod.MIN; #('D', 'Timeframe')
input smoothingType = AverageType.SIMPLE;
input smoothingLength = 5; #, "Period for WBT")  // Period is set to 5 days as per the article
#input adv = "$ADVA"; # "Symbol for Advances"
#input dec = "$DECA"; # "Symbol for Declines"
input SignificantHighThreshold = 0.6366;
input SignificantLowThreshold = 0.2905;
input exchange = {NYSE, NASDAQ, default AMEX};

def na = Double.NaN;
def last = IsNaN(close);
def cap = GetAggregationPeriod();
def tf = Max(cap, timeframe);

#// Inputs for advancing and declining stocks
def advances;
def declines;
switch (exchange) {
case NYSE:
    advances = close("$ADVN", Period = tf);
    declines = close("$DECN", Period = tf);
case NASDAQ:
    advances = close("$ADVN/Q", Period = tf);
    declines = close("$DECN/Q", Period = tf);
case AMEX:
    advances = close("$ADVA", Period = tf);
    declines = close("$DECA", Period = tf);
}

#// Breadth Thrust Ratio (BTR) Calculation
def btr = advances / (advances + declines + 0.001); #  // ADT = Advances / (Advances + Declines)

#// Calculate the simple moving average of BTR over the specified period
def wbt = MovingAverage(smoothingType, btr, smoothingLength);

#// Plot WBT
plot wbtI = if !last then wbt else na; # "WBT"
wbtI.SetLineWeight(2);
wbtI.SetDefaultColor(Color.CYAN);

#// Significant Thresholds based on the article
plot h_19_05 = if last then na else SignificantLowThreshold;  # "Significant Low Threshold"
plot h_73_66 = if last then na else SignificantHighThreshold; # "Significant High Threshold"
plot hline50 = if last then na else 0.50; #, "Mid Line", color=color.aqua
h_19_05.SetDefaultColor(Color.GREEN);
h_73_66.SetDefaultColor(Color.RED);
hline50.SetStyle(Curve.SHORT_DASH);
hline50.SetDefaultColor(Color.GRAY);
h_19_05.SetPaintingStrategy(PaintingStrategy.DASHES);
h_73_66.SetPaintingStrategy(PaintingStrategy.DASHES);

#// Horizontal lines and fills
def hline30 = if last then na else 0.30; # "Min Threshold"
def hline40 = if last then na else 0.40; # "Lower Threshold"
def hline60 = if last then na else 0.60; # "Upper Threshold"
def hline70 = if last then na else 0.70; # "Max Threshold"

AddCloud(hline70, hline60, Color.PLUM, Color.PLUM, yes);
AddCloud(hline40, hline30, Color.PLUM, Color.PLUM, yes);

#-- background

#// Highlighting significant ADT readings
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def os = wbt > SignificantHighThreshold;
def ob =  wbt < SignificantLowThreshold;

AddCloud(if (os or os[-1]) then pos else na, neg, Color.DARK_RED);
AddCloud(if (ob or ob[-1]) then pos else na, neg, Color.DARK_GREEN);


#-- END of CODE

#Source 1: https://www.tradingview.com/script/Ino0OEgK-Whaley-Breadth-Thrust-Indicator/
#Source 2: https://www.tradingview.com/pine/?id=PUB;754411c6279947fcb701b266d6ee65fa
#Source 3: https://lindaraschke.net/wp-content/uploads/Whaley-Breadth-THrust.pdf

Hope this helps...

Good Luck and Good Trading :cool:
Ah, now it looks like the values that Walter Deemer came up with using NYSE. Deemer references Whaley's threshold as 73.67%.

https://x.com/WalterDeemer/status/1881817348698775556

Thanks for adding the exchange option.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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