WiseTrader Toolbox

InstantTrendline

Background

The Instantaneous Trendline is John Ehlers' low-lag trend line (from Rocket Science for Traders). The idea is simple but powerful: if you average price over exactly one full dominant cycle, the up-and-down swings of that cycle cancel out and you are left with the underlying trend. Because the averaging window is matched to the measured cycle rather than to a fixed length, the trendline reacts quickly while still removing the cyclic noise.

Traders use it as a responsive trend filter and as a substitute for a moving average: price above the instant trendline suggests an up-trend, below it a down-trend, and the slope of the line itself indicates momentum. Because this version is engine-aware, you can choose which estimator measures the cycle that sets the averaging window — see Cycle Engines.

Included formula

The toolbox ships a ready-made Instant Trendline indicator, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Instant Trendline onto a price chart.

It plots the trendline over price and marks a buy where price crosses above the line and a sell where it crosses below, with optional signal arrows. The same formula can be run as an Exploration from the Analysis window to scan a watchlist for the latest signal. The colours are set from the indicator's parameters, and the engine that measures the cycle can be chosen there too — see Cycle Engines.

The exported function

If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.

InstantTrendline(Engine = 0, Alpha = 0.07)
ParameterDescription
Engine Optional. Which cycle estimator sets the averaging window: 0 Homodyne (default), 1 Ehlers alpha, 2 Autocorrelation/Mesa, 3 Burg, 4 Kalman, 5 Multitaper. Defaults to 0. See Cycle Engines.
Alpha Optional. Smoothing constant used only by engine 1. Must be greater than 0. Defaults to 0.07; ignored by every other engine.
Note

The trendline is always computed on the average of the High and Low of the current symbol, so you do not pass a price array — only the optional engine settings.

Returns a per-bar array holding the instantaneous trendline.

Usage

trend = InstantTrendline();          // engine 0 (Homodyne) by default
Plot( Close, "Price", colorDefault, styleCandle );
Plot( trend, "Instant Trendline", colorRed );

// Use it as a trend filter
upTrend = Close > trend;

To measure the cycle with a different engine, pass its code:

trend = InstantTrendline( 4 );       // Kalman engine, lowest lag
Plot( trend, "Instant Trendline (Kalman)", colorBlue );
Warning

An Engine outside 0–5, or Alpha of 0 or less with engine 1, returns an empty result. Spectral engines (2–5) need a long warm-up before producing values.