Indicator · Pine Script v6 · Own pane

Ehlers Reverse EMA

by mihakralj

Calculates John F.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code93
Settings2inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

93 lines of Pine Script v6 from lib/oscillators/reverseema/reverseema.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

reverseema.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
// Indicator algorithm (C) 2017 John F. Ehlers
//@version=6
indicator("Ehlers Reverse EMA (REVERSEEMA)", "REVERSEEMA", overlay=false)

//@function Calculates Ehlers Reverse EMA using Z-transform inversion of EMA smoothing
//@param source Series to calculate Reverse EMA from
//@param period Lookback period for the base EMA (>= 1)
//@returns Reverse EMA value with lag removed via 8-stage cascaded inversion
//@optimized Uses warmup-compensated EMA with O(1) cascaded reverse stages per bar
reverseema(series float source, simple int period) =>
    if period <= 0
        runtime.error("Period must be positive")

    float src = na(source) ? 0.0 : source

    // EMA smoothing factor from period: alpha = 2/(period+1)
    float a = 2.0 / (period + 1)
    float cc = 1.0 - a
    float beta = cc

    // Precompute powers of cc for the 8 reverse stages
    // Stage k uses cc^(2^(k-1)): 1, 2, 4, 8, 16, 32, 64, 128
    float cc2   = cc * cc
    float cc4   = cc2 * cc2
    float cc8   = cc4 * cc4
    float cc16  = cc8 * cc8
    float cc32  = cc16 * cc16
    float cc64  = cc32 * cc32
    float cc128 = cc64 * cc64

    // --- Forward EMA with warmup compensator ---
    var bool warmup = true
    var float e = 1.0
    var float ema_raw = 0.0
    var float ema_val = 0.0

    ema_raw := a * (src - ema_raw) + ema_raw
    if warmup
        e *= beta
        float comp = 1.0 / (1.0 - e)
        ema_val := comp * ema_raw
        warmup := e > 1e-10
    else
        ema_val := ema_raw

    // --- 8-stage cascaded reverse EMA ---
    // Each stage: RE_k[n] = cc^(2^(k-1)) * RE_{k-1}[n] + RE_{k-1}[n-1]
    // RE1 uses EMA as input: RE1[n] = cc * EMA[n] + EMA[n-1]
    var float re1 = 0.0
    var float re2 = 0.0
    var float re3 = 0.0
    var float re4 = 0.0
    var float re5 = 0.0
    var float re6 = 0.0
    var float re7 = 0.0
    var float re8 = 0.0

    float prev_ema = nz(ema_val[1])
    float prev_re1 = nz(re1[1])
    float prev_re2 = nz(re2[1])
    float prev_re3 = nz(re3[1])
    float prev_re4 = nz(re4[1])
    float prev_re5 = nz(re5[1])
    float prev_re6 = nz(re6[1])
    float prev_re7 = nz(re7[1])

    re1 := cc    * ema_val + prev_ema
    re2 := cc2   * re1     + prev_re1
    re3 := cc4   * re2     + prev_re2
    re4 := cc8   * re3     + prev_re3
    re5 := cc16  * re4     + prev_re4
    re6 := cc32  * re5     + prev_re5
    re7 := cc64  * re6     + prev_re6
    re8 := cc128 * re7     + prev_re7

    // Signal = EMA - alpha * RE8
    float signal = ema_val - a * re8
    na(source) ? na : signal

// ---------- Main loop ----------

// Inputs
i_period = input.int(20, "Period", minval=1, tooltip="Lookback period for the base EMA")
i_source = input.source(close, "Source")

// Calculation
reverseema_value = reverseema(i_source, i_period)

// Plot
plot(reverseema_value, "REVERSEEMA", color=color.yellow, linewidth=2)
hline(0, "Zero", color=color.gray)

Overview

Ehlers' Reverse Exponential Moving Average (EMA) designed to eliminate lag from traditional exponential smoothing. The indicator computes a warmup-compensated base EMA and subjects it to an 8-stage cascaded Z-transform inversion. The resulting line plots in a separate pane alongside a zero line reference. Input parameters allow users to configure the lookback period and price source.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Moving averages, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Periodint20i_period
Sourcesourceclosei_source
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

Colored fill

by be-thomas
65 stars

This indicator plots two simple moving averages of close, one over five bars and one over twenty bars, in a separate pane. It shades the area between the two plots green when the shorter average is above the longer average and red when it is below. There are n

Indicator v4 Moving averagesTrend
Updated 4 days ago · GPL-3.0 GitHub repository of Colored fill

Hash Ribbons

by oguzhandilber
47 stars

This indicator plots the Hash Ribbon metric by calculating 30-day and 60-day simple moving averages of Bitcoin network hash rate data. Designed for long-term market cycle analysis, it draws in a separate pane and displays hash ribbons alongside optional buy si

Indicator v4 Moving averagesTrend Repaints
Updated 5 years ago · None stated GitHub repository of Hash Ribbons

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers