This first thing to be done in trying to make the CCI a better indicator is to go to the second line of the code (please refer to previous article for code) and understand what the simple moving average is there for. I’m not going to get into how a moving average is calculated as that’s usually the first chapter in any book on technical analysis, and there are plenty of resources on the internet. However, most discussions on moving averages don’t discuss what a moving average really does, other than to say you buy when prices cross over it, or buy when two moving averages cross over each other. I think that’s incorrect. I view a moving average as a filter. To me the purpose is to filter out the noise of the market, and to pass through the trend. Admittedly there can be many cycles at play at any given time. Filtering the noise can mean different things to different traders; from filtering out the minor noise leaving a short-term trend, to filtering out all the little cycles and leaving only the longest trend. I plan to delve into cycles and moving average filtering in more detail in a later article, but I need to touch on the subject here only briefly because it is key to turning the CCI from a so so indicator to a really good indicator. Moving averages in general are more successfully employed in trading when used as support and resistance, rather than for crossovers. Sort of like a moving or live trend line. You of course want to be on the correct side of the trend, but pullbacks to the trend and then trend resumption are far more profitable, in my opinion, than trading crossovers. Trading pullbacks is the theory of the zero line reject, discussed in the previous article, as well as Linda Raschke’s grail trade, and many other pullback-within-trend approaches.

The CCI was designed with the simple moving average (right there in the second line of the code) as a filter to pass the trend on to the rest of the formula so the mean deviation could be calculated based on this filtered result. I recall very early software packages having a 30 period CCI, but more common today is the 20 period. Most technicians believe that the ideal parameter for the CCI to be the length of one full cycle. A cycle is usually defined as the number of bars from low to low. If you measure from high to high there is not as much accuracy as there is usually translation of the tops of the cycles either left or right depending on the trend direction. Most momentum oscillators use a half cycle length as the input parameter. Since the CCI uses a moving average up front, a full cycle would be better to filter out the noise. There are some references on the internet that suggest Lambert originally intended the use of 1/3 of a cycle. I attended many seminars in the early 1980’s with much discussion on the relatively new CCI, and the full cycle length was universally accepted. I think the discrepancy is due to the fact that Lambert designed the CCI on a hand calculator without the means to test using a PC and trading software, which became available later. I think some of the contradictions on the internet are referencing his earliest writing. His idea of trading breakouts of the 100 lines, which was his original intent, would not be logical with a very short parameter. Once he could plot and test his results he would realize that the CCI would not stay long enough beyond the 100 lines to get the results he intended. But his original idea does become viable with a longer parameter. Since Lambert’s original idea tested out so poorly most traders began to use the indicator in an entirely different way than what was originally intended. Most traders seemed to use if for divergences, and for strategies involving re-entering the 100 lines, instead of breakouts beyond them. The 20 period lookback period became default in most software packages since most traders in the early days of trading software tested on daily data, and many would assume a 20 or 21 day cycle, as that is the number of trading days in a calendar. Of course cycles expand and contract, and don’t pay much attention to the calendar. The common use today in most chat rooms is to use a 14 period CCI, at least on intraday data. In my opinion, if you trade on a 14 period CCI you are trading mostly on noise. Sometimes the signals will work, but it is mostly by random chance if they do. Sometimes the cycles tighten up to be only 14 bars in length, but then the market is in chop and you probably shouldn’t be trading it unless you have a very short term scalping method.

Refer to the chart above. The blue line under the price bars represents an estimate of what the cycle is based on a formula that attempts to extract the dominant cycle that is developing. It gives a very rough estimate of the developing cycle. It is not exact. A more accurate cycle measure would probably be a fast fourier transform, but that method is useless for trading as it takes many cycles before an estimate can be had, and by then the cycle will certainly have changed. The best we can do is get in the ballpark. There are many formulas to try to determine the cycle period. John Ehlers has done much excellent work in this area and I have a link to his website on my resources tab, as well as reference to a couple of his books on my book tab. Many of his formulas are written out on either his web site or in his books, and probably elsewhere on the internet. The formula I’m using in the above chart is from one of his earlier attempts.

