Back to TS code links
    Smoothed Adaptive Momentum 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.

{Smoothed Adaptive Momentum 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), Cutoff(8);
Vars: Smooth(0),Cycle(0),Q1(0),I1(0),DeltaPhase(0),MedianDelta(0),DC(0),InstPeriod(0),Period(0),
Num(0),Denom(0),a1(0),b1(0),c1(0),coef1(0),coef2(0),coef3(0),coef4(0),Filt3(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];
Value1 = Price-Price[IntPortion(Period-1)];
a1=expvalue(-3.14159/Cutoff);
b1=2*a1*Cosine(1.738*189/Cutoff);
c1=a1*a1;
coef2=b1+c1;
coef3=-(c1+b1*c1);coef4=c1*c1;
coef1=1-coef2-coef3-coef4;
Filt3=coef1*Value1+coef2*Filt3[1]+coef3*Filt3[2]+coef4*Filt3[3];
If CurrentBar<4 then Filt3 = Value1;
Plot1 (Filt3,"Filt3",Blue); Plot2(0,"Ref",Yellow);