Order-statistic Filters
Order-statistic filters smooth a series by ranking rather than averaging. Order-statistic Filters, also known as moving median, moving mode, are Trend concepts. The Library holds 1 implementation, ready to run on Vela.
Top Order-statistic Filters indicator
The top custom implementation, built on the original standard Order-statistic Filters formula.
1 total
See the Order-statistic Filters implementation below on Vela, our next-generation charting platform, then ask Quant to turn it into a strategy you can backtest.
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 family comes from signal processing and robust statistics. John Tukey proposed running-median smoothing in the early 1970s as part of exploratory data analysis, and median filters went on to become a staple of digital image processing because they remove salt-and-pepper noise while preserving edges. Traders inherited the tools directly: a bad tick is the chart's version of a corrupted pixel, and a genuine gap or regime break is an edge worth preserving. On modern platforms the general case is built in; Pine Script® provides median and percentile functions, and array support makes arbitrary ranks straightforward to compute.
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 familiar tools: Donchian channels are simply the 100th and 0th percentile filters plotted as a channel, and a median crossover system is a moving average crossover setup with means swapped for ranks.
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 it's calculated
Filters that output a chosen rank of the last n prices rather than an average; the moving median is the best-known case.
Ranks r = 1 and r = n give the moving minimum and maximum; applied to the lows and highs these are the lower and upper Donchian channel lines.
A moving median follows clean step changes and ignores isolated spikes better than a mean of the same length, at the cost of a staircase-like output.
Exact price repeats are rare, so the moving mode is only meaningful on binned or rounded prices.
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, standard outlier handling.
- 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 and a rank-based cousin of the MA envelope.
- 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.
- As a regime condition: price holding above a rising moving median, or the median's own slope, provides a robust trend regime label, the same role an MA slope filter plays but harder for one news bar to flip.
Order-statistic Filters vs linear 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.
EMA: An EMA weights recent data more heavily but is still linear, so a single extreme bar pulls it immediately and decays out of it slowly. A median never responds in proportion to an outlier's size, though the EMA tracks smooth turns more gracefully.
Ehlers SuperSmoother: The SuperSmoother is a carefully designed linear low-pass filter with little lag for its smoothness, but like all linear filters it rounds off level shifts and passes a scaled version of every spike. A median keeps step changes crisp and drops isolated spikes entirely, at the cost of plateau-shaped output.
VWMA: A VWMA reweights the mean by volume, so it is still an average and still outlier-sensitive, just along a different dimension. Order-statistic filters discard magnitude altogether and keep only rank order.
Order-statistic Filters FAQ
Turn Order-statistic Filters into a trading strategy.
Open the implementation from this page in Vela. Quant, our coding agent, builds the strategy with you and backtests it on real data.
Browse this familyTrend104 concepts mapped · 104 in the Library
- Adaptive-lookback MA
- ADX / DMI System
- Alligator
- ALMA
- Anchored MA
- Andrews' Pitchfork
- Aroon
- ATR Trailing Regime
- Bessel Filter
- Breakout
- Butterworth Filter
- Chande Kroll Stop
- Chandelier Stop
- Chebyshev Filters
- Climactic Moves
- Continuation
- Coral Trend
- Correlation Trend Indicator
- Death Cross
- DEMA
- Displaced MA
- Donchian Trend Rules
- Dynamic S/R Via MA
- Ehlers Instantaneous Trendline
- Ehlers SuperSmoother
- Elastic Volume-weighted MA
- Elliptic Filter
- EMA
- Fan Principle
- FRAMA
- Gann Box
- Gann Fan & Angles
- Gann HiLo Activator
- Gann Method
- Gann Square of 9
- Gaussian Filter
- Geometric MA
- Golden Cross
- Guppy GMMA
- Halftrend
- Harmonic MA
- Higher-timeframe Trend Filter
- HMA
- Ichimoku Signals
- Ichimoku System
- Ichimoku Theories
- JMA
- KAMA
- Kaufman Efficiency Ratio
- Laguerre Filter
- Linear-regression Channel
- LSMA
- MA Envelope
- MA of MA
- MA Ribbon
- MA Slope Filter
- MAMA/FAMA
- McGinley Dynamic
- MLMA
- Moving Average Crossovers
- NRTR
- Order-statistic Filters
- Parabolic SAR
- Parallel Channel
- Polynomial Regression Band
- Pullback
- R-squared Trend Fit
- Rainbow MA Stack
- Random Walk Index
- Range Filter
- Retest
- Reversal
- RMA
- Savitzky-Golay Filter
- Sine-weighted MA
- SMA
- Speed Resistance Lines
- Standard-error Channel
- Supertrend
- Swiss Army Knife Filter
- SWMA
- T3
- TEMA
- TRAMA
- Trend Acceleration/inflection
- Trend Exhaustion
- Trend Intensity Index
- Trend Magic
- Trend Regime Label
- Trend-quality Composites
- Trendline
- Triangular MA
- UHL Adaptive MA
- Ultimate Smoother
- Vertical Horizontal Filter
- VIDYA
- Volume-adjusted MA
- Vortex
- VWMA
- Weinstein Stage Analysis
- Whittaker–Henderson Smoother
- Windowed FIR Smoothing
- WMA
- ZLEMA
