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が提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。

チャートでこのスクリプトを利用したいですか?