Kaufman's Efficiency Ratio (er)
Kaufman’s Efficiency Ratio (ER) compares the net displacement of a series with the full distance it traveled over the length period. When that period contains an uninterrupted run of defined values, the result lies between 0 and 1 and describes how direct the path was, independently of its direction.
A value near 1 means that successive changes formed an almost straight move. A value near 0 means that those changes largely canceled one another out, or that the series did not move. A steady rise and a steady decline can therefore produce the same high reading: ER measures the efficiency of the move, not its direction.
Block declaration
A strategy can contain multiple [[er]] blocks. Each block produces a numeric series identified by its id field.
The calculation uses close by default. Set source to use another price series or the output of another indicator.
Examples
Minimal setup
This block uses the default close source and the default length of 10.
[[er]]
id = "efficiency"Custom fixed setup
This block measures the efficiency of the hl2 source over 20 candles.
[[er]]
id = "efficiency"
source = "hl2"
length = 20Finding the optimal length
This block explores the lengths 5, 10, 15, 20, 25, and 30. Whale-E runs one grid combination for each value so you can compare their effect on the strategy’s results.
[[er]]
id = "efficiency"
length.start = 5
length.stop = 30
length.step = 5Efficiency filter with a threshold
This example uses ER to let the strategy continue only when the recent move is efficient enough. The [[constant]] block varies er_threshold from 0.3 to 0.7 during the grid search.
The condition becomes true when efficiency > er_threshold. A low threshold accepts choppier paths, while a high threshold keeps only the cleanest moves. Because ER does not indicate direction, this filter can trigger during either a rise or a decline.
[[er]]
id = "efficiency"
[[constant]]
id = "er_threshold"
start = 0.3
stop = 0.7
step = 0.1
[[condition]]
id = "directional_market"
condition = "efficiency > er_threshold"
next_block_id = "..."Dedicated symbol and timeframe
This block uses the four-hour closing prices from BINANCE:ETHUSDT, independently of the primary symbol and timeframe defined in [backtest]. See Exchanges, Symbols and Timeframes for accepted formats and alignment rules.
[[er]]
id = "efficiency_4h"
symbol = "BINANCE:ETHUSDT"
timeframe = "240"Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name identifying the ER series produced by the block. |
sourceString or Array Optional | Input series whose efficiency the block measures. Accepted forms: source = "hl2" or source = ["close", "hl2"].Each value can be a standard price source ( open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.If source is omitted, the default value is "close". |
lengthInteger Optional | Number of candles in the observation period; must be between 1 and 10000 when specified.A short value makes ER more responsive to recent changes. A higher value evaluates efficiency over a broader period. If length is omitted, the default value is 10.Usage: • Fixed: length = value• Grid search: – length.start = min_value– length.stop = max_value– length.step = value (optional, default 1) |
symbolString or Array Optional | Market symbol(s) used when source contains a standard price source.If source mixes standard prices and indicator identifiers, symbol applies only to combinations based on standard prices.If source contains only indicator identifiers, symbol is ignored.If symbol is omitted, the block inherits the primary symbol defined in [backtest].For accepted formats and alignment rules, see Exchanges, Symbols and Timeframes. |
timeframeString or Array Optional | Timeframe on which ER is computed. If timeframe is omitted, the calculation uses the grid’s primary timeframe defined in [backtest].For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes. |
Available variables
Use the identifiers below directly in your expressions. The ER block exposes its numeric series and length, together with its input source, symbol, and timeframe.
Assume the block is configured as follows:
[[er]]
id = "efficiency"Then:
| Variable | Description |
|---|---|
efficiency or efficiency[0]Decimal | Current ER value. |
efficiency[n]Decimal | ER value from n candles ago. |
efficiency.lengthDecimal | Length used by the ER series. |
efficiency.sourceString | Input series name. |
efficiency.symbolString | Market symbol used by the series. |
efficiency.timeframeString | Timeframe used by the series. |
Notes
- If the source contains
NaNvalues, the engine retains the most recent valid changes for the denominator. Once the current and lagged values are defined again, the output may exceed1. The0to1range is guaranteed only for a continuous window with no missing values. - Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality and inequality checks only.