Welcome to the Traders Laboratory Forums.
Trading Indicators Post your custom trading indicators. If you download, remember to click INSTALL.

Reply
Adaptive CCI Details »»
Adaptive CCI
Platform: EasyLanguage, by Tams Tams is offline
Developer Last Online: May 2012 Show Printable Version Email this Page

Platform: Tradestation Rating:
Released: 02-28-2009 Last Update: Never Installs: 3
 
No support by the author.

Code:
{Adaptive CCI
From the book 'Rocket Science for Traders' by John Ehlers
modified with new cycle measurement method from 'Cybernetic Analysis for Stocks and Futures'
 
mmillar, July 2004
 
Price   - the current price - only used by the Cycle Period measurement, not by the CCI calculation
Length   - used by the Cycle Period measurement - John Ehlers uses alpha but I have replaced it with the more intuitive Length, where alpha=2/(Length+1)
CycPart - allows you to change how much of the cycle period should be used in the CCI calculation - usually 1
 
}
 
Inputs:   Price((H+L)/2), Length(19), CycPart(1);
 
Vars:   oResult1(0), oResult2(0);
 
value1=_Oscillators(18, Price, Length, CycPart, 1, 0, 1, oResult1, oResult2);
 
Plot1(oResult1, "AdaptCCI");
_Oscillators function:
Code:
{A collection of oscillators by John Ehlers
by mmillar, July 2004
 
1-15 are taken from 'Cybernetic Analysis for Stocks and Futures'
16-18 are taken from 'Rocket Science for Traders' and updated using a new cycle period measurement method
 
This function calls the function '_CyclePeriod' to calculate the Dominant Cycle for use in adaptive strategies
 
 
Oscillator Types
   1 - Cyber Cycle
   2 - CG Oscillator
   3 - Relative Vigor Index (RVI)
   4 - Stochastic RSI
   5 - Stochastic Cyber Cycle
   6 - Stochastic CG
   7 - Stochastic RVI
   8 - Fisher Cyber Cycle
   9 - Fisher CG
   10 - Fisher RVI
   11 - Adaptive Cyber Cycle
   12 - Adaptive CG
   13 - Adaptive RVI
   14 - Sinewave Indicator
   15 - Laguerre RSI
   16 - Adaptive RSI
   17 - Adaptive Stochastic
   18 - Adaptive CCI
 
This function is called with
   OscType - one of the above
   Price   - some indicators can use a price input e.g. (H+L)/2, Close etc, otherwise this can be set to 0
   Length   - the length or period that you wish to measure.  In some instances John Ehlers uses 'alpha' as his
           input but I have standardised all inputs using Length and then converted, where necessary, with
           alpha=2/(Length+1)
   Length2   - this is a catch all used when an additional input variable is needed (just because everything is done in one function)
   RSILength, StocLength, WMALength - only used by Stochastic RSI (OscType=4)
   oResult1, oResult2 - are the results returned by the function
}
 
 
Inputs:   OscType(Numeric), Price(Numeric), Length(Numeric), Length2(Numeric),   {general inputs}
      RSILength(Numeric), StocLength(Numeric), WMALength(Numeric),          {only used by OscType=4}
      oResult1(NumericRef), oResult2(NumericRef);                         {results to return}
 
Vars:   alpha(0), 
      count(0), Num(0), Denom(0),
      Smooth(0), Cycle(0),             {for OscType=1, 5, 8, 11}
      CG(0),                        {for OscType=2, 6, 9, 12}
      RVI(0),                        {for OscType=3, 7, 10, 13}
      MaxVal(0), MinVal(0),            {for OscType=5-10}
      Period(0),                     {for OscType=11-18}
      Cycle1(0),                      {for OscType=11-18 but only used in 14}
      Smooth1(0),                     {for OscType=11-18 but only used in 11}
      DCPeriod(0), RealPart(0), ImagPart(0), DCPhase(0),   {for OscType=14}
      L0(0), L1(0), L2(0), L3(0),       {for OscType=15}
      vRSI(0), CU(0), CD(0),             {for OscType=15, 16}
      vStoch(0), HH(0), LL(0),          {for OscType=17}
      vCCI(0), Avg(0), MD(0), MPrice(0);   {for OscType=18}
 
