Market Breath Labels for ThinkorSwim

Here is a binary version that plots triangles along with the labels
Code:
# Market Breath Ratios
# Paris (based on an earlier idea from ESP) = 3;
# 11.02.2015
# One Note Download
Declare Lower;
input Dotsize = 3;
def UVOL   = close(“$UVOL”);
def DVOL   = close(“$DVOL”);

def UVOLD  = close(“$UVOLI”);
def DVOLD  = close(“$DVOLI”);

def UVOLS  = close(“$UVOLSP”);
def DVOLS  = close(“$DVOLSP”);

def UVOLN  = close(“$UVOL/Q”);
def DVOLN  = close(“$DVOL/Q”);

def UVOLR  = close(“$UVOLRL”);
def DVOLR  = close(“$DVOLRL”);

def SPYRatio =  if (UVOLS >= DVOLS) then (UVOLS / DVOLS) else -(DVOLS / UVOLS);
AddLabel(yes, "S&P500: " + Concat(Round(SPYRatio, 2), ” :1”), if SPYRatio >= 0 then Color.UPTICK else Color.DOWNTICK);

def DJIRatio =  if (UVOLD >= DVOLD) then (UVOLD / DVOLD) else -(DVOLD / UVOLD);
AddLabel(yes, "DJI: " + Concat(Round(DJIRatio, 2), ” :1”), if DJIRatio >= 0 then Color.UPTICK else Color.DOWNTICK);

def NDXRatio =  if (UVOLN >= DVOLN) then (UVOLN / DVOLN) else -(DVOLN / UVOLN);
AddLabel(yes, "QQQ: " + Concat(Round(NDXRatio, 2), ” :1”), if NDXRatio >= 0 then Color.UPTICK else Color.DOWNTICK);

def RUTRatio =  if (UVOLR >= DVOLR) then (UVOLR / DVOLR) else -(DVOLR / UVOLR);
AddLabel(yes, "R2000: " + Concat(Round(RUTRatio, 2), ” :1”), if RUTRatio >= 0 then Color.UPTICK else Color.DOWNTICK);

def NYSERatio =  if (UVOL >= DVOL) then (UVOL / DVOL) else -(DVOL / UVOL);
AddLabel(yes, "NYSE: " + Concat(Round(NYSERatio, 2), ” :1”), if NYSERatio >= 0 then Color.UPTICK else Color.DOWNTICK);

plot R1_Dot = if IsNaN(close) then Double.NaN else 1;
R1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R1_Dot.SetLineWeight(DotSize);
R1_Dot.AssignValueColor(if SPYRatio < 0  then Color.DownTICK else Color.UpTICK);
R1_Dot.HideBubble();
plot R2_Dot = if IsNaN(close) then Double.NaN else 2;
R2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R2_Dot.SetLineWeight(DotSize);
R2_Dot.AssignValueColor(if DJIRatio < 0 then Color.DownTICK else Color.UpTICK);
R2_Dot.HideBubble();
plot R3_Dot = if IsNaN(close) then Double.NaN else 3;
R3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R3_Dot.SetLineWeight(DotSize);
R3_Dot.AssignValueColor(if NDXRatio < 0 then Color.DownTICK else Color.UpTICK);
R3_Dot.HideBubble();
plot R4_Dot = if IsNaN(close) then Double.NaN else 4;
R4_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R4_Dot.SetLineWeight(DotSize);
R4_Dot.AssignValueColor(if RutRatio < 0 then Color.DownTICK else Color.UpTICK);
R4_Dot.HideBubble();
plot R5_Dot = if IsNaN(close) then Double.NaN else 5;
R5_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
R5_Dot.SetLineWeight(DotSize);
R5_Dot.AssignValueColor(if NYSERatio < 0 then Color.DownTICK else Color.UpTICK);
R5_Dot.HideBubble();
 

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

SPX Market Breadth Indicator
This is my first attempt at thinkscript, and I also wanted to share back with the community. Please give me feedback if this is not the right way to share.

Indicator Image

This indicator shows the number of stocks that are above 50-day, 100-day, and 200-day moving averages. It is one of my favorite ways to get a sense of market health.

Code:
# Market Breath Indicator to Display $SPXA50R, $SPXA100R, and $SPXA200R
# Author: bulusufinances
# Version: 1


declare lower;

# The values come as 0.X format - multiplying by 100 to make the graph more readable

plot SPXA50R = close("$SPXA50R")*100;
plot SPXA100R = close("$SPXA100R")*100;
plot SPXA200R = close("$SPXA200R")*100;

# Set the plot colors and line styles
SPXA50R.SetDefaultColor(Color.GREEN);
SPXA100R.SetDefaultColor(Color.RED);
SPXA200R.SetDefaultColor(Color.BLUE);

# Optional: Set line styles
SPXA50R.SetStyle(Curve.FIRM);
SPXA100R.SetStyle(Curve.FIRM);
SPXA200R.SetStyle(Curve.FIRM);

# Optional: Add labels to the plots
AddLabel(yes, "$SPXA50R", Color.GREEN);
AddLabel(yes, "$SPXA100R", Color.RED);
AddLabel(yes, "$SPXA200R", Color.BLUE);

# Add horizontal lines
plot line30 = 30;
line30.SetDefaultColor(Color.RED);
line30.SetLineWeight(2);

plot line60 = 70;
line60.SetDefaultColor(Color.GREEN);
line60.SetLineWeight(2);
Thank you this is really good and works great for 1Day charts...can this code be changed or used for smaller time frames 5min, 15min or 30min?
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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