Drawdown Dynamics Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
// Author © TradeAutomation

indicator("Drawdown Dynamics Indicator")

//Measures All Time High of Asset
var float ATH = na
ATH := if na(ATH[1])
    high
else 
    math.max(high,ATH[1])

//Measures Drawdown
Drawdown=100-(low/ATH)*100

//Measures Total Max Drawdown
var float MaxDrawdown = Drawdown
MaxDrawdown := if na(MaxDrawdown[1])
    Drawdown
else
    math.max(Drawdown,MaxDrawdown[1])

//Measures Rolling Period Max Drawdown
RollingMDD = ta.highest(Drawdown, input.int(200, "Length of Rolling Period Max Drawdown"))
UseAllTime = input.bool(false, "Use All Time Max Drawdown Instead of Rolling Period?")

//Visualizations
plot(UseAllTime==false ? RollingMDD : MaxDrawdown, "Max Drawdown", color=color.gray,linewidth=2)
plot(Drawdown, "Current Drawdown", color=color.blue,linewidth=1)