> *A ratchet that only moves down gradually: price can push it up instantly, but gravity pulls it back at an exponential pace — faster when far from zero, slower as it approaches.*
- **Similar:** [Decay](../decay/Decay.md) | **Trading note:** Exponential decay; faster initial fading than linear. Natural half-life model for signal importance.
- Validated against Tulip Indicators `ti_edecay` reference algorithm.
EDECAY implements the exponential decaying function. When price is above the decayed level, output snaps to price. When price falls below, the output decays exponentially by multiplying by `(period-1)/period` per bar, creating a ceiling that gradually descends. Unlike linear DECAY which subtracts a fixed amount, EDECAY's multiplicative factor produces a proportional decay rate.
## Historical Context
The exponential decay indicator originates from the Tulip Indicators library, a high-performance C library of technical indicators. It provides a peak-tracking mechanism where the tracked level decays at a proportional rate. The indicator is useful for:
- **Trailing stops**: The decaying level acts as a trailing stop that descends proportionally.
- **Peak detection**: Identifies when price last reached a new high relative to the decay rate.
- **Signal filtering**: Removes noise by requiring price to exceed the decayed level to register as significant.
## Architecture & Physics
### 1. Pure IIR (No Buffer)
The indicator requires no history buffer — only the previous output value is needed:
$$
\text{state} = \{y_{t-1}\}
$$
This makes it O(1) in both time and space.
### 2. Exponential Decay Calculation
$$
y_t = \max(x_t, \; y_{t-1} \cdot \frac{p-1}{p})
$$
where:
- $x_t$ = current input value
- $y_{t-1}$ = previous output value
- $p$ = period parameter
- $\frac{p-1}{p}$ = multiplicative decay factor per bar
### 3. First Bar Initialization
$$
y_0 = x_0
$$
The first bar simply passes through the input value.
### 4. State Management
The indicator uses state rollback for bar correction:
```
if isNew:
save current state as previous
else:
restore previous state
```
## Mathematical Foundation
### Core Formula
$$
y_t = \max(x_t, \; y_{t-1} \cdot s)
$$
where $s = \frac{p-1}{p}$ is the multiplicative decay factor.
### Decay Behavior
After a peak at value $v$, with no new inputs exceeding the decayed level, the output follows:
$$
y_{t+k} = v \cdot s^k = v \cdot \left(\frac{p-1}{p}\right)^k
$$
The output asymptotically approaches zero but never reaches it ($v > 0$).
1.**Not a moving average**: Edecay is a peak-tracking/envelope indicator, not a smoothing filter. It only descends when price is below the decayed level.
2.**Proportional decay rate**: Unlike linear DECAY, EDECAY decays proportionally. For a stock at $100 with period=5, the first bar decays by $20; for a stock at $10, it decays by $2. This makes EDECAY scale-invariant.
3.**Period interpretation**: Period=5 means `scale = 4/5 = 0.8`, so each bar retains 80% of the previous value. After 5 bars, approximately 32.8% of the peak value remains.
4.**First bar**: The first bar always equals the input — there is no warmup period in the traditional sense.
5.**Asymmetric behavior**: Upward moves are instant (output = input), but downward moves are rate-limited to multiplication by `(period-1)/period` per bar.
6.**Never reaches zero**: Unlike linear DECAY, exponential decay asymptotically approaches zero but never reaches it (assuming positive values).