Skip to content
All library documents

Single-Pass and Pairwise Maximum Drawdown Calculations

Article TradingView scripts

Summary

This document explains how to calculate absolute and percentage maximum drawdown from an ordered array of values, such as an account balance series. For each measure, it presents a pairwise search that compares candidate peaks with later troughs and a single-pass method that tracks a running peak while scanning forward. Both methods return the drawdown and its associated peak and trough; the example also counts iterations and displays results for recent closing prices.

The stated computational distinction is that the pairwise approach requires a number of comparisons that grows quadratically with the series length, while the optimized scan uses one pass. The script offers an implementation example rather than a trading strategy or empirical performance study. Its illustration uses a short sample of closes, so it does not establish how a drawdown measure should be applied to portfolio equity, nor does it assess data quality or edge cases such as empty arrays or zero values in percentage calculations. The code and description are useful as a basic algorithmic reference, but users should validate behavior for their own input conventions.

Key ideas

  • Maximum drawdown is the largest decline from an earlier peak to a later trough in an ordered series.
  • Absolute drawdown measures the value difference, while relative drawdown expresses the decline as a percentage of the peak.
  • A pairwise search checks candidate peak and trough combinations, while a running-peak scan can compute the largest decline in one pass.
  • The functions return the drawdown alongside its peak and trough values.
  • The chart example demonstrates calculations on recent closes but does not test trading performance.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.