Here is another example. This chart I will use for the rest of the examples below.

In the above chart you can see a reference line at the bottom drawn at the 14 level. There is only one instance on this chart where this formula determined the cycle period to be as short as 14 bars. You can see it on the left side of the chart, and if you look up to the price bars you see the market is in chop for the moment. As prices come out of chop and start to descend you see the cycle period increasing. At that point in the price action the formula doesn’t know prices will stop and reverse, thus introducing a cycle component based on the new pivot. In this case cycle period quickly reverses and returns to a more normal 30 or so. Had prices continued to drop the cycle period would have stayed high. Actually the cycle component would be removed entirely if prices kept going, so it’s best to put a maximum and minimum value into the formula. You can see as prices start to make an impulse move the cycle extends to a longer period, and as prices lose direction and flatten or reverse the cycle period shortens.

The above chart shows the prices bars with the standard 14 period CCI under it. I used an intraday tick chart for this example. The same principle applies to minute based charts, daily charts, monthly charts, or any chart. The cycles on an intraday chart are a little more erratic than on a daily chart so for the purpose of visual explanation the intraday chart will make the example more obvious to see. I’m not advocating or implying that this method lends itself more to daytrading. In fact the John Ehlers’ references are all on daily based charts. I’ve included some numbers on the CCI subgraph for reference to subsequent charts.

Compare the above chart with the previous chart. This is exactly the same CCI formula, but instead of using the static 14 parameter, I used the full cycle period measure from the code that produced the blue line in the first chart at the top of the page. Observe how much more clearly the patterns on the CCI become. At reference #1 the 14 period CCI isn’t telling me much of anything, but on the next chart, that I’ll refer to from here on as the adaptive CCI, you can see two inverse head and shoulders patterns, one inside the other. Observe the lines drawn on the necklines. The pattern doesn’t exist on the 14 period CCI. At point #2 again there isn’t much of a signal on the 14 period CCI chart, but on the adaptive CCI chart there is a nice reversal of momentum as the CCI approaches the zero basis line, giving a good place to enter on the bullflag on the price bars. Point #3 on the 14 period was again a mess, but on the adaptive chart there was a clear divergence with a hook around the 100 line. This played out again at point #4.

On the above chart I’ve taken one more step to help visually clear up the CCI patterns. I’ve taken the adaptive CCI and smoothed it with a very short term moving average. This takes out most of the little wiggles and creates a much smoother line. But there is a price to be paid for the smoothing as there always is when applying a moving average. There is a little lag. I find about half the time by smoothing the CCI the signal will be delayed by one bar. The other side of the coin is there are far fewer whipsaws. I have more to say on this subject in the next article, which is on application of the CCI. The type and length of the moving average should be chosen based on how smooth you want the CCI to be based on your own experimentation.

On the above chart in the upper subgraph you’ll see the same adaptive CCI that has the moving average component. In addition I added a second moving average, the blue line, as a signal line, much like the signal line in an MACD. In the bottom subgraph I detrended the CCI on that moving average, so the zero line on the indicator in the bottom subgraph is the same as the blue line on the CCI in the top subgraph. It’s as if I pulled the blue line in the top graph like a string so it’s tight. Then the CCI line readjusts itself around the moving average. This method has some application when trading divergences. For example, observe the inverted head and shoulders after point #1. You can see on the right shoulder that the detrended CCI on the bottom was already positive and gave a clear reversal up when the CCI in the upper graph broke its neckline. Point #4 was also confirmed in a similar way. Point #3 had gone slightly positive for only a couple of bars, but the detrended CCI had been under the zero line for some time as that divergence was forming. The detrended CCI did not help the signal at point #2. Again, this method of detrending is only useful as confirmation for some types of signals. I offer it here as something to experiment with, however you might not find it to be of enough use to warrant taking up screen space, unless you trade divergences, or patterns that have a divergence component.

