WiseTrader Toolbox

SineWave

Background

The Sine Wave indicator is John Ehlers' cycle-phase display (from Rocket Science for Traders). It works out where the market currently sits within its dominant cycle — the phase — and plots a smooth sine of that phase. Alongside it, a second curve (the lead sine) is the same wave advanced by 45°. Because the two waves track the cycle's phase rather than its price, they keep a steady rhythm during a cycling market and the crossing of the lead over the main sine signals the cycle's turning points roughly an eighth of a cycle early.

The big practical advantage of the Sine Wave is what it does not do: it does not give the false, repeated crossover signals that ordinary oscillators throw off in a trend. When the market stops cycling and starts trending, the two sine lines run roughly parallel and stop crossing, which itself is a useful "no cycle / trend mode" tell. Because this version is engine-aware, you can choose which estimator measures the cycle; see Cycle Engines.

Included formula

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

It plots the sine and lead-sine lines together in their own pane, where their crossings flag 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. A companion Sine Wave DC formula plots the same pair driven from the dominant-cycle reading.

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.

SineWave(Price, Engine = 0, Alpha = 0.07)
ParameterDescription
Price The price array the cycle phase is calculated on. It must not contain empty/null values at the left edge of the data.
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

SineWave does not return an array directly. It writes two AFL variables you read afterwards: Sine_Array (the main sine) and LeadSine_Array (the lead sine, advanced 45°).

Usage

SineWave( Close );                   // engine 0 (Homodyne) by default
sine     = Sine_Array;
leadSine = LeadSine_Array;

Plot( sine,     "Sine",      colorRed );
Plot( leadSine, "Lead Sine", colorBlue );

// Cycle turning-point signals
Buy  = Cross( leadSine, sine );
Sell = Cross( sine, leadSine );
Tip

When the two sine lines stop crossing and run side by side, the market has likely switched from cycling to trending — a good moment to lean on a trend tool such as InstantTrendline instead of cycle signals.