Recursive Median Oscillator by John Ehlers

Recursive Median Oscillator by John Ehlers

This is the the recursive median Oscillator featured by John Ehlers in the march 2017 issue of Trader’s Tips.

In “Recursive Median Filters” in this issue, author John Ehlers presents an approach for filtering out extreme price and volume data that can throw off typical averaging calculations. Ehlers goes on to present a novel oscillator using this technique, comparing its response to the well-known RSI. He notes that by being able to smooth the data with the least amount of lag, the recursive median oscillator may give the trader a better view of the bigger picture.


Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

New! PRC is also now on YouTube, subscribe to our channel for exclusive content and tutorials

  1. JMat45 • 03/08/2018 #

    Thanks, Despair. Wasn’t it the most recent issue though, i.e. March 2018?

  2. Despair • 03/08/2018 #

    You are right, it is from March 2018. 🙂

  3. Bard • 03/08/2018 #

    See this PRT link for more details from Stocks & Commodities Magazine:
    (submit link button wouldn’t open)

  4. Bard • 03/08/2018 #

    From the url link #post-65420 above but without the chart image:

    Stocks & Commodities V. 36:03 (8–11): Recursive Median Filters by John F. Ehlers

    Impulsive noise spikes or extreme price or volume data are not unusual in the nancial markets and these extreme values can throw off your averaging calculations. How can you set up a data lter to re- move these extreme price movements? This STOCKS & COMMODITIES Contributing Editor shows you a way to handle this by using a lter that discards all data except the median value.

    Median lters are best applied to remove impulsive or spiking types of noise. Rather than averaging the spike into the lter out- put, median lters simply ignore the spike. Median lters are routinely used for pro-

    cessing photographs and video because they preserve the sharp edges in the images rather than smoothing them as is done by averaging lters. Median lters have the unique characteristic of being idempotent, that is, if you repeatedly perform median ltering on a time waveform, the output rapidly converges to being exactly the input waveform except for com- putational lag. That a price waveform converges to a core waveform has some interesting philosophical rami cations for trading.

    HOW SO?

    Median lters are nonlinear. Since a median lter is not a convolution lter, it cannot be suitably represented in the Fourier frequency domain. Also, its output is not differentiable and therefore does not have a Taylor series expansion. This precludes curve- tting by a higher-order polynomial.

    There are many academic articles describing rather arcane algorithms for recursive median lters. The rea- son I consider the algorithms arcane is they exclusively study nite impulse response (FIR) types of lters.

    This is because the applications being considered are being implemented in hardware rather than software. “Recursive” means using a previous calculation in the current calculation.


    An example of a recursive lter used in trading is the exponential moving average (EMA). I propose a recur- sive median lter for trading be implemented as the EMA of a ve-bar median lter. A simple pseudocode representation of a recursive median lter is:

    Output = a*Median(Input, 5) + (1 – a)*Output[1];

    The EMA a is a constant between zero and 1. I prefer to calculate it in terms of the critical period of the lter. The critical period is where shorter wavelengths are passed by the lter and longer wavelengths are rejected at the lter output. The relationship between the EMA constant and critical period is expressed by the equation:

    a = (Cosine (360 / Period) + Sine (360 / Period) – 1) / Cosine (360 / Period)

    where the arguments of the trigonometric terms are in degrees.

    An easier-to-remember approximation to the re- lationship between the EMA constant and critical period is:

    a = 5 / Period


    An interesting and unique oscillator-type indicator can be cre- ated from the recursive median lter by further ltering with a second-order highpass lter. The highpass lter removes the DC (constant) values and very long wavelength components from the recursive median lter output. Using a second-order lter guarantees attenuation of the long wavelength components resulting from the statistical fractal pink-noise spectral shape of market data.

    The second-order nature of the highpass lter reduces its critical period about 70% relative to the critical period of an EMA lter. The EasyLanguage code to compute the recursive median oscillator is given in sidebar “EasyLanguage Code For Recursive Median Oscillator.”

    You can see the uniqueness and novelty of the recursive median oscillator when you compare it to the RSI (Figure 1). The recursive median oscillator is displayed in the rst sub- graph and the RSI is plotted in the second subgraph. The RSI is scaled to swing from -1 to +1 instead of the standard swing from zero to 100. The price data for Figure 1 is of the SPY for

    the calendar year 2017. The recursive median oscillator uses a 40-bar (two-month) critical highpass period and the RSI uses a standard 14-bar calculation. Both indicators have a smoothing lter critical period of 16 bars. From Figure 1 you can see that the recursive median oscillator has less lag and generally has faster response to the larger moves in the price data.


    When data contains impulsive noise or uctuations in data, a trader needs to gure out how to smooth that data with the least amount of lag. The recursive median oscillator meets this need by ltering out outlier data, which gives a better view of the bigger picture.

    S&C Contributing Editor John Ehlers is a pioneer in the use of cycles and DSP technical analysis. He is president of MESA Software and cofounder of MESASoftware. com offers the MESA Phasor and MESA intraday futures strategies.

    The code given in this article is available in the Article Code section of our website,

    (See our Traders’ Tips section beginning on page 48 for commentary and implementation of John Ehlers’ technique in various technical analysis programs. Accompanying program code can be found in the Traders’ Tips area at

    The EasyLanguage code to compute the recursive median Filter is given in sidebar “EasyLanguage Code For Recursive Median Filter.”)

  5. Bard • 03/08/2018 #

    Note: lter = filter

  6. Bard • 03/08/2018 #

    Apologies, there’s been an issue with copying “f” and “I” from the article and pasting.. which in part, is why I’m waiting for UPS to take this new MacBook Pro back to today…