The above chart is a recap of where we started, with the 14 period CCI in the top subgraph, and the smoothed adaptive CCI in the bottom subgraph. Personally, I can’t make any sense of the CCI on the top subgraph, but the CCI on the bottom has some nice clean patterns that I can see at a glance. Go to next article on CCI application.

Hi there Doug!

Your articles caught my attention, because I use CCI as a base for my Trading System. I´m interested on reading more about making indicators adaptive. I come from different background (economics), but I´m amateur programmer in MT4 platform. I want to thank you for your valuable insights into examination of the classical TA tools. And, if you don´t mind, could you point me to specific resource where I could read about the process of making the indicators adaptive.

Thanks for your reply in advance!

Joey

Doug,

I want to first thank you for your clear work in de-constructing the CCI and in putting together a CCI indicator which is much more effective in giving an edge.

Would it be possible for you to post the easylanguage code for your adaptive CCI? My EL skills are basic. I have no idea how to code the CCI from scratch let alone this third step from your article (“3. Calculate the Mean Deviation: delta_i = abs(last_SMATP – TP_of_period_i) (for all i from 0 to N, where N is the length of a period used to calculate the SMATP). MD = sum_for_all_i(delta_i) / N”). Any help with the coding would be very much appreciated.

Thanks again!

Frank

Frank, I can’t post the code here as it is copyrighted by John Ehlers. I have references to both his books. His Rocket Science book has a good version of the adaptive parameter and it is already coded for TradeStation. His next book, Cybernetic Analysis has a different code, and he has it written out for both Tradestation and eSignal, but I don’t recall he has the CCI written written out, but it is easy to put in. I’m sure there are places on the web that also have the code published if you search around. Check TradeStation forum.

Thanks for the post,

Doug

I’ve been working with the adaptive cci for a few weeks now but first started my study of the cci without the adaptive code. I plotted several CCIs of different periods. So in other words, I had a cci14, cci34, cci50, and cci100 just as an example. I noticed that the different periods showed the same basic patterns but noticed one thing that I found to be significant. There are a number of times during a day where divergence appears. What I noticed is that the longer the period the fewer occurences of divergence. That was very desirable to me. Divergence can cause problems for the success of the patterns, imo. The longer period didn’t show the divergence and more closely represented what price was doing. This also presented more of an opportunity to enter with the trend. You’ll have to check this out for yourself. Also, the longer periods cross the zero line less frequently which more closely represents the REAL trend instead of an artificial CCI trend. I find that crossing the zero line really is an attempt to change the trend in price. There are certainly exceptions to all these observations but fewer exceptions than using a straight cci14 which is very noisy. Well now to my current state. I have the adaptive cci in operation and am using it. However, it isn’t adaptive the way I was hoping. It somehow limits the min and max periods to 6 and 50. Those can be changed but the reality is that the rest of the algorithm seems to keep the period within those limits. I am really wanting the period to change to whatever the true cycle of the market is without those artificial boundaries. Haven’t come up with a solution yet but am looking. Haven’t conversed with John Ehlers yet but intend to.

Well I guess that’s my dissertation for now.

Thanks Doug for allowing these comments.

Mike

By the way, I should mention that in order for my approach to be beneficial in any way, the charting package must allow dynamic scaling of the cci panel. Otherwise, you could go to extremes and sit there for any number of bars.

I have modified the adaptive code to allow a multiplication of the calculated period. So, as of this writing, I am using a multiplication factor of 10. The current calculated period is 26 so my effect period is 10 x 26 =260.

Mike

