InvestorUnknown

Asset Drawdown & Drawdown HeatMap [InvestorUnknown]

Overview

The "Asset Drawdown & Drawdown HeatMap" indicator is designed for educational purposes to help users visualize and analyze the drawdowns of various assets. It highlights both recent and historical drawdowns, offering valuable insights into the performance and risk of different investments. Additionally, it can serve as a complementary analysis tool for trading and investing decisions.

Features

Drawdown Calculation:
  • Computes the drawdown from the highest value (ATH) to the current value, showing the percentage decline.
  • Displays both the current drawdown and the maximum historical drawdown for the selected assets.

HeatMap Visualization:
  • Uses a gradient color scheme to represent the magnitude of drawdowns over a specified lookback period.
  • Helps identify periods of significant decline and recovery visually.


Multiple Assets:
  • Supports up to 10 different assets (adding more would make it harder to see the drawdowns of different assets), allowing users to compare drawdowns across various symbols.
  • Each asset can be individually plotted and color-coded for clarity.


Customizable Settings:
  • User inputs for high and low value calculations, color preferences, and lookback periods.
  • Option to color bars based on the drawdown heatmap.

Detailed Functionality

Drawdown Calculation:
The DD() function calculates the current drawdown and the maximum historical drawdown based on the high and low values.
The drawdown is calculated as 100 - (lowvalue / ATH * 100), where ATH is the highest value observed so far.

// - - - - - Custom Function - - - - - //{
DD() =>
    ATH = highvalue
    ATH := na(ATH[1]) ? highvalue : math.max(highvalue, ATH[1])
    Drawdown = 100 - lowvalue / ATH * 100
    MaxDrawdown = Drawdown
    MaxDrawdown := na(MaxDrawdown[1]) ? Drawdown : math.max(Drawdown, MaxDrawdown[1])
    [Drawdown,MaxDrawdown]
//}

Security Request:
Uses the request.security() function to fetch drawdown data for each specified asset on a daily timeframe.
Computes both current drawdown (TnDD) and maximum drawdown (TnMDD) for each asset.

// - - - - - Create Variables - - - - - //{
[T0DD ,  T0MDD] = request.security("",  "1D", DD()) // Chart
[T1DD ,  T1MDD] = request.security(t1,  "1D", DD())
[T2DD ,  T2MDD] = request.security(t2,  "1D", DD())
[T3DD ,  T3MDD] = request.security(t3,  "1D", DD())
[T4DD ,  T4MDD] = request.security(t4,  "1D", DD())
[T5DD ,  T5MDD] = request.security(t5,  "1D", DD())
[T6DD ,  T6MDD] = request.security(t6,  "1D", DD())
[T7DD ,  T7MDD] = request.security(t7,  "1D", DD())
[T8DD ,  T8MDD] = request.security(t8,  "1D", DD())
[T9DD ,  T9MDD] = request.security(t9,  "1D", DD())
[T10DD, T10MDD] = request.security(t10, "1D", DD())
//}

Plotting:
Plots the drawdown values for each asset on the chart, with the option to enable or disable plotting for individual assets.
Colors the plotted lines and labels based on user-specified preferences.

HeatMap:
Creates a heatmap color gradient based on the drawdown values over the lookback period.
Colors the bars on the chart according to the heatmap to visualize drawdown severity over time.

// - - - - - HeatMap - - - - - //{
heatcol = color.from_gradient(T0DD, ta.lowest(T0DD,lookback), ta.highest(T0DD,lookback), topcol, botcol)
barcolor(colbars ? heatcol : na)
//}

Labels:
Displays labels for each asset's drawdown value at the end of the chart for quick reference.


This indicator is an excellent tool for educational purposes, helping users understand drawdown dynamics and their implications on asset performance. It also provides a visual aid for monitoring and comparing drawdowns across multiple assets, which can be beneficial for making informed trading and investment decisions.
Open-source script

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.

Disclaimer

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.

Want to use this script on a chart?