DocsMathStatisticsMax Drawdown

Max Drawdown

Windowed · default period 20Statistics

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

NameTypeDefaultDescription
periodnumber20Rolling window size.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

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.