Mike, I set my limits to 8 and 60. It seems anything beyond 60 isn’t helpful. If you think about what the code is trying to do, it is just eliminating the cyclic content as it is detecting trend and slowly incrementing the cycle length upward as long prices lack cycle tendency. It seems that no matter what time frame you are using there will be some cyclic tendency before 60 bars are reached. Even if not, the CCI will just bump up somewhere beyond the 100 level and stay there and the patterns won’t be that much different if it the cycle stays at 60 or goes to 80 or 100. Also when the cycle comes back into play it will take longer to display the new cycles, especially if a couple of moving averages are used prior to the final cycle measure. This isn’t perfect. The best that it can do is get in the ballpark of the developing cycle. Not sure why the length doesn’t change when you change those limits. It does on my tradestation code. Also, I have tradestation scale in the sub-graph to display the entire range that the CCI travels on the current chart, rather than limit it in any way. That’s a good observation on the lack of divergences as the cycle length extends. When clear divergences do present themselves they are often more reliable than they are with the shorter parameter CCI. And thanks for sharing your posts.

Doug

Thanks Doug…I understand your point about the cycle. I can certainly confirm what you’re saying based on observation. The only problem for me is the divergence and as the CCI is designed that will always occur. I also see the divergence in every indicator I’ve seen except when looking at price directly. How obvious is that? Kidding. I have pondered the issue of divergence for quite some time and actually thought I had found a way to minimize it’s occurence with this adaptive cci and it appears to be the best I’ve seen so far. So, NOT BAD I guess is my comment about the adaptive CCI. Pondering this issue for sometime and discussing it with other, my thought has been “if divergence is such an issue for you, why don’t you just trade off price.” A very good friend that you know as well asked me that very question the other night. That finally caused me to think about the problem a bit differently. As a result, I thought how can I accurately represent price without having to look directly at price. The answer came to me to use EMA with a period of 1. That IS price. I put that up and liked it because there was no divergence. Go figure…Kinda liked that. But that wasn’t enough. It was kinda noisy so I used h+l+c/3 to calculate the EMA(10). Smoothed it out considerably. Funny that it has a CCI look which you would expect except there is no zero line. Well I like the look of the CCI so with the help of a friend, we put some bars under the EMA that we use for a purpose I won’t detail here. I also added 4 other EMAs, EMA(2). EMA(3), EMA(4), and EMA(5). Now that gives me some indication of where entries might be. Then as another experiment based on this adaptive CCI study, I added a smoothing component to see what that did. I like what I saw but it’s use will be delayed for a bit while I explore the base EMA chart. I also intend to add the adaptive code in a separate EMA to explore it’s use as a signal line. All I can say now is studying this adaptive CCI has really opened a new world to me in understanding and possibilities. We are in the process now of backtesting some entry rules.

Thanks,

Mike

Hi Doug,

Again, thanks for all your input on a variable CCI. I hace had a .efs developed for eSignal of a dynamic (variable) CCI. There are still a couple of bugs but they will soon be gone. If anyone wants this .efs, they can Email me at john@sykesusa.com, and I’ll let them know where to go. It will probably not be free but I can say that I will get little if anything out of it.

I was also a frustrated CCIer who soon realized that the CCI had to be used with a longer period. It had not occurred to me that the period should be variable. You changed that. I think that anyone who puts a dynamic CCI on his charts will immediately see the difference.

But, again, thanks. I’ll post more as we go along.

John

Hi Doug – having experimented a with the variable cycle period on the CCI as explained in your article I find the results interesting to say the least. Having spent some time with the WCCI outfit, (an having heard the resistance NOW mantra on numerous occasions) it is really interesting to it for what it really is. Even more interesting is the fact that the CCI formula as indicated on the WCCI site has a hard coded 20 period lookback scheme! Having coded the Ehlers cycle determining period the following :

1. The results of very small adjustments in the alpha parameter appear to have a huge effect on the cycle period determined. I find this fairly disconcerting, as it becomes hard to find a consistent relationship.

2. The cycle period appears to be the exact inverse of what the WCCI club promotes (14p 5min or less, 20 for anything over 5 mins). Generally it would appear that periods averaging around 50 appear fairly consistently on interday charts, while daily, weekly and monthly charts float around 22-30 periods (barring real chop). Is this consistent with your experience?

