This Pine Script is a **Drawdown Indicator from All-Time High** for TradingView. It calculates and plots the percentage drawdown from the highest price the asset has ever reached (the all-time high). Here's a breakdown of what this script does:
### Description: - **Drawdown Calculation**: - The drawdown is calculated as the difference between the current price (`close`) and the all-time high, divided by the all-time high, and multiplied by 100 to express it as a percentage. - If the current price is higher than the previous all-time high, the all-time high is updated to the current price.
- **All-Time High Tracking**: - The script tracks the highest price (`allTimeHigh`) that the asset has ever reached. Each time a new high is reached, the `allTimeHigh` value is updated.
- **Line Plot**: - The drawdown percentage is then plotted as a line on the chart, with a color of **blue** for easy visualization. - The line shows how much the price has dropped relative to its all-time high.
- **Zero Line**: - A horizontal line is added at the **0%** level to act as a reference point, which is helpful to identify when the asset has fully recovered to its all-time high.
### Key Features: - **Track Drawdown**: The indicator helps visualize how far the current price has fallen from its highest point, which is useful for understanding the depth of losses (drawdowns) during a period. - **Update All-Time High**: The indicator automatically updates the all-time high whenever a new high is detected. - **Visual Reference**: The 0% horizontal line provides a clear indication of when the asset is at its all-time high, and the drawdown is at 0%.
### How it Works: - If the current price surpasses the all-time high, the script will reset the all-time high to the new price. - The drawdown percentage is calculated from the current price relative to this all-time high, and it is displayed as a line on the chart.
### Visuals: - **Drawdown Line**: Plots the percentage of the drawdown, which is the drop from the all-time high. - **Zero Line**: A dotted horizontal line at 0% marks the level of the all-time high.
This indicator is valuable for understanding the extent of price corrections and potential recoveries relative to the historical peak of the asset. It is especially useful for traders and investors who want to assess the risk of drawdowns in relation to the highest price achieved by the asset.
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 publication is governed by House rules. You can favorite it to use it on a chart.
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.