FRED Recession Indicator for ThinkorSwim

BenTen

Staff member
Staff
VIP
This indicator tries to predict the recession four quarters ahead using the yield curve spread (the spread between the interest rates on the ten-year Treasury note and the three-month Treasury bill). I previously saw some of our members talking about this concept in the Discord chatroom but didn't put much thought into it until recently, I came across this script on TradingView.

The yield curve—specifically, the spread between the interest rates on the ten-year Treasury note and the three-month Treasury bill—is a valuable forecasting tool. It is simple to use and significantly outperforms other financial and macroeconomic indicators in predicting recessions two to six quarters ahead.

More on that here.

The following table is important. Recession Probability Value of Spread.

5% → 1.21
10% → 0.76
15% → 0.46
20% → 0.22
25% → 0.02
30% → -0.17
40% → -0.50
50% → -0.82
60% → -1.13
70% → -1.46
80% → -1.85
90% → -2. 40

The Recession Indicator below will plot the yield curve spread along with the 25% probability value, which is 0.02. You can refer back to the table above and adjust this probability line based on your liking.

thinkScript Code

Code:
``````# FRED Recession Indicator
# Assembled by BenTen at UseThinkScript.com

declare lower;

def tenyear_tres = close("DGS10:FRED");
def threemonth_tb = close("DTB3:FRED");

plot ratio = tenyear_tres - threemonth_tb;
plot value = 0.02;``````

thanks Ben!

@BenTen I added percentage prob option. Can you check it out.

Python:
``````# FRED Recession Indicator
# Assembled by BenTen at UseThinkScript.com
# Updated 2020-12-28 Barbaros, added percentage probability

#5% → 1.21
#10% → 0.76
#15% → 0.46
#20% → 0.22
#25% → 0.02
#30% → -0.17
#40% → -0.50
#50% → -0.82
#60% → -1.13
#70% → -1.46
#80% → -1.85
#90% → -2.40

declare lower;

input chartType = { default ratio, percentage };

def tenyear_tres = close("DGS10:FRED");
def threemonth_tb = close("DTB3:FRED");
def diff = tenyear_tres - threemonth_tb;
def perc = (-25.896 * diff) + 29.036;

plot limit;
plot prob;

switch(chartType) {

case ratio:
prob =  diff;
limit = 0.02;

case percentage:
prob = perc;
limit = 25;

}

AddLabel(yes, prob + (if chartType == chartType.percentage then "%" else ""), Color.GRAY);``````

Is there anyway to use the percentages as the scale for the chart?

Not the exact question you're looking for?

87k+ Posts
320 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?