Back to TS code links
    Adaptive RVI 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 RVI 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),
Count(0),Length(0),Num(0),Denom(0),RVI(0),MaxRVI(0),MinRVI(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];
Length = intportion((4*Period+3*Period[1]+2*Period[3]+Period[4])/20);
Value1=((Close-Open)+2*(Close[1]-Open[1])+2*(Close[2]-Open[2])+(Close[3]-Open[3]))/6;
Value2=((High-Low)+2*(High[1]-Low[1])+2*(High[2]-Low[2])+(High[3]-Low[3]))/6;
Num = 0;
Denom = 0;
For Count = 0 to Length - 1 begin
Num = Num + Value1[count];
Denom = Denom + Value2[count]; End;
If Denom <> 0 then RVI = Num/Denom;
Plot1(RVI,"RVI",blue);
Plot2(RVI[1],"Trigger",green);

{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. }