DominantCycle
Background
Almost every adaptive technique starts with the same question: how long is the market's current swing? The dominant cycle is the answer — the number of bars the price is cycling over right now. Knowing it lets you set indicator lengths automatically instead of guessing a fixed period, so an RSI, stochastic or moving average can stretch in slow markets and tighten in fast ones.
DominantCycle returns that period as a per-bar array. What makes it
flexible is the optional Engine argument: the same function can measure the
cycle several different ways, from the low-lag Homodyne default to a sharp Burg spectrum
or a fast-adapting Kalman tracker. See Cycle Engines
for a full description of each engine and when to use it.
Function
DominantCycle(Price, Engine = 0, Alpha = 0.07)
| Parameter | Description |
|---|---|
| Price | The price array the dominant-cycle period is measured from. 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
(Ehlers alpha). A smaller value gives a smoother, slower period; a larger value
reacts faster. Must be greater than 0. Defaults to 0.07. Ignored by
every other engine. |
Returns a per-bar array of the dominant-cycle period in bars. The spectral engines (2–5) leave a long warm-up region at the start of the data empty.
Usage
The classic use is driving an adaptive indicator:
periods = DominantCycle( Close ); // engine 0 (Homodyne) by default
myRSI = VariablePeriodRSI( Close, periods );
Plot( myRSI, "Adaptive RSI", colorRed );
To use a different estimator, pass the engine code. Only engine 1 reads
Alpha:
burgCycle = DominantCycle( Close, 3 ); // Burg, sharpest resolution
ehlersDC = DominantCycle( Close, 1, 0.05 ); // Ehlers alpha, smoother
Plot( burgCycle, "Burg cycle", colorBlue );
An Engine outside the range 0–5, or an Alpha of 0 or
less when using engine 1, produces an empty result. The spectral engines also need
plenty of warm-up history (roughly 50–100 bars) before they return values.