If ( OscType=1 ) then Begin {Cyber Cycle}
   alpha=2/(Length+1);
   Smooth=(Price+2*Price[1]+2*Price[2]+Price[3])/6;
   Cycle=(1-0.5*alpha)*(1-0.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;
 
   oResult1=Cycle;
   oResult2=Cycle[1];
end
else If ( OscType=2 ) then Begin {CG Oscillator}
   Num=0;
   Denom=0;
   For count=0 to Length-1 Begin
      Num=Num+(1+count)*Price[count];
      Denom=Denom+Price[count];
   end;
   If Denom<>0 then CG=-Num/Denom+(Length+1)/2;
 
   oResult1=CG;
   oResult2=CG[1];
end
else If ( OscType=3 ) then Begin {Relative Vigor Index}
   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;
 
   oResult1=RVI;
   oResult2=RVI[1];
end
else If ( OscType=4 ) then Begin {Stochastic RSI}
   Value1=RSI(Close, RSILength)-Lowest(RSI(Close, RSILength), StocLength);
   Value2=Highest(RSI(Close, RSILength), StocLength)-Lowest(RSI(Close, RSILength), StocLength);
   If Value2<>0 then Value3=Value1/Value2;
   Value4=2*(WAverage(Value3, WMALength)-0.5);
 
   oResult1=Value4;
   oResult2=Value4[1];
end
else If ( OscType=5 ) then Begin {Stochastic Cyber Cycle}
   alpha=2/(Length+1);
   Smooth=(Price+2*Price[1]+2*Price[2]+Price[3])/6;
   Cycle=(1-0.5*alpha)*(1-0.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;
 
   MaxVal=Highest(Cycle, StocLength);
   MinVal=Lowest(Cycle, StocLength);
   If MaxVal<>MinVal then Value1=(Cycle-MinVal)/(MaxVal-MinVal);
   Value2=(4*Value1+3*Value1[1]+2*Value1[2]+Value1[3])/10;
   Value2=2*(Value2-0.5);
 
   oResult1=Value2;
   oResult2=0.96*(Value2[1]+0.02);
end
else If ( OscType=6 ) then Begin {Stochastic CG}
   Num=0;
   Denom=0;
   For count=0 to Length-1 Begin
      Num=Num+(1+count)*Price[count];
      Denom=Denom+Price[count];
   end;
   If Denom<>0 then CG=-Num/Denom+(Length+1)/2;
 
   MaxVal=Highest(CG, Length);
   MinVal=Lowest(CG, Length);
      If MaxVal<>MinVal then Value1=(CG-MinVal)/(MaxVal-MinVal);
   Value2=(4*Value1+3*Value1[1]+2*Value1[2]+Value1[3])/10;
   Value2=2*(Value2-0.5);
 
   oResult1=Value2;
   oResult2=0.96*(Value2[1]+0.02);
end
else If ( OscType=7 ) then Begin {Stochastic RVI}
   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;
 
   MaxVal=Highest(RVI, Length);
   MinVal=Lowest(RVI, Length);
   If MaxVal<>MinVal then Value3=(RVI-MinVal)/(MaxVal-MinVal);
   Value4=(4*Value3+3*Value3[1]+2*Value3[2]+Value3[3])/10;
   Value4=2*(Value4-0.5);
 
   oResult1=Value4;
   oResult2=0.96*(Value4[1]+0.02);
end
else If ( OscType=8 ) then Begin {Fisher Cyber Cycle}
   alpha=2/(Length+1);
   Smooth=(Price+2*Price[1]+2*Price[2]+Price[3])/6;
   Cycle=(1-0.5*alpha)*(1-0.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;
 
   MaxVal=Highest(Cycle, Length2);
   MinVal=Lowest(Cycle, Length2);
   If MaxVal<>MinVal then Value1=(Cycle-MinVal)/(MaxVal-MinVal);
   Value2=(4*Value1+3*Value1[1]+2*Value1[2]+Value1[3])/10;
   Value3=0.5*Log((1+1.98*(Value2-0.5))/(1-1.98*(Value2-0.5)));
 
   oResult1=Value3;
   oResult2=Value3[1];
end
else If ( OscType=9 ) then Begin {Fisher CG}
   Num=0;
   Denom=0;
   For count=0 to length-1 Begin
      Num=Num+(1+count)*(Price[count]);
      Denom=Denom+(Price[count]);
   end;
   If Denom<>0 then CG=-Num/Denom+(Length+1)/2;
 
   MaxVal=Highest(CG, Length);
   MinVal=Lowest(CG, Length);
   If MaxVal<>MinVal then Value1=(CG-MinVal)/(MaxVal-MinVal);
   Value2=(4*Value1+3*Value1[1]+2*Value1[2]+Value1[3])/10;
   Value3=0.5*Log((1+1.98*(Value2-0.5))/(1-1.98*(Value2-0.5)));
 
   oResult1=Value3;
   oResult2=Value3[1];
end
else If ( OscType=10 ) then Begin {Fisher RVI}
   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;
 
   MaxVal=Highest(RVI, Length);
   MinVal=Lowest(RVI, Length);
   If MaxVal<>MinVal then Value3=(RVI-MinVal)/(MaxVal-MinVal);
   Value4=(4*Value3+3*Value3[1]+2*Value3[2]+Value3[3])/10;
   Value5=0.5*Log((1+1.98*(Value4-0.5))/(1-1.98*(Value4-0.5)));
 
   oResult1=Value5;
   oResult2=Value5[1];
end
else If ( OscType=11 ) then Begin {Adaptive Cyber Cycle}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
 
   alpha=2/(Period+1);
   Cycle=(1-0.5*alpha)*(1-0.5*alpha)*(Smooth1-2*Smooth1[1]+Smooth1[2])+2*(1-alpha)*Cycle[1]-(1-alpha)*(1-alpha)*Cycle[2];
   If currentbar<7 then Cycle=(Price-2*Price[1]+Price[2])/4;
 
   oResult1=Cycle;
   oResult2=Cycle[1];
end
else If ( OscType=12 ) then Begin {Adaptive CG}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
   Value1=IntPortion(Period/2); {use half the cycle period}
 
   Num=0;
   Denom=0;
   For count=0 to Value1-1 Begin
      Num=Num+(1+count)*(Price[count]);
      Denom=Denom+(Price[count]);
   end;
   If Denom<>0 then CG=-Num/Denom+(Value1+1)/2;
 
   oResult1=CG;
   oResult2=CG[1];
end
else If ( OscType=13 ) then Begin {Adaptive RVI}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
   Value3=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 Value3-1 Begin
      Num=Num+Value1[count];
      Denom=Denom+Value2[count];
   end;
   If Denom<>0 then RVI=Num/Denom;
 
   oResult1=RVI;
   oResult2=RVI[1];
end
else If ( OscType=14 ) then Begin {Sinewave Indicator}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
 
   DCPeriod=IntPortion(Period);
   RealPart=0;
   ImagPart=0;
   For count=0 to DCPeriod-1 Begin
      RealPart=RealPart+Sine(360*count/DCPeriod)*(Cycle1[count]);
      ImagPart=ImagPart+Cosine(360*count/DCPeriod)*(Cycle1[count]);
   end;
   If AbsValue(ImagPart)>0.001 then DCPhase=Arctangent(RealPart/ImagPart);
   If AbsValue(ImagPart)<=0.001 then DCPhase=90*Sign(RealPart);
   DCPhase=DCPhase+90;
   If ImagPart<0 then DCPhase=DCPhase+180;
   If DCPhase>315 then DCPhase=DCPhase-360;
 
   oResult1=Sine(DCPhase);
   oResult2=Sine(DCPhase+45);
end
else If ( OscType=15 ) then Begin {Laguerre RSI}
   L0=(1-Length2)*Close+Length2*L0[1];
   L1=-Length2*L0+L0[1]+Length2*L1[1];
   L2=-Length2*L1+L1[1]+Length2*L2[1];
   L3=-Length2*L2+L2[1]+Length2*L3[1];
 
   CU=0;
   CD=0;
   If L0>=L1 then CU=L0-L1 else CD=L1-L0;
   If L1>=L2 then CU=CU+L1-L2 else CD=CD+L2-L1;
   If L2>=L3 then CU=CU+L2-L3 else CD=CD+L3-L2;
   If CU+CD<>0 then vRSI=CU/(CU+CD);
 
   oResult1=vRSI;
   oResult2=0;
end
else If ( OscType=16 ) then Begin {Adaptive RSI}   
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
 
   CU=0;
   CD=0;
   For count=0 to (Period*Length2)-1 Begin
      If Close[count]-Close[count+1]>0 then CU=CU+(Close[count]-Close[count+1]);
      If Close[count]-Close[count+1]<0 then CD=CD+(Close[count+1]-Close[count]);
   end;
   If CU+CD<>0 then vRSI=100*CU/(CU+CD);
 
   oResult1=vRSI;
   oResult2=0;
end
else If ( OscType=17 ) then Begin {Adaptive Stochastic}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
 
   HH=High;
   LL=Low;
   For count=0 to IntPortion(Period*Length2)-1 Begin
      If High[count]>HH then HH=High[count];
      If Low[count]<LL then LL=Low[count];
   end;
   If HH-LL<>0 then vStoch=(Close-LL)/(HH-LL);
 
   oResult1=vStoch;
   oResult2=0;
end
else If ( OscType=18 ) then Begin {Adaptive CCI}
   alpha=2/(Length+1);
   Period=_CyclePeriod(Price, alpha, Cycle1, Smooth1);
 
   Value1=IntPortion(Period*Length2);
   MPrice=(High+Low+Close)/3;
   Avg=0;
   For count=0 to Value1-1 Begin
      Avg=Avg+MPrice[count];
   end;
   If Value1<>0 then Avg=Avg/Value1;
   MD=0;
   For count=0 to Value1-1 Begin
      MD=MD+AbsValue(MPrice[count]-Avg);
   end;
   If Value1<>0 then MD=MD/Value1;
   If MD<>0 then vCCI=(MPrice-Avg)/(0.015*MD);
      
   oResult1=vCCI;
   oResult2=0;
end;
 
_Oscillators=1;
_cycleperiod function
Code:
{Cycle Period Measurement
From the book 'Cybernetic Analysis for Stocks and Futures' by John Ehlers
 
mmillar, July 2004
 
This function is called with 
   Price   - the current price, such as (H+L)/2 or Close
   alpha   - the alpha (which is related to the measurement period/length)
   oCycle   - a return variable that is needed by some indicators
}
 
 
Inputs:   Price(numeric), alpha(numeric), oCycle(numericref), oSmooth(numericref);
 
Vars:   Smooth(0), Cycle(0), Q1(0), I1(0), DC(0),
      DeltaPhase(0), MedianDelta(0), InstPeriod(0), Period(0);
 
Smooth=(Price+2*Price[1]+2*Price[2]+Price[3])/6;
Cycle=(1-0.5*alpha)*(1-0.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=(0.0962*Cycle+0.5769*Cycle[2]-0.5769*Cycle[4]-0.0962*Cycle[6])*(0.5+0.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+0.5;
InstPeriod=0.33*DC+0.67*InstPeriod[1];
Period=0.15*InstPeriod+0.85*Period[1];
 
oCycle=Cycle;
oSmooth=Smooth;
_CyclePeriod=Period;

Screenshots

Adaptive CCI-adaptive_cci.gif  

Show Your Support

  • If you like to thanks you by the author -> Click Thanks to the Author
  • This modification may not be copied, reproduced or published elsewhere without the author's permission.
The Following 2 Users Say Thank You to Tams For This Useful Post:
aaa (06-11-2009), strader2 (02-20-2010)

Comments
Old 03-01-2009, 06:45 PM   #2

Power555's Avatar

Join Date: Jun 2007
Location: ny
Posts: 30
Ignore this user

Thanks: 7
Thanked 7 Times in 7 Posts

Re: Adaptive CCI

Thanks for posting someone elses code from the tradestation Forum.
Power555 is offline  
Reply With Quote
Old 06-10-2009, 01:15 AM   #3

Join Date: Mar 2008
Location: Amsterdam
Posts: 2
Ignore this user

Thanks: 0
Thanked 0 Times in 0 Posts

Re: Adaptive CCI

I am looking for working Adaptive CCI indicators for MetaTrader4.
Can somebody help me?
Would be great!

Cheers,
Jazz
Jazz1964 is offline  
Reply With Quote
Old 06-10-2009, 03:02 AM   #4

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Adaptive CCI

Quote:
Originally Posted by Power555 »
Thanks for posting someone elses code from the tradestation Forum.
Lots of people (Multicharts users for example) don't have access to TS forums, so having an alternate source is handy.

Just one thing Tams, this looks like it's a lot more than just a CCI, dont know if you can change the thread title.
BlowFish is offline  
Reply With Quote
The Following User Says Thank You to BlowFish For This Useful Post:
Tams (03-19-2010)
Old 06-16-2009, 06:23 AM   #5

Join Date: Mar 2008
Location: Amsterdam
Posts: 2
Ignore this user

Thanks: 0
Thanked 0 Times in 0 Posts

Re: Adaptive CCI

Quote:
Originally Posted by Jazz1964 »
I am looking for working Adaptive CCI indicators for MetaTrader4.
Can somebody help me?
Would be great!

Cheers,
Jazz
Nobody have this adaptive CCI in Metatrader, or knows where to get it?

Best regards,
Jazz
Jazz1964 is offline  
Reply With Quote
Old 06-19-2009, 03:24 PM   #6
aaa

aaa's Avatar

Join Date: Jun 2008
Location: Switzerland
Posts: 443
Ignore this user

Thanks: 240
Thanked 283 Times in 136 Posts

Re: Adaptive CCI

Quote:
Originally Posted by Power555 »
Power555
Thanks for posting someone elses code from the tradestation Forum.
"And so my fellow Traders,

ask not what your website can do for you,

ask what you can do for your website

Inaugural address of John F. Kennedy - Wikipedia, the free encyclopedia
aaa is offline  
Reply With Quote
Old 06-19-2009, 03:42 PM   #7
aaa

aaa's Avatar

Join Date: Jun 2008
Location: Switzerland
Posts: 443
Ignore this user

Thanks: 240
Thanked 283 Times in 136 Posts

Re: Adaptive CCI

************************* *
Attached Files
File Type: eld ADAPTIVE CCI.ELD (19.3 KB, 106 views)
File Type: pla Adaptive CCI.pla (38.8 KB, 50 views)
aaa is offline  
Reply With Quote
The Following 2 Users Say Thank You to aaa For This Useful Post:
shrike (12-19-2009), Tams (07-06-2009)
Old 03-19-2010, 10:13 AM   #8

Join Date: Nov 2009
Location: kolkata
Posts: 3
Ignore this user

Thanks: 1
Thanked 0 Times in 0 Posts

Re: Adaptive CCI

looking for smothed adaptive cci
Attached Files
File Type: txt chart.txt (2 Bytes, 32 views)
apollo12 is offline  
Reply With Quote

Reply

Tags
cci, ehlers, oscillator, woodies

Thread Tools
Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adaptive Moving Average (AMA) metalhead Technical Analysis 38 07-03-2009 08:33 PM

All times are GMT -4. The time now is 07:58 AM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.