OPEN-SOURCE SCRIPT

Kaufman Efficiency Ratio Gate [NovaLens]

778
Kaufman Efficiency Ratio Gate is a regime classifier that separates trending markets from choppy ones. Instead of plotting a raw ratio and leaving you to interpret thresholds, it ranks the current Kaufman Efficiency Ratio within its own recent history and outputs a binary gate: trend-favorable or chop-dominant. Five timeframe-specific presets ship ready to use - pick the one matching your chart.


HOW IT WORKS

The Efficiency Ratio measures how much of price's total movement was directional over N bars:

ER = |Close - Close(N)| / Σ|Close(i) - Close(i-1)|

A value near 1.0 means price moved in a straight line - maximum efficiency. A value near 0 means price covered distance but went nowhere net - noise. Perry Kaufman introduced this in "Trading Systems and Methods" (1995) as the foundation for his Adaptive Moving Average.

Raw ER values are hard to threshold because what counts as "efficient" varies by asset and timeframe. This gate solves that with a three-stage pipeline:

Light EMA smoothing - removes single-bar noise from the raw ER without adding meaningful lag (Smoothing = 2 for most presets).

Percentile rank - ranks the smoothed ER within its own rolling window. A reading at the 70th percentile means the current efficiency is higher than 70% of recent history. This is what makes the gate self-normalizing. A "trending" efficiency ratio for Gold might sit at 0.45, while for a volatile altcoin it might be 0.25 - the gate adjusts automatically to each asset's own baseline, so you never need to guess at fixed thresholds.

Symmetric hysteresis - the gate opens when rank crosses above the median + Stability/2, and closes when rank drops below the median - Stability/2. This prevents flicker at the boundary. A small buffer (Stability = 2) is enough because KER is already a clean ratio.

Other regime tools approach this differently. ADX measures trend strength through smoothed directional movement - it tells you how strong a trend is, but its fixed scale means a reading of 25 carries different weight on different instruments. The Choppiness Index compresses ATR relative to the window's price range into a 0-100 scale - useful, but sensitive to window length and not inherently normalized. The Efficiency Ratio takes a more direct route: what fraction of total movement was net directional? And the percentile-rank layer on top makes that reading self-normalizing across any asset or timeframe - no manual threshold tuning required.

The result is a binary state: trend-favorable (gate open) or chop-dominant (gate closed).


HOW TO READ IT

Teal background / teal hero line - Gate open. The market's directional efficiency is above its recent median. Trend-following setups tend to perform better in this environment.

Amber background / amber hero line - Gate closed. Efficiency is below the median - price is moving but not going anywhere. Trend-following setups historically tend to underperform in this environment.

Bright teal (strong trend) - Smoothed KER is in the top 25% of its recent rank window. The trend is unusually clean - continuation setups tend to be cleaner in this state.

Bright amber (strong chop) - Smoothed KER is in the bottom 25%. Noise is dominant - even range-bound strategies may find fewer clean entries. Generally a low-opportunity environment.

The info panel (top-right) shows the current gate state, smoothed KER value, percentile rank, and a momentum readout (strengthening / weakening / stable) based on how the rank has moved over the last few bars.


HOW WE USE IT - REGIME FILTER

In systematic trading, the Efficiency Ratio often serves as one of the regime filters applied before a trend-following signal gets capital allocation. The idea is to confirm that the market is actually trending efficiently, not just moving.

When the gate is open (teal), directional efficiency is elevated. Pullback entries, breakout continuations, trend-following MA crosses - these setups tend to perform better because price is converting movement into net progress. When the gate closes (amber), the same setups historically tend to underperform. Price is volatile but going nowhere. In choppy regimes, trend-following systems generally struggle, and while mean reversion may be more favorable, it remains a harder environment to trade overall. Many systematic traders use this kind of regime awareness to reduce exposure or adjust position sizing rather than forcing directional bets.

The gate works well as a context overlay alongside other entry signals. It doesn't indicate which direction to trade, but it helps characterize whether the current environment is rewarding directional movement at all.

What the gate is NOT: a forward predictor. It classifies the recent past. A gate-open reading means efficiency has been high - it doesn't guarantee the next bar will trend. It's a filter, not a crystal ball.


OTHER APPLICATIONS

Entry filter - pair with any trend-following signal (MA cross, breakout, RSI) and add a gate-open condition. Filtering out chop regimes can help reduce whipsaw entries.

Multi-timeframe confirmation - checking the gate on a higher timeframe before entering on a lower one can add confidence. For example, a Daily gate-open reading alongside a 4H trend entry.

Regime-aware sizing - some traders scale position size with regime state, increasing exposure during gate-open periods and reducing it when the gate closes.

Alert-driven workflow - set alerts on gate open/close transitions and check your trend setups only when the gate fires.


SETTINGS

Preset (default: Daily) - Timeframe-specific parameter bundles. Select the one matching your chart resolution:

Weekly - KER 10, Smoothing 2, Rank Window 100, Stability 2. Long context window for position traders.

Daily - KER 8, Smoothing 2, Rank Window 50, Stability 2. The default. Works well on most daily charts.

8H - KER 8, Smoothing 2, Rank Window 50, Stability 2. Starting point same as Daily - validate on your own 8H charts.

4H - KER 14, Smoothing 2, Rank Window 30, Stability 2. Wider KER period compensates for noisier intraday data.

30m - KER 5, Smoothing 5, Rank Window 30, Stability 2. Short KER period with heavier smoothing for fast charts.

Custom - Drive the gate from the four inputs below.

KER Period - Lookback for the raw Efficiency Ratio. Shorter (5-8) reacts faster to regime changes. Longer (14-20) gives more stable readings but lags transitions.

Smoothing - EMA applied to the raw KER. Set to 1 for no smoothing. KER is self-normalizing by construction, so low values (1-5) are usually enough.

Rank Window - Rolling window for the percentile rank. Controls how much recent history defines "typical." Shorter windows adapt faster; longer windows give more stable context.

Stability - Hysteresis half-width around the 50th percentile. At 0, the gate flips the instant rank crosses the median. At higher values, the gate requires a stronger signal to switch state. Low values (2-5) work well since KER is already a clean signal.

Display toggles:

• Show Raw KER - thin white line showing the unsmoothed ratio

• Show Median - 50th-percentile reference line on the smoothed KER

• Show Background - teal/amber background wash (turn off if your workspace already signals the regime elsewhere)

• Show Info Panel - gate state, KER, rank, and momentum readout

• Light Theme - flips panel colours for light chart backgrounds


LIMITATIONS

Backward-looking - the gate classifies recent efficiency, not future direction. Regimes can shift faster than the rank window catches, especially around news events.

Directionless - both strong uptrends and strong downtrends produce gate-open readings. A separate directional indicator is needed to determine which side to trade.

Noise on thin instruments - short KER periods on low-volume assets can produce noisy readings even with smoothing.

History requirement - percentile rank needs sufficient data to be meaningful. The first ~50-100 bars on any chart (depending on preset) will have unstable rankings.


NOTES

• Based on Perry Kaufman's Efficiency Ratio from "Trading Systems and Methods" (1995)

• Cross-validated against our PyneCore Python reference implementation.

• Parameters were tuned on gold (XAUUSD) via the NovaLens research pipeline. The same presets generalize reasonably to other assets - though testing on your own instruments is always recommended.

• Regime palette: teal = trend-favorable, amber = chop-dominant. Not green/red - this is a state classifier, not a directional signal.

If you find a Custom parameter set that works well on a different instrument, the comments are a good place to share it.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。