Keep track of Bonds In ThinkOrSwim

johns52

New member
Lots of talk about bonds lately. Sell-off in bonds has made the interest rates rise. Surges in Bonds make SPX rise. SPX and Bonds seem to be highly correlated these days. This is a lower study. Hope this is useful to someone.

I have attached a day chart for /ES and a 15 minute chart for SPX. Note the moving average lag problem doesn't show up with SPX - don't know why. Note, with the 15 minute SPX chart that a rise in bonds can push up SPX and a drop in bonds can presage a big daily drop in SPX. Bonds are not the only force guiding the market but are an important consideration.

Code:
#JS_TLT_Comparison
#plots the TLT with three averages
#be sure to set it up on the Left Axis if overlaying price

declare lower;

input Period1 = 21;
input Period2 = 55;
input Period3 = 233;

plot tlt = Close("TLT");

tlt.SetPaintingStrategy(paintingStrategy.Line);
tlt.SetLineWeight(1);
tlt.SetDefaultColor(Color.white);

plot TltAvg1 = Average(tlt, Period1);

TltAvg1.SetPaintingStrategy(paintingStrategy.Line);
TltAvg1.SetLineWeight(2);
TltAvg1.SetDefaultColor(Color.magenta);

plot TltAvg2 = Average(tlt, Period2);

TltAvg2.SetPaintingStrategy(paintingStrategy.Line);
TltAvg2.SetLineWeight(2);
TltAvg2.SetDefaultColor(Color.cyan);

plot TltAvg3 = Average(tlt, Period3);

TltAvg3.SetPaintingStrategy(paintingStrategy.Line);
TltAvg3.SetLineWeight(2);
TltAvg3.SetDefaultColor(Color.magenta);

def rising = tlt > TltAvg1 and TltAvg1 > TltAvg2 and TltAvg2 > TltAvg3;

def falling = tlt < TltAvg1 and TltAvg1 < TltAvg2 and TltAvg2 < TltAvg3;

AddLabel(yes, "TLT Trend", if rising then color.light_green else if falling then color.light_red else color.yellow);
 

Attachments

  • SPX with TLT indicator.PNG
    SPX with TLT indicator.PNG
    310.5 KB · Views: 330
  • ES with TLT indicator.PNG
    ES with TLT indicator.PNG
    268.6 KB · Views: 260
Last edited:
@johns52 : Thanks for sharing the Bonds Tracker...Given the current volatility in the Markets, this is a timely addition to uTS, especially since there are few studies available related specifically to Bonds...

As a result of incorporating the study into my workspace I noticed the Average Lines are breaking up for some unknown reason...I've attached a screenshot to give you an idea of what I'm looking at...

Please advise...
 

Attachments

  • 202310251551_test_.jpg
    202310251551_test_.jpg
    80.2 KB · Views: 222
@johns52 : Thanks for sharing the Bonds Tracker...Given the current volatility in the Markets, this is a timely addition to uTS, especially since there are few studies available related specifically to Bonds...

As a result of incorporating the study into my workspace I noticed the Average Lines are breaking up for some unknown reason...I've attached a screenshot to give you an idea of what I'm looking at...

Please advise...
I speculate that this happens because TLT is not trading 24 hours a day. TLT restarts each day, then the shorter period moving average gets picked up first, followed by the slower moving averages. /ZN could be substituted for TLT since it trades 5/23 but I don't think it correlates as well as TLT. Your thoughts?
 
I speculate that this happens because TLT is not trading 24 hours a day. TLT restarts each day, then the shorter period moving average gets picked up first, followed by the slower moving averages. /ZN could be substituted for TLT since it trades 5/23 but I don't think it correlates as well as TLT. Your thoughts?
@johns52 : Thanks for your reply...Your points are well taken...I plugged in /ZN for TLT and that fixed the issue... :cool: I attached a screenshot for your review...

I then started thinking since /ZN represents the 10-Year and TLT reflects 20 years maybe it would be better to plug in /ZB (30-Year), but /ZN and /ZB turned out to be comparable, so /ZN it is...plus the 10-Year has significantly more volume, which always helps...