3. I must say – the effect of the longer period is remarkable.

Your effort has sparked much food for thought. Thank you !

Regards

Tony

Tony, I did have a problem with the alpha parameter adjustment, and for a long time used fixed CCI values of 21, 34, and 55. In time I became for comfortable using the Ehlers formula without the need for the fixed periods, realizing that the Ehlers formula will never be exact but will get me in the ballpark of the most useful cycle. And I do find on the intra-day tick charts the most common cycles seem to hover around 35 to 40 periods with brief excursions beyond 50 or so during trends, and the only time the cycle shortens to 14 is in chop. The daily charts are much more consistent at between 20 and 30, as you suggest. Doug

Doug, I managed to get the Adaptive CCI working from the Ehlers book, but in order to smooth it out I am using the following statement :

CCI_Smoothed = 2 * (WAverage(CCI_Adaptive, WMALength) – .5);

wherein, “CCI_Adaptive” is the raw CCI adaptive value returned from Ehlers formula in the book, and “CCI_Smoothed” is the smoothed out version of the same, which I then plot.

Is this the correct way to go about smoothing the adaptive CCI ? Also, for the smoothing moving average I am using an input variable “WMAlength”, that allows me to see the effects of varying that moving average.

I am currently using a value of 21 for the moving average as that gives me patterns that I can easily recognize and work with for trading. Using smaller lengths (such as 5, 6 etc) creates a lot of whipsawing to and fro over the zero line and makes it difficult to for me to discern the real longer trend.

Am doing this correctly ? and do you have any suggestions for the length of the smoothing moving average ? Your ideas on this would be much appreciated.

Webby,

Regarding the smoothing, thee is no right or wrong. Some people prefer the raw or unsmoothed CCI if they are using it to draw trendlines, which I don’t do. I find a slight smoothing helps to draw my attention to patterns such as the head and shoulders, which seems to pop out much more clearly using the smoothed version, as does the tests of the zero line. With a short parameter there is some lag but not much, so it seems to be a fair tradeoff to make the indicator more clear. I use the weighted average, but only a four period. I did notice that the formula you posted will double the scaling of the CCI, so the 100 line becomes the 200 line. I’d just use the tradestation function, or write it out manually. Regarding using the 21 period parameter, I do like to look at a longer term signal line and 21 period is good for that, but sometime I use a 16 period. I just use the tradestation exponential moving average function for that, and I plot it over the top of the smoother cci along with the histogram of the smoothed cci. I also plot the unsmoothed line, but fairly faint so it doesn’t distract. But I find using a longer smoothing for the basic cci obscures the patterns too much.

Does anyone know how to get an anticipator on adaptive CCI? I have been using it in “as is” form, and it has kepr me out of trouble most of the time i.e CCI fixed period must be confirmed by adaptive CCI so when going long I will not take the signal if the adaptive cci is red ( green or grey is fine ).

The issue is that often it is hard to tell what collor the adaptive cci histogram bar will end up being.

Regards,

Th

hi, here is my cci core(part) to plot the cci -Inputs: Price((H+L+c)/3), Length(19), CycPart(1), Avg1Len(5), Avg2Len(7);

Vars: oResult1(0), oResult2(0), temp(0);

value1=_Oscillators(18, Price, Length, CycPart, 1, 0, 1, oResult1, oResult2);

temp = XAverage(oResult1, Avg1Len);

Plot1(temp, “AdaptCCI”);

Plot2(temp, “AdpCCI_hist”);

Plot3(XAverage(temp, Avg2Len), “AvgCCI”);

is this the rigth wave to plot like u?

Hi Doug,

While I love, and am grateful for, your insight into the Adaptive CCI, I absolutely cannot seem to be able to lay my hands on one, and am very jealous of you for having it.

Do you, or would you be amenable to sharing it? Even at a cost?

Keen as all hell. Thx

Joseph