TradingView indicator calculations

Ehlers Instantaneous Trendline: recursion, trigger and confirmation

The Ehlers Instantaneous Trendline combines three price samples with two previous trendline values. Its trigger is twice the current trendline minus its value two bars ago. This page implements the fixed-alpha ITrend formula from Cybernetic Analysis for Stocks and Futures, with explicit startup rules. The name does not mean every turn has zero delay: in the test sequence below, price falls one bar before the downward trigger crossing.

See the decision guide

Account for all five terms

Let P be the source price, I the trendline, a the fixed alpha and q = 1 − a. Brackets indicate previous bars. The recurrence is I = (a − a²/4)P + (a²/2)P[1] − (a − 3a²/4)P[2] + 2qI[1] − q²I[2]. Ehlers gives this formula in equation 2.9 and the indicator in Figure 3.4. The table evaluates each coefficient at a = 0.07.

  • These terms work together. The negative coefficients mean I need not lie between recent prices. It is not a weighted average with exclusively positive weights.
  • The three price coefficients sum to a², while the two state coefficients sum to 1 − a². With P and both states equal to 100, the next I remains 100. This is a useful constant-input check.
  • The default input is hl2 = (high + low)/2. Changing it to close changes the observations. This version holds alpha fixed; it does not estimate a dominant cycle or adapt alpha like MAMA.
  • Sierra Chart documents the same recurrence but accepts length n and maps it to a = 2/(n + 1). Alpha 0.07 corresponds algebraically to n ≈ 27.5714; rounding that to an integer changes the coefficient.
TermCoefficientRole in this recurrence
Current price P0.068775Introduces the newest observation.
Previous price P[1]0.002450Adds the one-bar input contribution.
Price two bars ago P[2]−0.066325Subtracts an older input contribution.
Previous trendline I[1]1.860000Carries the preceding recursive state.
Trendline two bars ago I[2]−0.864900Completes the second-order feedback.

Read the trigger as two-bar momentum

T = 2I − I[2] = I + (I − I[2]). Subtracting I from both sides gives T − I = I − I[2]. Therefore, a trigger crossing is a change in the sign of the trendline's two-bar change. The trigger extrapolates that change; it does not observe a future price.

  • A price crossing the trendline is a different rule. So is a one-bar slope reversal, I crossing I[1]. Neither reproduces trigger-versus-trend crossings.
  • If I rises exactly one unit per bar, T is two units above I. That separation can persist without any new up crossing. A later flat or reversing market breaks the extrapolation assumption.
ConditionExact meaning
T > II is above I[2]. This describes a state.
Up crossingT > I now, with T[1] ≤ I[1] on the preceding bar.
Down crossingT < I now, with T[1] ≥ I[1] on the preceding bar.
T = IThe two-bar change is zero; equality alone is not a crossing.

Declare where the recursion starts

The example numbers samples from zero. At indices 0 and 1, I equals P. At indices 2 through 5, I = (P + 2P[1] + P[2])/4. At index 6, it switches to the full recurrence. T is unavailable for the first two samples because I[2] does not exist. This is an explicit Pine startup convention, consistent with the t < 6 FIR branch documented by Sierra Chart once sufficient input history exists.

  • The first two direct-price values define behavior at the dataset boundary; do not assume every platform or public script chooses the same seeds. The book's CurrentBar count also depends on the host platform's available history.
  • A six-sample startup does not prove convergence. For the same subsequent input, a state difference satisfies e[n] = 2q e[n−1] − q²e[n−2], with solutions of the form (A + Bn)qⁿ. At alpha 0.07, q is 0.93.
  • The code permits alpha from 0.01 through 1 and defaults to 0.07. Alpha zero would retain seed error rather than letting it decay. Smaller positive alpha retains state differences longer; 100 bars is only a signal-gating default, not a convergence guarantee.
  • The script rejects missing source values instead of silently inserting zero. To compare scripts, match their source, alpha, start timestamp, startup branch and complete earlier history.

Reproduce a rise followed by an abrupt reversal

This artificial sequence uses P = 100 at indices 0 through 5, P = 110 at indices 6 through 11, then P = 100 from index 12 onward. Use alpha 0.07 and the startup convention above. Values below are rounded to six decimals after calculation; no market data or trading returns are involved.

  • At index 6: I = 0.068775×110 + 0.00245×100 − 0.066325×100 + 1.86×100 − 0.8649×100 = 100.68775. T = 2×100.68775 − 100 = 101.3755.
  • At index 12, price has already dropped by 10, yet I rises from 105.959693 to 106.008254 and T remains above I. The down crossing arrives at index 13. Bar-close confirmation fixes when to accept it; it cannot remove the filter's response delay.
  • The upward event at index 6 follows an input jump on that same bar. It does not establish that a trade could capture the move from 100 to 110.
IndexInput PTrend ITrigger TCrossing
4100100.000000100.000000None
5100100.000000100.000000None
6110100.687750101.375500Up
7110101.991465103.982930None
8110103.158290105.628830None
11110105.959693107.718384None
12100106.008254106.885250None
13100105.357564104.755435Down

Test trend, noise and bad seeds separately

