Trading metric
Calmar Ratio Calculator
The Calmar ratio compares how fast an account grew each year with the worst peak-to-trough fall it suffered on the way. Enter the start and end values, the years, and the max drawdown to compute it.
What the Calmar ratio is
The Calmar ratio is the annualized rate of return divided by the maximum drawdown over the same period: Calmar = annualized return ÷ max drawdown. Terry Young introduced it in 1991, originally using a 36 month window. A ratio of 2 means the account grew at twice the yearly rate of its worst fall.
Unlike the Sharpe ratio, which uses standard deviation, Calmar measures risk by one number: the deepest hole the account fell into. If you do not have the drawdown yet, the max drawdown calculator finds it from an equity curve, and the CAGR calculator covers the return side.
How to read the result
A higher ratio means more return per unit of drawdown. A negative ratio means the account lost value over the period. The drawdown is a single worst observation, so the ratio swings a lot when the window is short, and it only describes the period you measured.
The inputs must cover the same period. Taking the return from one window and the drawdown from another produces a number that means nothing. This is a descriptive statistic, not a forecast, and how you use it is your own decision.
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
On a chart the same ratio can be computed over a rolling window. The script measures the annualized price return across the lookback and the worst peak-to-trough fall inside it, then plots the quotient as a line with a zero reference.
It measures the instrument's own closes, not a strategy's equity. The bars per year input should match your timeframe, for example 252 for daily bars on a stock.
//@version=6
indicator("Rolling Calmar ratio", overlay = false)
lengthBars = input.int(756, "Lookback (bars)", minval = 2)
barsPerYear = input.int(252, "Bars per year", minval = 1)
years = lengthBars / barsPerYear
float calmar = na
if bar_index >= lengthBars
// Annualized return over the window, as a percentage.
annualReturn = (math.pow(close / close[lengthBars], 1.0 / years) - 1.0) * 100.0
// Max drawdown over the same window: walk oldest to newest, track the peak.
float runPeak = close[lengthBars]
float maxDd = 0.0
for i = lengthBars to 0
runPeak := math.max(runPeak, close[i])
maxDd := math.max(maxDd, (runPeak - close[i]) / runPeak * 100.0)
calmar := maxDd > 0.0 ? annualReturn / maxDd : na
plot(calmar, "Calmar ratio", color = color.new(color.blue, 0))
hline(0, "Zero", color = color.gray)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.