Macro-Indicator: 20 Day Stock vs. Bond Return
Another macro economic indicator that was requested is the difference in 20 day returns between stocks and bonds. When the market is doing well, stock tend to outperform bonds, just as bonds outperform stocks when economic times are tough. Pictured here is a screenshot of this indicator on another site, but it would be much better if we could have this in thinkorswim.
In a new study we can enter the following:
def stock_return = (close("spy") - close("spy")[20])/close("spy")[20];
def bond_return = (close("vgit") - close("vgit")[20])/close("vgit")[20];
plot dif = round(100*(stock_return-bond_return));
addlabel(1, " " + dif + "%" + if dif < -7.5 then " Extreme Fear "
else if dif > -7.5 and dif < -2.5 then " Fear "
else if dif > 2.5 and dif < 5 then " Greed "
else if dif > 7.5 then " Extreme Greed "
else " Neutral ",
if dif < -2.5 then color.red else if dif > 2.5 then color.green else color.light_gray);
plot zeroline = 0;
zeroline.setdefaultColor(color.gray);
zeroline.setStyle(curve.SHORT_DASH);
declare lower;
Note: We are using the ETF's SPY and VGIT to represent the stock and bond markets, but this could be done with a number of different similar symbols.
Also, the color choices here are what work better on the "Light" color scheme. On dark you would want to use red, green, and light gray.
Here is the result of that script, giving us a chart that matches the data displayed on top. The label at the top left will also change between Extreme Fear, Fear, Neutral, Greed and Extreme Greed depending on the value of the chart.