Indicator · Pine Script v6 · Own pane

Ehlers Reflex Indicator

by mihakralj

Calculates John Ehlers' Reflex indicator to measure price cycle reversal tendencies and trend direction with low lag.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code88
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

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

reflex.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Ehlers Reflex Indicator (REFLEX)", "REFLEX", overlay = false)

//@function Ehlers Reflex — a zero-lag oscillator that measures the reflex (reversal
//          tendency) of price by comparing the SSF-filtered price against a linear
//          extrapolation from N bars ago. Applies a 2-pole Super Smoother pre-filter
//          at half the specified period, then computes slope = (Filt[N] - Filt) / N,
//          sums deviations of the extrapolated line from actual filtered values over
//          the window, and normalizes by exponential RMS. Values above 0 suggest
//          uptrend, below 0 suggest downtrend; crossovers signal reversals.
//@param source Series to analyze
//@param period Lookback window / assumed cycle period (>= 2)
//@returns Reflex oscillator value (normalized, roughly ±σ scale)
//@reference Ehlers, J.F. (2020). "Reflex: A New Zero-Lag Indicator."
//           Technical Analysis of Stocks & Commodities, Feb 2020.
//@optimized O(period) per bar for the summation loop; SSF is O(1) IIR
reflex(series float source, simple int period) =>
    if period < 2
        runtime.error("Period must be at least 2")

    float price = nz(source)

    // --- 2-Pole Super Smoother Filter (half-period cutoff) ---
    float half_period = period * 0.5
    float a1 = math.exp(-1.414 * math.pi / half_period)
    float b1 = 2.0 * a1 * math.cos(1.414 * math.pi / half_period)
    float c2 = b1
    float c3 = -(a1 * a1)
    float c1 = 1.0 - c2 - c3

    var float filt  = 0.0
    var float filt1 = 0.0
    var float filt2 = 0.0
    float src1 = nz(source[1])
    filt2 := filt1
    filt1 := filt
    filt := c1 * (price + src1) * 0.5 + c2 * filt1 + c3 * filt2

    // --- Circular buffer to store filtered values for lookback ---
    var array<float> buf = array.new_float(period + 1, 0.0)
    var int head = 0
    array.set(buf, head, filt)

    int count = math.min(bar_index + 1, period)

    // --- Slope: (Filt[Length] - Filt) / Length ---
    int lag_idx = (head - period + period + 1) % (period + 1)
    float filt_lag = array.get(buf, lag_idx)
    float slope = (filt_lag - filt) / period

    // --- Sum the differences ---
    // Sum = Σ(i=1..Length) [(Filt + i*Slope) - Filt[i]] / Length
    float the_sum = 0.0
    if count >= period
        for i = 1 to period
            int idx = (head - i + period + 1) % (period + 1)
            float filt_i = array.get(buf, idx)
            the_sum += (filt + float(i) * slope) - filt_i
        the_sum /= period

    // --- Advance head ---
    head := (head + 1) % (period + 1)

    // --- Normalize in terms of Standard Deviations ---
    // MS = 0.04 * Sum² + 0.96 * MS[1]  (exponential RMS)
    var float ms = 0.0
    ms := 0.04 * the_sum * the_sum + 0.96 * ms

    float result = 0.0
    if ms > 0.0
        result := the_sum / math.sqrt(ms)

    result

// ── Inputs ──
int   p_period = input.int(20, "Period", minval = 2)
float p_src    = input.source(close, "Source")

// ── Calculation ──
float out = reflex(p_src, p_period)

// ── Plot ──
plot(out, "REFLEX", color.yellow, 2)
hline(0, "Zero", color.gray)
hline(1.0, "+1σ", color.new(color.red, 60))
hline(-1.0, "-1σ", color.new(color.green, 60))

Overview

The script pre-filters price data using a two-pole Super Smoother Filter, measures linear extrapolation slope deviations over a lookback window, and normalizes the results with an exponential RMS calculation. Plotted in a separate pane alongside zero line and standard deviation boundaries (+1σ and -1σ), values above zero indicate uptrends while values below zero indicate downtrends.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Oscillators & momentum, Trend, Mean reversion

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
Periodint20p_period
Sourcesourceclosep_src
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

Calculates a composite carry and decay oscillator fusing impulse-autocorrelation half-life, a Hurst exponent approximation, path efficiency, and range expansion ratios. It evaluates whether an impulse is likely to persist or mean-revert, plotting the oscillato

Indicator v6 TrendOscillators & momentum
Updated yesterday · MIT GitHub repository of Market Memory & Decay Oscillator [WavesUnchained]

MACD x RSI Study

by jerryinyang
5 stars

This indicator combines MACD and RSI to generate pullback signals on forex pairs. It plots MACD line, signal line and histogram alongside RSI and Wave Trend oscillator. Higher-timeframe MACD provides trend bias while RSI identifies overbought and oversold zone

Indicator v4 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of MACD x RSI Study
2 stars

Rolling Z-Score Trend [QuantAlgo] calculates a rolling Z-score using mean and standard deviation over a user-defined lookback window to evaluate statistical price deviations and momentum. Plotted in a separate indicator pane, it displays the rolling Z-score li

Indicator v6 TrendOscillators & momentum
Updated 8 months ago · None stated GitHub repository of Rolling Z-Score Trend [QuantAlgo]

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

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

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