Register or


avatar avatar avatar avatar avatar avatar avatar avatar avatar avatar
Related users ' posts
Ste Thanks. I would like if possible some further explanation and clarification on the P3 (64) n...
Jan Hi Actarus, Thanks for the code ! To get the picture as attached above from the indicato...
Actaru5 Caio Jan, con ognuno dei setting ottieni un indicatore visualizzato diverso, ma tutti sono ...
eva.g.forsgren I cant make it work in anyway.
Nicolas Play with the "highpassLength" settings and add more units displayed on your chart.
MrEastwood Interesting indicator! Can anyone get it working for longer "highpasslengths"? I've been tes...
Morrissey38 Buenas tardes Nicolás . Como podría introducir una línea cero a este indicador? . Muchas gra...
Nicolas Change the last line with : RETURN Reflex, 0
Morrissey38 Muchísimas gracias Nicolás , muy amable.
Sapo Thank you for your indicators. As always it's perfect, I thank you for your help it's preci...
eivaremir have u got the trading view version?
finplus Bonjour, cet indicateur a t il fait l'objet d'une évolution avec PRT 11 ? Par ailleurs, en ...
kj1988 Thank you for this nice indicator. I find it useful and a better replacement for the RSI
ALE Happy to know
Nicolas Thanks again for all your valuable posts... and well formatted code! :)
Abdelkrim Maksour hi sir is this indicator for mt4 and how i can get one .
Nicolas Thanks a lot for this new valuable addition to our library. I changed line 76 with "barindex...
Horance Thanks. I've noticed this leftover after submission, but it was too late for editing. BTW, I...
Etienne Thanks Horance for porting this code to PRT. I would like to bring some speedup to your cod...
Horance This is a good question. John Ehlers explains it in Rocket Science for Traders. You have to ...
cbeukes Much appreciated, I will give that a try. Also, is there any criteria that one could use to ...
firemyst Thanks for the code! I'm trying to understand how it works, and have a few questions... line...
Bebbo Grazie del prezioso contributo Nicolas, scusa la mia inesperienza, sono alle prime armi e s...
Nicolas To avoid recalculation, you should use the one from this post.
Bebbo Ok Grazie Nicolas.
Appsoluxions Hi Nicolas, do you have the MT4 version of the indicator? I am not sure if these kind of que...
Nicolas Hi, don't have one sorry. But you can still ask for private coding through our programming s...
Appsoluxions Cool. Thanks for the response.
Etienne Hi, thanks for proving this code. I would like to contribute by adding a computation speed...
Etienne //Compute Super Smoother coefficients once if barindex = 1 then a1 = exp( -1.414 * 3.14159...
Nicolas Thanks a lot!
2 years ago
Nicolas Oui. Pour changer la période, il faudra ajuster la variable MMperiod
macbartin plus la période est grande (en occurrence 20) plus l'indicateur est précis dans les changeme...
Hasardeur Hallo Nicolas, in John Ehlers book "cycle analytics for Traders" from 2013, Mr. Ehlers desc...
Alai-n Ok thank you Pietro...
Halan thank you for the code. coded as per above, I encounter an error "unexpected character" ...
Gianluca Hello there is a new version, is it possible to translate it?