ta.drawdown
Measure how far a series sits below its running peak, over the run or each period.
ta.drawdown(source, reset)Drawdown against the running peak of the run, or of each period with reset: [source/peak - 1, the running minimum of that, bars since the peak was last set]. The base is the highest value seen since the first bar of the run or period. It is not a rolling window. drawdown and maxdrawdown are fractions and never positive, with 0 on a bar that sets a new peak. duration is 0 on that bar and counts observed bars, not elapsed time.
Parameters
A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
source | Series | number | - | - | A positive series: a price, or an equity curve. |
reset | Constant | string | - | - | Restarts the peak, the worst drawdown and the duration at the first bar of each session, day, week, month, quarter or year (an option, written reset=session). |
Outputs
| Name | Type |
|---|---|
drawdown | number |
maxdrawdown | number |
duration | number |
The outputs come back in this order: [drawdown, maxdrawdown, duration] = ta.drawdown(…).
Warm-up and missing values
- Warm-up
- 1 bar.
- Missing values
- na until the first non-na, strictly positive observation, which seeds the peak. An na bar leaves all three outputs standing rather than resetting them, exactly as ta.cum keeps its total across a gap. na while the running peak is not strictly positive. Each period starts empty.
Example
[dd, maxdd, bars] = ta.drawdown(close)[dd, maxdd, bars] = ta.drawdown(close)
plot(dd, "Drawdown")