Max Drawdown
The Max Drawdown node computes the largest peak-to-trough decline as a fraction of the peak within the rolling window. Output is in the range [0, 1] where 0.15 means 15% drawdown. It is a real-time rolling risk metric for continuous assessment of the worst-case loss experienced within the lookback period. Requires at least 2 non-null values.
Algorithm
- ▸peak = running maximum from the first non-null value in the window
- ▸For each v: dd = (peak − v) / peak (when peak > 0)
- ▸output = max(dd) across all steps in the window
- ▸Returns null with fewer than 2 non-null values
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| period | number | 20 | Rolling window size. |
Inputs & Outputs
| Port | Type | Description |
|---|---|---|
| Inputs | ||
| input | number[] | Source numeric array |
| Outputs | ||
| values | number | null | Computed value at each bar; null before the warmup period completes |
| timestamps | number[] | Bar timestamps (UNIX ms), aligned 1-to-1 with values |
Use Cases
Risk-On / Risk-Off Filter
If rolling max drawdown exceeds a threshold (e.g., 5% on a price series), reduce or halt new position entries until conditions stabilize.
Strategy Evaluation
Apply Max Drawdown to an equity curve to continuously track the worst-case experience for any rolling N-bar window — equivalent to a rolling strategy quality metric.
Position Sizing Brake
Multiply position size by max(0, 1 − 5 × maxDrawdown) to automatically reduce risk exposure as recent drawdowns increase.