Indicator · Pine Script v6 · Own pane

Efficiency Ratio (ER)

by mihakralj

This indicator calculates Kaufman's Efficiency Ratio as a signal-to-noise measure of price movement.

View on GitHub

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

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

er.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Efficiency Ratio (ER)", "ER", overlay=false)

//@function Calculates Kaufman's Efficiency Ratio as signal-to-noise measure
//@param source Series to calculate from
//@param period Lookback period for efficiency measurement
//@returns ER value (0 to 1) where 1 = trending, 0 = choppy
//@optimized O(1) per bar using dual circular buffers with running sum
er(series float source, simple int period) =>
    if period <= 0
        runtime.error("Period must be greater than 0")

    var int p = math.max(1, period)

    // Close buffer: stores source values for signal (net change over period)
    var array<float> closeBuf = array.new_float(p + 1, na)
    var int closeHead = 0
    var int closeCount = 0

    // Noise buffer: stores |change| values for running sum
    var array<float> noiseBuf = array.new_float(p, na)
    var int noiseHead = 0
    var float noiseSum = 0.0

    var float prevVal = na

    float current = nz(source)

    // Compute bar-to-bar absolute change
    float absChange = not na(prevVal) ? math.abs(current - prevVal) : 0.0

    // Update noise running sum
    float oldNoise = array.get(noiseBuf, noiseHead)
    if not na(oldNoise)
        noiseSum -= oldNoise
    noiseSum += absChange
    array.set(noiseBuf, noiseHead, absChange)
    noiseHead := (noiseHead + 1) % p

    // Update close buffer
    if na(array.get(closeBuf, closeHead))
        closeCount := math.min(closeCount + 1, p + 1)
    array.set(closeBuf, closeHead, current)

    // Get close from period bars ago
    int oldIdx = (closeHead - p + p + 1) % (p + 1)
    float oldClose = array.get(closeBuf, oldIdx)
    closeHead := (closeHead + 1) % (p + 1)

    prevVal := current

    // Signal = |close - close[period]|
    float signal = not na(oldClose) and closeCount > p ? math.abs(current - oldClose) : 0.0

    // ER = signal / noise (0 when noise is 0)
    float result = noiseSum != 0.0 ? signal / noiseSum : 0.0
    math.max(0.0, math.min(1.0, result))

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

// Inputs
i_source = input.source(close, "Source")
i_period = input.int(10, "Period", minval=1, maxval=500)

// Calculation
er_value = er(i_source, i_period)

// Plot
plot(er_value, "ER", color.new(color.yellow, 0), 2)
hline(0.5, "Midline", color=color.gray, linestyle=hline.style_dotted)

Overview

Efficiency Ratio (ER) compares the absolute net change over a lookback period with the sum of absolute bar-to-bar changes, then clamps the result between 0 and 1. Values near 1 mean directional movement and values near 0 mean choppy movement. Source and period control the series and lookback. It plots the ratio in a separate pane with a dotted midline at 0.5 and does not issue trade signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Oscillators & momentum

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
Sourcesourceclosei_source
Periodint10i_period
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

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

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of [RS]Standardized Trend Map

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
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

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