I updated your script to reflect /ZN and altered the color scheme a bit...I hope I'm not stepping on any toes...

Code:
# filename: _Bonds_Tracker_
# source: https://usethinkscript.com/threads/keep-track-of-bonds.17003/post-133253

#JS_ZN_Comparison
#plots /ZN (10-Year US Treasury Note Futures) with three averages
#be sure to set it up on the Left Axis if overlaying price

declare lower;

input Period1 = 21;
input Period2 = 55;
input Period3 = 233;

plot ZN = Close("/ZN");

ZN.SetPaintingStrategy(PaintingStrategy.LINE);
ZN.SetLineWeight(1);
ZN.SetDefaultColor(Color.WHITE);

plot ZNAvg1 = Average(ZN, Period1);

ZNAvg1.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg1.SetLineWeight(2);
ZNAvg1.SetDefaultColor(Color.GREEN);

plot ZNAvg2 = Average(ZN, Period2);

ZNAvg2.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg2.SetLineWeight(2);
ZNAvg2.SetDefaultColor(Color.ORANGE);

plot ZNAvg3 = Average(ZN, Period3);

ZNAvg3.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg3.SetLineWeight(2);
ZNAvg3.SetDefaultColor(Color.RED);

def rising = ZN > ZNAvg1 and ZNAvg1 > ZNAvg2 and ZNAvg2 > ZNAvg3;

def falling = ZN < ZNAvg1 and ZNAvg1 < ZNAvg2 and ZNAvg2 < ZNAvg3;

AddLabel(yes, "ZN Trend", if rising then color.GREEN else if falling then color.RED else color.YELLOW);

Thanks again for assembling and posting this study...It is much appreciated...

Good Luck and Good Trading...
 

Attachments

  • 202310252124_ZN_.jpg
    202310252124_ZN_.jpg
    83.8 KB · Views: 225
@johns52 : Thanks for your reply...Your points are well taken...I plugged in /ZN for TLT and that fixed the issue... :cool: I attached a screenshot for your review...

I then started thinking since /ZN represents the 10-Year and TLT reflects 20 years maybe it would be better to plug in /ZB (30-Year), but /ZN and /ZB turned out to be comparable, so /ZN it is...plus the 10-Year has significantly more volume, which always helps...

I updated your script to reflect /ZN and altered the color scheme a bit...I hope I'm not stepping on any toes...

Code:
# filename: _Bonds_Tracker_
# source: https://usethinkscript.com/threads/keep-track-of-bonds.17003/post-133253

#JS_ZN_Comparison
#plots /ZN (10-Year US Treasury Note Futures) with three averages
#be sure to set it up on the Left Axis if overlaying price

declare lower;

input Period1 = 21;
input Period2 = 55;
input Period3 = 233;

plot ZN = Close("/ZN");

ZN.SetPaintingStrategy(PaintingStrategy.LINE);
ZN.SetLineWeight(1);
ZN.SetDefaultColor(Color.WHITE);

plot ZNAvg1 = Average(ZN, Period1);

ZNAvg1.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg1.SetLineWeight(2);
ZNAvg1.SetDefaultColor(Color.GREEN);

plot ZNAvg2 = Average(ZN, Period2);

ZNAvg2.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg2.SetLineWeight(2);
ZNAvg2.SetDefaultColor(Color.ORANGE);

plot ZNAvg3 = Average(ZN, Period3);

ZNAvg3.SetPaintingStrategy(PaintingStrategy.LINE);
ZNAvg3.SetLineWeight(2);
ZNAvg3.SetDefaultColor(Color.RED);

def rising = ZN > ZNAvg1 and ZNAvg1 > ZNAvg2 and ZNAvg2 > ZNAvg3;

def falling = ZN < ZNAvg1 and ZNAvg1 < ZNAvg2 and ZNAvg2 < ZNAvg3;

AddLabel(yes, "ZN Trend", if rising then color.GREEN else if falling then color.RED else color.YELLOW);

Thanks again for assembling and posting this study...It is much appreciated...

Good Luck and Good Trading...
Very nice. Glad you like this. A simple indicator but very useful. I will try the /ZN version and compare it to the TLT version.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
354 Online
Create Post

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