Concept
Order-statistic Filters
Order-statistic Filters, also known as moving median, moving mode, are Trend concepts. The Library holds 3 implementations, each one a working definition you can pull into Quant.
Top Order-statistic Filters indicators
3 total
What are Order-statistic Filters?
Order-statistic filters smooth a series by ranking rather than averaging. Slide a window of the last N values along the chart, sort the contents, and output the value at a chosen rank: the middle value gives the moving median, a chosen percentile gives a percentile filter, the two extremes give running maximum and minimum, and the most frequent value gives a moving mode. Because the output is chosen by rank, always an actual data point or an interpolation between two adjacent ones rather than a weighted blend of the whole window, these are nonlinear filters and behave differently from any moving average.
The practical appeal is robustness. A single bad tick or one violent bar drags a mean in proportion to its size but barely moves a median, and where linear smoothers round off sharp level shifts, a median tends to preserve them, at the cost of a steppy, plateau-prone output. The family also generalizes tools traders already know: Donchian channels are simply the 100th and 0th percentile filters plotted as a channel.
How to calculate a moving median
The moving median is the flagship order-statistic filter, and every other member of the family is the same procedure with a different rank.
- 1Choose a window length N and, at each bar, collect the most recent N values of the source series (close, volume, an indicator, anything).
- 2Sort the window's values in ascending order.
- 3Output the middle value. With an odd N that is the single center element; with an even N, average the two center elements.
- 4For the general case, output a different rank instead: the p-th percentile (interpolating between neighboring ranks where needed), the maximum, the minimum, or the most frequent value for a moving mode.
How traders use it
- To despike raw data: a short moving median strips isolated bad ticks and single-bar anomalies before other indicators are computed, a standard outlier-handling step.
- As a robust baseline: swapping a moving median in place of an SMA or EMA gives a centerline that one wide bar barely moves, useful in gappy or thinly traded markets.
- As percentile channels: an upper and lower percentile of price over a lookback frame a range that ignores the most extreme excursions, a softer alternative to pure high-low channels.
- Inside classic constructs: median-based variants of tools like Supertrend or MACD replace the mean component so the signal reacts less to single-bar shocks.
Order-statistic Filters vs similar smoothers
SMA: An SMA is a linear filter: every value in the window contributes proportionally, so one outlier shifts the output. A moving median is rank-based, so an outlier's size never enters the output; at most it shifts which value sits in the middle.
Gaussian Filter: A Gaussian filter is a linear smoother that produces gracefully rounded output and smears sharp level shifts. A median filter preserves step changes but prints plateaus and staircases instead of smooth curves.
Donchian Channels: Donchian channels are the extreme special case: running maximum and minimum, the 100th and 0th percentiles. General order-statistic filters can take interior ranks, which are far less sensitive to a single extreme bar.
Related concepts · Digital filters & smoothers
Concept family
Trend
100 concepts mapped · 88 in the Library
Order-statistic Filters FAQ
What is a moving median in trading?
It is the middle value of the last N bars, recomputed each bar: sort the window and take the center element (or the average of the two center elements when N is even). It smooths like a moving average of similar length but resists spikes: an extreme value lands at the end of the sorted window, so it can shift the median to a neighboring observation at most and never drags it in proportion to its size.
When is a moving median better than a moving average?
When the data contains outliers: bad ticks, thin-market spikes, or one-bar news candles that would drag a mean. The median ignores them almost entirely. The trade-off is a steppier line that can sit still while price drifts, so neither is universally better; they suit different noise profiles.
How long should a median filter window be?
Long enough to outvote the noise you want removed: a run of k consecutive spike bars survives unless the window holds at least 2k+1 values, so a 3-bar median only removes 1-bar spikes. Beyond that, the usual trade-off applies: longer windows are smoother and lag more.
Build Order-statistic Filters your way.
Quant writes, tests, and refines it with you — then it runs on LuxAlgo charting or ports to TradingView.
.png&w=3840&q=75)

