Indicator · Pine Script v6 · On the chart

One Euro Filter

by mihakralj

This indicator plots an adaptive One Euro low-pass filter of a chosen price source on the chart.

View on GitHub

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

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

oneeuro.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("One Euro Filter (ONEEURO)", "ONEEURO", overlay=true)

//@function One Euro adaptive low-pass filter — trades jitter suppression
//     against responsiveness. At low signal speed, uses a low cutoff frequency
//     for heavy smoothing (reduces jitter). At high speed, raises the cutoff
//     to reduce lag. Only two meaningful parameters to tune.
//
//     Smoothing factor from cutoff frequency:
//       r = 2π · f_c · T_e
//       α = r / (r + 1)
//
//     Per-bar algorithm (T_e = 1.0 for uniform bar spacing):
//       1. dx   = x - x_prev                       (raw derivative)
//       2. d̂x  = α_d · dx + (1 - α_d) · d̂x_prev  (smoothed derivative)
//       3. f_c  = minCutoff + β · |d̂x|             (adaptive cutoff)
//       4. α    = smoothingFactor(f_c)
//       5. x̂   = α · x + (1 - α) · x̂_prev         (filtered output)
//
//     Reference: Casiez, Roussel & Vogel (2012), "1€ Filter: A Simple
//     Speed-Based Low-Pass Filter for Noisy Input in Interactive Systems,"
//     CHI '12, pp. 2527–2530. DOI: 10.1145/2207676.2208639
//
//@param src       Input series
//@param minCutoff Minimum cutoff frequency. Lower = smoother at low speed.
//@param beta      Speed coefficient. Higher = faster response to rapid moves.
//@param dCutoff   Cutoff frequency for the derivative estimator.
//@returns Filtered series (overlay, tracks price)
//@optimized O(1) per bar, O(1) memory — 4 state variables (x̂, d̂x, x_prev, init flag)
oneeuro(series float src, simple float minCutoff, simple float beta, simple float dCutoff) =>
    if minCutoff <= 0.0
        runtime.error("minCutoff must be > 0")
    if beta < 0.0
        runtime.error("beta must be >= 0")
    if dCutoff <= 0.0
        runtime.error("dCutoff must be > 0")

    var float xHat  = na
    var float dxHat = 0.0
    var float xPrev = na          // ← previous RAW input, not filtered output

    if bar_index == 0 or na(xHat)
        xHat  := nz(src, 0.0)
        xPrev := nz(src, 0.0)    // ← initialise alongside xHat
        dxHat := 0.0
    else
        // Derivative smoothing factor — constant, depends only on dCutoff
        float rD     = 2.0 * math.pi * dCutoff
        float alphaD = rD / (rD + 1.0)

        // Step 1-2: raw derivative from consecutive RAW inputs, then smooth it
        float dx = src - xPrev    // ← fix: raw-to-raw, no filter feedback
        dxHat   := alphaD * dx + (1.0 - alphaD) * dxHat

        // Step 3-5: adaptive cutoff driven by smoothed speed, then filter
        float fc    = minCutoff + beta * math.abs(dxHat)
        float rC    = 2.0 * math.pi * fc
        float alpha = rC / (rC + 1.0)
        xHat       := alpha * src + (1.0 - alpha) * xHat

        xPrev := src              // ← store raw input for next bar's derivative

    xHat


// ─── Inputs ───
i_source    = input.source(close, "Source")
i_minCutoff = input.float(1.0,   "Min Cutoff Frequency", minval=0.001, step=0.1,
                 tooltip="Controls jitter at low speed. Lower = smoother when price is stable.")
i_beta      = input.float(0.007, "Speed Coefficient (β)", minval=0.0, step=0.001,
                 tooltip="Controls lag at high speed. Higher = faster response to rapid moves.")
i_dCutoff   = input.float(1.0,   "Derivative Cutoff", minval=0.001, step=0.1,
                 tooltip="Cutoff frequency for the derivative (speed) estimator.")

// ─── Calculation ───
float filtered = oneeuro(i_source, i_minCutoff, i_beta, i_dCutoff)

// ─── Plot ───
plot(filtered, "OneEuro", color.new(color.yellow, 0), 2)

Overview

When movement is slow it uses a lower cutoff for heavier smoothing; when the smoothed derivative rises it raises the cutoff to reduce lag. Minimum cutoff, the speed coefficient, and derivative cutoff control that trade-off. It keeps a few state values and updates bar by bar. It is not a strategy and does not define entries, exits, or a stop loss.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

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
Min Cutoff Frequencyfloat1.0i_minCutoff
Speed Coefficient (β)float0.007i_beta
Derivative Cutofffloat1.0i_dCutoff
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

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
575 stars

The indicator plots ICT displacement candles on the price chart and can switch to retracement scanning. Displacement requires a move larger than a set share of the 14-bar average high-low range, lasting at least a chosen number of bars, with optional close, pr

Indicator v6 SMC / ICT / price actionCandlestick patterns
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Displacement Candles Indicator
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

1833 Tracker

by Allen1212
303 stars

1833 Tracker is an overlay indicator that visualizes historical buy and sell transactions executed by ARK Invest ETFs for the stock on the main price chart. It displays trade dates using green buy and red sell labels positioned relative to price bars, indicati

Indicator v4
Updated 2 years ago · None stated GitHub repository of 1833 Tracker

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