When they ‘invert’ long-term bonds have a lower interest rate than short-term bonds. In other words, the bond market is pricing in a significant drop in future interest rates (which might be caused by the US Fed fighting off a recession in the future).
In the last 50 years, every time the US treasury yield curve inverted a recession followed within 3 years. On average the S&P500 gained 19.1% following the inversion and peaked 13 months later. In other words, as far as investors are concerned, the recession began roughly one year later.
However, once the market peaks, it then drops 37.6% on average, wiping out all those gains and more.
...Looks like 2020 is shaping up to be another prime example.
In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.