Skip to content

Rolling Median

Math · Rolling

Rolling Median node on the canvas

Median of the trailing N bars — the outlier-resistant cousin of a rolling mean. Useful when one bad print would skew an SMA.

Rolling Median reports the middle value of a series over the trailing N bars. It's the outlier-resistant cousin of a moving average: where one freak print can yank an SMA around, the median barely notices it, because a single extreme value just becomes the new top or bottom of the sorted window rather than distorting the centre. When you want a smooth, robust read of "where the series has been sitting," the median is often the better choice.

How it works

Each bar the block sorts the source's last Window (bars) values (default 14) and outputs the middle one. Feed it Bars (uses close) or any series. Because it ignores magnitude and only cares about rank, spikes and gaps move it far less than they move a mean.

When to use it

Use Rolling Median when outliers would corrupt a mean. On gappy or spike-prone instruments it gives a cleaner trend baseline than an SMA. It's also a robust centre for a mean-reversion reference — price's distance from its rolling median is less skewed by one violent bar than its distance from an SMA. Anywhere you'd reach for a simple average but worry about a single bad print, the median is the sturdier pick.

Example

A robust mean-reversion centre: compute the Rolling Median of price over 20 bars and measure price's distance from it with Subtract; fade large deviations back toward the median. The median centre won't be dragged off by a single spike the way an SMA would. Backtest in the Tester.

Tips & gotchas

  • Outlier-resistant — one freak bar barely moves it, unlike an SMA.
  • Best on gappy/spiky data — cleaner trend baseline there.
  • Rank-based, not magnitude-based — that's the source of its robustness.
  • Slightly "steppier" than a mean — it jumps between actual values rather than gliding.

Inputs

Socket Type What to wire in
In series / bars Source series. BARS input uses close.

Outputs

Output Type Plots as Description
median series Line · sub-pane Per-bar rolling median.

Parameters

Parameter Type Default What it does
Window (bars) number · 2–500 14 Bars in the rolling window.

Reference auto-generated from the block catalog · category Math.