OPEN-SOURCE SCRIPT
Triple Derivative Engine

Most momentum indicators tell you where the price is. The Triple Derivative Engine tells you how fast it's getting there, whether that speed is increasing or fading, and whether the acceleration itself is changing direction — three layers of motion analysis extracted from a single smoothed price signal, all normalized to a common ±100 scale so every layer is directly comparable at a glance.
How It Works
Step 1 — Smoothing
Raw price is too noisy to differentiate reliably. TDE first passes your source through one of three selectable filters to extract the underlying motion curve before computing any derivatives.
Step 2 — Finite Difference Derivatives
Once the smoothed signal sm is computed, three derivatives are calculated using standard finite difference formulas:
Step 3 — Normalization
Each derivative is divided by its rolling peak absolute value over the normalization lookback window, then scaled to ±100. This keeps all three series on the same axis and comparable to each other, regardless of the instrument's price level or volatility. A velocity reading of +80 and an acceleration reading of +80 carry equivalent relative meaning within their own histories.
Signals
Zero Crosses
Every time a derivative crosses the zero line, a marker appears at the top or bottom of the panel. Each derivative has a distinct shape to avoid confusion:
Each set of markers is independently gated by its visibility toggle, so you only see the crosses for the series you have enabled.
Divergence Markers (Triangles)
Divergence fires when acceleration crosses zero while velocity is still extreme — specifically when |vn| > 30. This combination means the move has been strong enough to be considered extended, but the underlying force driving it is already reversing.
Divergence markers are rarer than zero crosses by design. They represent a specific confluence, not a general crossover signal.
Regime Background
The panel background is tinted to reflect the current momentum regime:
The regime is also displayed in the info table with four states: ▲ Accelerating, ↗ Decelerating, ↘ Recovering, ▼ Falling.
Signal Line
An EMA of velocity (default length 9) is plotted as a thin white line over the velocity histogram. Velocity crossing its own signal line is an additional early entry cue, analogous to the MACD signal cross but applied directly to the derivative layer.
Settings
⏱ Timeframe
🔬 Smoothing Filter
📈 Derivatives & Display
🎨 Colors
All seven colour elements are individually configurable: Velocity (up/down), Acceleration (up/down), Jerk (up/down), and the Signal line.
Alerts
Eight alert conditions are available:
Reading the Indicator Together
The three layers are designed to be read in sequence, from slowest to fastest signal:
A high-confidence setup aligns all three: velocity positive, acceleration positive and rising, jerk positive. As a move matures, acceleration will peak and roll over first, while velocity remains elevated — that is the divergence condition. Velocity eventually follows. Jerk will often signal the peak of acceleration one step earlier still.
No single cross is a trade signal on its own. TDE is a momentum structure tool. It is most useful when combined with price structure, support/resistance levels, and a defined higher timeframe bias.
How It Works
Step 1 — Smoothing
Raw price is too noisy to differentiate reliably. TDE first passes your source through one of three selectable filters to extract the underlying motion curve before computing any derivatives.
- Savitzky-Golay (default) fits a 2nd-order polynomial to a moving window of bars using Gram polynomial coefficients. Unlike a moving average, it preserves the shape of peaks and troughs rather than smoothing them away. Window sizes of 5, 7, 9, 11, 13, and 15 are supported, each with exact integer coefficients — no approximation. This gives the best phase response of the three filters: signals appear earlier and with less distortion.
- Gaussian weights each past bar by a bell-curve function of its distance from the current bar. Sigma controls how quickly the weights fall off. Softer and more trailing than SG, useful when you want a cleaner curve at the cost of a slight lag.
- Kalman is a single-state recursive filter that continuously estimates the "true" price by balancing how much it trusts the new measurement (R) versus how much the underlying process is expected to move (Q). It adapts bar-to-bar, making it the most responsive of the three with the least lag, but also the most sensitive to sharp moves.
Step 2 — Finite Difference Derivatives
Once the smoothed signal sm is computed, three derivatives are calculated using standard finite difference formulas:
- Velocity (1st derivative): sm − sm[1] — the rate of change of price. Positive means price is rising, negative means it is falling. The magnitude tells you how fast.
- Acceleration (2nd derivative): sm − 2·sm[1] + sm[2] — the rate of change of velocity. Positive means momentum is building; negative means it is fading, even if price is still moving in the same direction.
- Jerk (3rd derivative): sm − 3·sm[1] + 3·sm[2] − sm[3] — the rate of change of acceleration. A leading indicator of acceleration reversals. When jerk crosses zero, acceleration is about to change direction.
Step 3 — Normalization
Each derivative is divided by its rolling peak absolute value over the normalization lookback window, then scaled to ±100. This keeps all three series on the same axis and comparable to each other, regardless of the instrument's price level or volatility. A velocity reading of +80 and an acceleration reading of +80 carry equivalent relative meaning within their own histories.
Signals
Zero Crosses
Every time a derivative crosses the zero line, a marker appears at the top or bottom of the panel. Each derivative has a distinct shape to avoid confusion:
- Velocity (Circle): Bottom (bullish) / Top (bearish)
- Acceleration (Diamond): Bottom (bullish) / Top (bearish)
- Jerk (Square): Bottom (bullish) / Top (bearish)
Each set of markers is independently gated by its visibility toggle, so you only see the crosses for the series you have enabled.
- Velocity cross — the most direct signal. When velocity crosses above zero, price momentum has turned positive on the source timeframe. Below zero, it has turned negative.
- Acceleration cross — a timing tool, not a trend signal. When acceleration crosses above zero while velocity is still positive, the move is re-accelerating. When acceleration crosses below zero while velocity is still positive, the move is losing steam — the trend continues, but is starting to exhaust. Acceleration reversals frequently precede velocity reversals by several bars.
- Jerk cross — the earliest signal in the chain. Jerk crossing zero means acceleration is about to change direction. By itself, jerk is noisy, but when it aligns with acceleration near a zero cross, it can give a meaningful early warning.
Divergence Markers (Triangles)
Divergence fires when acceleration crosses zero while velocity is still extreme — specifically when |vn| > 30. This combination means the move has been strong enough to be considered extended, but the underlying force driving it is already reversing.
- Bear divergence (▼ triangle, top): Acceleration crosses below zero while velocity is still elevated above +30. The upswing's engine is cutting out while the price is still high. Historically, this precedes deceleration into a stall or reversal.
- Bull divergence (▲ triangle, bottom): Acceleration crosses above zero while velocity is still depressed below −30. The downswing is losing power from the bottom. Historically, this precedes a deceleration of selling and a potential recovery.
Divergence markers are rarer than zero crosses by design. They represent a specific confluence, not a general crossover signal.
Regime Background
The panel background is tinted to reflect the current momentum regime:
- Velocity > 0 and Acceleration > 0: Accelerating bull - Cyan tint
- Velocity < 0 and Acceleration < 0: Accelerating bear - Red tint
- No tint: Decelerating or mixed - Neutral
The regime is also displayed in the info table with four states: ▲ Accelerating, ↗ Decelerating, ↘ Recovering, ▼ Falling.
Signal Line
An EMA of velocity (default length 9) is plotted as a thin white line over the velocity histogram. Velocity crossing its own signal line is an additional early entry cue, analogous to the MACD signal cross but applied directly to the derivative layer.
Settings
⏱ Timeframe
- Source Timeframe — the timeframe on which the smoothed signal is computed before derivatives are taken. Options: Auto, Chart, 5m, 15m, 1H, 4H, 1D, 1W.
- Auto scales to a fixed higher timeframe based on your current chart: below 5m → 15m, below 15m → 1H, below 1H → 4H, below 4H → 1D, otherwise 1W. This allows the indicator to show higher-timeframe derivative structure on any intraday chart without manual adjustment.
- The chart uses the same timeframe as the chart is on. Useful when you want the derivatives of the chart's own bars rather than a higher context.
🔬 Smoothing Filter
- Filter — selects the smoothing method: Savitzky-Golay (recommended), Gaussian, or Kalman.
- SG Window (SG only) — odd integer from 5 to 15. Controls the width of the polynomial fitting window. Larger windows produce smoother derivatives with (window−1)/2 additional bars of lag. Window 9 is the default and a good general-purpose choice. Use 5 or 7 for faster signals on volatile instruments; 13 or 15 for cleaner derivatives on smooth trends.
- Gaussian Length (Gaussian only) — number of bars in the weighted sum. Longer = smoother.
- Gaussian Sigma (Gaussian only) — controls the standard deviation of the bell curve. Lower values concentrate weight on recent bars; higher values spread it more evenly.
- Kalman Q — Process Noise (Kalman only) — how much the filter expects the price to move on its own each bar. Higher Q makes the filter track price more closely with less smoothing. Range 0.0001–1.0, default 0.01.
- Kalman R — Measurement Noise (Kalman only) — how much the filter distrusts the raw price measurement. Higher R produces more smoothing and more lag. Range 0.01–50.0, default 1.0.
📈 Derivatives & Display
- Price Source — the input series to smooth and differentiate. Defaults to close. Can be set to any source, including hl2, ohlc4, or another indicator's output via the source selector.
- Normalization Lookback — the rolling window (in bars) over which each derivative is scaled to ±100. Shorter windows (e.g., 50) make the indicator more responsive to recent extremes; longer windows (e.g., 200–500) provide a more stable baseline. Default 100.
- Signal EMA Length — the length of the EMA applied to normalized velocity to produce the signal line. Default 9.
- Velocity (1st deriv) — show/hide the velocity histogram and line, and its zero-crossing markers.
- Acceleration (2nd deriv) — show/hide the acceleration line and its zero-cross diamond markers.
- Jerk (3rd deriv) — show/hide the jerk line and its zero-crossing square markers. Hidden by default as it is primarily useful for advanced analysis.
- Signal Line on Velocity — show/hide the EMA signal line overlay on velocity.
- Divergence Markers — show/hide the bear/bull divergence triangle markers.
🎨 Colors
All seven colour elements are individually configurable: Velocity (up/down), Acceleration (up/down), Jerk (up/down), and the Signal line.
Alerts
Eight alert conditions are available:
- Velocity → Positive: Velocity crosses above zero
- Velocity → Negative: Velocity crosses below zero
- Momentum Trough: Acceleration crosses above zero
- Momentum Peak: Acceleration crosses below zero
- Jerk → Positive: Jerk crosses above zero
- Jerk → Negative: Jerk crosses below zero
- Bullish Divergence: Acceleration recovers while velocity is below −30
- Bearish Divergence: Acceleration rolls over while velocity is above +30
Reading the Indicator Together
The three layers are designed to be read in sequence, from slowest to fastest signal:
- Check velocity for trend direction — is the move positive or negative?
- Check acceleration for conviction — is the move building or fading?
- Check jerk for early warning — is acceleration about to change?
A high-confidence setup aligns all three: velocity positive, acceleration positive and rising, jerk positive. As a move matures, acceleration will peak and roll over first, while velocity remains elevated — that is the divergence condition. Velocity eventually follows. Jerk will often signal the peak of acceleration one step earlier still.
No single cross is a trade signal on its own. TDE is a momentum structure tool. It is most useful when combined with price structure, support/resistance levels, and a defined higher timeframe bias.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.