How to calculate Max Drawdown Percentage?

Viewed 37

Can anybody help me calculate "Max Strategy Drawdown %" as shown in the strategy testor.

TV mentions the formula for Drawdown dollar value:

"Highest Equity of all time - Lowest Equity after the highest peak"

While Percentage Drawdown is calculated relatively:

The percentage and absolute values of a drawdown are two different metrics. They are tracked independently. For example, let’s say the initial capital is $100. After a series of losing trades, equity decreases to $50. The drawdown amounts to $50 in absolute terms and 50% in relative terms. Later, after a series of profitable trades, equity increases to $300 and then drops to $200. In this case, the absolute drawdown will be $100, and the relative drawdown, 33%. The overall maximum absolute drawdown of the strategy will be $100, and the maximum relative drawdown will be 50%.

//@version=5
strategy("Max Drawdown")

maxDrawdown = (strategy.max_drawdown/strategy.initial_capital * 100) 

longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
1 Answers

It can be fairly simple depending on what exactly you need.
Pine Script helps you a lot with that. Link

maxTradeDrawDown() =>
maxDrawdown = 0.0
for tradeNo = 0 to strategy.closedtrades - 1
    maxDrawdown := math.max(maxDrawdown, strategy.closedtrades.max_drawdown(tradeNo))
result = maxDrawdown  

Like the example from TradingView shows you can use the built-in strategy.closedtrades.max_drawdown(trade_num). Depending on your needs you can get the max drawdown (like above) or without math.max() you can add up to a total drawdown, whatever you want. Then you can calculate your percentage by deviding it by your strategy.initial_capital.

Related