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.
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,以便交易者可以理解和验证它。为作者喝彩!您可以免费使用它,但在出版物中重复使用此代码受网站规则的约束。 您可以收藏它以在图表上使用。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想在图表上使用此脚本?