Back to TS code links
Adaptive Cyber Cycle indicator from John Ehlers
Back to Ehlers links


Anyone using information or codes on these pages does so at their own risk - no guarantees of stability or profitability are claimed. These codes are all for testing purposes only.

{Adaptive Cyber Cycle indicator - //// From 'Cybernetic Analysis for Stocks and Futures' by John Ehlers //// code compiled by dn
} // plot on a subgraph separate from the price region

Inputs: Price((H+L)/2), alpha(.07);
Vars: Smooth(0),Cycle(0),Q1(0),I1(0),DeltaPhase(0),MedianDelta(0),DC(0),InstPeriod(0),Period(0),
Length(0),Num(0),Denom(0),alpha1(0),AdaptCycle(0);

Smooth = (Price + 2*Price[1] + 2*Price[2] + Price[3])/6;

Cycle = (1 - .5*alpha)*(1 - .5*alpha)*(Smooth - 2*Smooth[1] + Smooth[2]) + 2*(1-alpha)*Cycle[1] - (1 - alpha)*(1-alpha)*Cycle[2];
If currentbar < 7 then Cycle = (Price - 2*Price[1] + Price[2])/4;
Q1 = (.0962*Cycle + .5769*Cycle[2] - .5769*Cycle[4] - .0962*Cycle[6])*(.5+.08*InstPeriod[1]);
I1 = Cycle[3];
If Q1 <> 0 and Q1[1] <> 0 then DeltaPhase = (I1/Q1 - I1[1]/Q1[1]) / (1 + I1*I1[1]/(Q1*Q1[1]));
If DeltaPhase < 0.1 then DeltaPhase = 0.1;
If DeltaPhase > 1.1 then DeltaPhase = 1.1;
MedianDelta = Median(DeltaPhase,5);
If MedianDelta = 0 then DC = 15 else DC = 6.28318 / MedianDelta + .5;
InstPeriod = .33*DC + .67*Instperiod[1];
Period = .15*InstPeriod + .85*Period[1];

alpha1 = 2/(Period + 1);
AdaptCycle=(1-.5*alpha1)*(1-.5*alpha)*(Smooth-2*Smooth[1]+Smooth[2])+2*(1-alpha1)*AdaptCycle[1]-(1-alpha1)*(1-alpha1)*AdaptCycle[2];
If currentbar <7 then AdaptCycle=(Price-2*Price[1]+Price[2])/4;
Plot1(AdaptCycle,"AdaptCycle",blue);
Plot2(AdaptCycle[1],"Trigger",green);
//PlotN(Expression[,"<PlotName>"[,ForeColor[,Default[,Width]]]]);

{Note: Adaptive indicators all use the measured dominant cycle
Adaptive CyberCycle, Center of Gravity (CG), and RVI all yeild similar results
but are more responsive than their static (non-adaptive) counterparts. }

{Adaptive Cyber Cycle Oscillator
From the book 'Cybernetic Analysis for Stocks and Futures' by John Ehlers
compiled by mmillar, July 2004
Price - the current price - only used by the Cycle Period measurement, not the Cyber Cycle calculation (except for the first few bars)
Length - used by both the Cyber Cycle calculation and the Cycle Period measurement -
John Ehlers uses alpha but I have replaced it with the more intuitive Length, where alpha=2/(Length+1)}
{
Inputs: Price((H+L)/2), Length(19);
Vars: oResult1(0), oResult2(0);
value1=_Oscillators(11, Price, Length, 0, 1, 0, 1, oResult1, oResult2);
Plot1(oResult1, "AdaptCyber");
Plot2(oResult2, "Trigger");
}