OPEN-SOURCE SCRIPT

US Leverage Overlay — Margin Debt & Total Credit (YoY / Z-score)

47
What this does
An overlay indicator that brings U.S. leverage proxies from FRED onto your main price chart (left axis). Choose between a proxy for investor margin debt or total credit market debt and view them as YoY %, Z-score of YoY, or an Indexed Level so they’re comparable with price without wrecking the scale.

Data sources (FRED symbols)
--- Margin (investor leverage proxy): FRED:BOGZ1FL663067003Q
Brokers & Dealers; Receivables Due from Customers ≈ margin loans (quarterly).
--- TotalCredit (economy-wide leverage): FRED:TCMDO
All sectors; Debt Securities & Loans; Liability (quarterly).

Note: These are quarterly series. The indicator samples monthly and holds values between official prints, so you’ll see step-like updates when new data drops.

Views (pick one in settings)
--- YoY % — 12-month rate of change. Above 0% = leverage expanding; below 0% = contracting.
--- Z-score (YoY) — Standardizes YoY vs. its recent history to flag unusual moves (regime shifts).
--- Indexed Level — 100 × (level / moving average), a compact “above/below trend” view.

How to read quickly
--- Rising YoY % > 0 → leverage expansion (often supportive for risk).
--- Falling YoY % < 0 → deleveraging headwind.
--- Z-score spikes (±2) → unusually fast changes; watch for volatility or policy inflections.
--- Indexed Level crossing down through 100 → slipping below trend.

Inputs
--- Data source: Margin or TotalCredit
--- YoY/Z-score lookbacks and Index baseline length
--- Overlay: overlay=true, scale=scale.left (uses its own left axis by default)

Tips
--- If it spawns in a sub-pane, right-click the label → Move to → Main chart.
--- For context, consider adding related series on separate panes:
FRED:TOTALSL (Consumer Credit), FRED:REVOLSL (Credit Cards),
FRED:BUSLOANS (C&I Loans), FRED:TDSP (Debt Service Ratio).
--- Occasionally FRED returns “Failed to fetch”; re-add or reload fixes it.

Why it’s useful
Equity drawdowns often line up with turns in leverage (households, corporates, or brokers). This overlay gives you a clean, normalized read so you can spot expansion vs. contraction alongside price action.

Compatibility
--- Pine Script® v6
--- Works on any chart timeframe (data internally sampled monthly)

Educational use only — not financial advice.

Pernyataan Penyangkalan

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.