All free tools

Trading metric

Max Drawdown Calculator

Paste an equity curve, an account balance history, or a running P&L and this finds the deepest peak-to-trough decline in it, how long the account spent below a previous high, and the gain required to climb back.

Max drawdown
17.09%
A fall of 1,940.00 from a peak of 11,350.00.
Recovery needed
20.62%
Gain required from the trough to reach the old peak again.
DetailValue
Peak value before the decline11,350.00
Trough value at the bottom9,410.00
Decline in value1,940.00
Data points from peak to trough5
Longest stretch below a prior peak8 points
Gain needed to recover from the trough20.62%
Drawdown at the end of the series0.00%
Values read17

What max drawdown measures

Max drawdown is the largest percentage fall from a peak to a subsequent trough anywhere in a series. It is calculated by walking the curve from left to right, remembering the highest value seen so far, and measuring how far below that running high each later value sits. The deepest of those falls is the maximum drawdown.

The order of the values is what makes it different from simply comparing the highest and lowest points in the series. A curve that fell to its low before reaching its high never experienced that full decline as a drawdown, because the peak had not happened yet. Drawdown is a path-dependent measure, so shuffling the same set of returns into a different order changes the answer.

Two secondary numbers usually matter as much as the depth. The first is duration, meaning how long the account stayed below a previous high, which this calculator reports in data points because a pasted series carries no dates. The second is the recovery required, which grows faster than the loss: a 20% fall needs a 25% gain to undo, and a 50% fall needs 100%. Our drawdown recovery calculator covers that asymmetry on its own.

How to read the result

Depth alone is an incomplete picture. A short, sharp decline that recovers within a few weeks is a very different experience from a shallower decline that grinds on for a year, even when the percentage is identical. That is why the longest stretch below a previous peak is reported alongside the depth rather than buried.

Be careful about the sample. A drawdown figure from thirty data points tells you almost nothing about what the same process might produce over three hundred, because the worst decline in any sample is a single extreme observation rather than an average. The measured maximum is the worst thing that happened to have occurred in the window you pasted, and there is no rule that says a future window cannot be worse.

Also check what your series actually contains. This calculator expects account balances or equity values, not the profit and loss of individual trades. If you paste per-trade results, the numbers it returns will not mean anything. If your data has a zero or a negative balance in it, the percentage calculation has no sensible interpretation and the calculator will decline to produce one.

What are TradingView and Pine Script?

TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.

People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.

The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.

Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.

Turn this into Pine Script

You just measured drawdown on a fixed set of numbers. On a TradingView chart the equivalent runs continuously: TradingView's Strategy Tester reports max drawdown for any coded strategy, and you can also track it yourself in Pine Script with the same peak-following logic this calculator uses, then plot the current and worst values as they develop.

The Pine version needs one thing the calculator does not: a variable that survives from bar to bar. That is what var is for. Without it the running peak resets on every bar and the drawdown reads as zero forever, which is a common and quiet mistake. Our guide to var and varip explains why.

Pine Script v6
//@version=6
strategy("Max drawdown example", overlay = true)

// ... your entry and exit rules go here ...

// TradingView reports max drawdown in the Strategy Tester, but you can also
// track it yourself. This is the same peak-tracking walk the calculator does.
var float peakEquity = na
peakEquity := na(peakEquity) ? strategy.equity : math.max(peakEquity, strategy.equity)

drawdownPct = (peakEquity - strategy.equity) / peakEquity * 100

var float worstDrawdown = 0.0
worstDrawdown := math.max(worstDrawdown, drawdownPct)

plot(drawdownPct,   "Current drawdown %", color = color.new(color.red, 0))
plot(worstDrawdown, "Max drawdown %",     color = color.new(color.gray, 0))

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.

Related free calculators

From the blog

PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.