A plausible-looking line is insufficient evidence of a correct or useful calculation. These independent synthetic inputs expose different failure modes under the same alpha 0.07 and startup rule.

  • For the four-bar sine, I at n = 1001 is about 100.003938 and T about 100.011813; at n = 1003 they are about 99.996062 and 99.988187. Small differences still satisfy exact crossing inequalities. A minimum-separation threshold would be an additional rule with different events.
  • For a constant input with correct states, both lines stay constant and no mathematical crossing occurs. Floating-point arithmetic can leave tiny residuals; compare numerical tests with a tolerance rather than treating machine precision as market significance.
  • The ramp can have negligible settled lag while the step response still overshoots and the reversal example still reacts late. A single zero-lag label cannot describe all input frequencies and transients.
Input or altered stateCalculated resultWhat it disproves
P[n] = 100 + nAt n = 1000, I ≈ 1100 and T ≈ 1102.A persistent trigger separation does not produce a new event on every rising bar.
100 for six samples, then 110 foreverI peaks near 111.354823 at n = 33.The filter can overshoot a price that has stopped rising.
P[n] = 100 + sin(2πn/4)After settling, up at n = 1001; down at n = 1003.Crossings can alternate every two bars in a series with no sustained trend.
Flat P = 100, but force I[4] = I[5] = 0The full recurrence produces I[6] = 0.49 instead of 100.Zero is not a neutral initial price state.

Run the Pine Script v6 audit

Paste this indicator into Pine Editor and enable the test-sequence input to reproduce the table. The Data Window exposes input, sample index, both lines and their difference. Fixture mode permits markers from index 6 and disables market alerts. On a market source, the First market signal index input gates markers and alert conditions while the recurrence continues from the first sample.

  • The lines update during an open bar because high, low or the selected source can change. Only markers and alert conditions require barstate.isconfirmed. Historical bars are already confirmed; a live bar becomes confirmed on its closing update.
  • Both ta.crossover and ta.crossunder run on every execution, before the gate. Create an alert explicitly and select Once Per Bar Close. After changing settings, recreate the alert to use the revised configuration.
  • This is a chart-timeframe indicator with no future references or higher-timeframe requests. It does not place orders. Confirmed signals still need explicit entry timing, exits, sizing and transaction costs before any strategy test.
Independent implementation of the public formula with declared seeds, a reproducible fixture and confirmed chart-bar crossing conditions.pine
//@version=6
indicator("Instantaneous Trendline calculation audit", overlay = true, precision = 6)
alpha = input.float(0.07, "Alpha", minval = 0.01, maxval = 1.0, step = 0.01)
source = input.source(hl2, "Market source")
useFixture = input.bool(false, "Use 100 / 110 / 100 test sequence")
warmup = input.int(100, "First market signal index", minval = 6)
n = bar_index
p = useFixture ? (n < 6 or n >= 12 ? 100.0 : 110.0) : source
if na(p)
    runtime.error("Use a continuous source without missing values.")
a2 = alpha * alpha
q = 1.0 - alpha
float trend = na
if n < 2
    trend := p
else if n < 6
    trend := (p + 2.0 * p[1] + p[2]) / 4.0
else
    trend := (alpha - a2 / 4.0) * p + a2 / 2.0 * p[1] - (alpha - 3.0 * a2 / 4.0) * p[2] + 2.0 * q * trend[1] - q * q * trend[2]
trigger = 2.0 * trend - trend[2]
crossUp = ta.crossover(trigger, trend)
crossDown = ta.crossunder(trigger, trend)
ready = n >= (useFixture ? 6 : warmup) and barstate.isconfirmed
plot(trend, "Trend", color = color.blue, linewidth = 2)
plot(trigger, "Trigger", color = color.orange)
plot(p, "Input", display = display.data_window)
plot(trigger - trend, "Trigger minus trend", display = display.data_window)
plot(n, "Sample index", display = display.data_window)
plotshape(ready and crossUp, "Confirmed up crossing", shape.triangleup, location.belowbar, color.green, size = size.tiny)
plotshape(ready and crossDown, "Confirmed down crossing", shape.triangledown, location.abovebar, color.red, size = size.tiny)
alertcondition(ready and crossUp and not useFixture, "Trigger crosses above trend", "Confirmed Instantaneous Trendline upward crossing")
alertcondition(ready and crossDown and not useFixture, "Trigger crosses below trend", "Confirmed Instantaneous Trendline downward crossing")

Ask Pineify to implement a checkable specification

Give the Pine Script AI Coding Agent the five-term recurrence, alpha range, hl2 input, exact startup indices and T = 2I − I[2]. Ask it to draft or review a Pine indicator with confirmed crossings, then supply the sequence table as a numerical acceptance check. Inspect the generated source and compare values in TradingView before using alerts.

  • Keep the formula version in the request. A Hilbert-transform trendline, an adaptive version or a smoothed signal-line variant can share similar names while producing different values.
  • Use the public algorithm or source you have permission to use. A successful syntax check establishes compilation diagnostics, not a match to protected code, predictive accuracy or trading returns.
Where Pineify fits

Pine Script AI Coding Agent

Draft or review the explicit ITrend recurrence and startup policy, then compare the generated indicator with a reproducible input sequence.

Draft an ITrend calculation

Frequently asked questions

Educational information, not investment advice. Synthetic calculations test indicator behavior and do not measure trading performance. Crossings, matched numerical values and successful syntax checks do not guarantee returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.