WiseTrader Toolbox

HilbertOscillator

Background

The Hilbert oscillator is John Ehlers' cycle-based oscillator (from Rocket Science for Traders). It recovers the in-phase and quadrature components of the market's cycle and turns them into a smooth oscillator that you can read like an RSI or stochastic — but because it is matched to the measured dominant cycle, it leads those conventional oscillators and stays in step with the market's actual rhythm.

The function produces two curves: a lead line and a lag line. They swing together with the cycle, and the crossing of the lead over the lag (and back) marks the turning points of the cycle — a clean, low-lag timing signal in cyclic markets. Because this version is engine-aware, you can pick which estimator measures the cycle; see Cycle Engines.

Included formula

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

It plots the lead line, with the lag line as an option, in its own pane; the crossing of the lead over the lag marks the cycle's turning points. 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.

HilbertOscillator(Engine = 0, Alpha = 0.07)
ParameterDescription
Engine Optional. Which cycle estimator to use: 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 oscillator is computed on the average of the current symbol's High and Low, so you do not pass a price array. It does not return an array directly — instead it writes two AFL variables: HilbertLead_Array (the lead line) and HilbertLag_Array (the lag line).

Usage

HilbertOscillator();                 // engine 0 (Homodyne) by default
lead = HilbertLead_Array;
lag  = HilbertLag_Array;

Plot( lead, "Hilbert Lead", colorRed );
Plot( lag,  "Hilbert Lag",  colorBlue );

// Turning-point signals
Buy  = Cross( lead, lag );
Sell = Cross( lag, lead );
Warning

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