## CCI Divergence Indicator for Think or Swim

I got commissioned to write more divergence indicators, and the customer was generous enough to allow me to share it with the rest of the donors. I say donors because it builds on my donor-only fully variable swing points indicator, so I’m not releasing it freely as a sponsored indicator. If you are a past (or future ) donor, you can get it from the “Released Thinkscript Studies” page, called “Pro_CCIDivergence_v1STUDY.zip”. I like this “donor share” idea and will keep doing it as those who commission custom work are willing to share. If you don’t care to donate or you just want to do-it-yourself, it’s not complicated to write your own if you already have a swing points logic built, like I outlined previously. I’ll walk through the additional steps below.

Following on the heels of my Swing Points and MACD Divergence indicators, here’s two more indicators that look for divergences between the CCI and price, and divergences between Price and CCI. There’s one upper study and one lower study.

Every time we get a lower swing low in price, the CCI is checked to see if it also prints a lower value. Similar for highs; higher high without higher CCI is a divergence. Here is a picture of the indicator at work. On the upper frame, the ProCCIDivergence is plotted as a red dot for bearish divergence, and a green dot for bullish divergence. On the lower frame, the opposite divergence is checked. If the CCI has a a lower swing low, the price lows are checked to see if they also print a lower value. Similar for highs; higher CCI swing high without higher price high is a divergence. The colors on the lower plot look backwards, but remember–the lower indicator is plotting a bullish divergence for the value of CCI, NOT the value of price. And as CCI rises, price generally declines.

To make the top study, just follow the MACD divergence tutorial, but in the recursive divergence functions, change the references from MACD to CCI in this way:

input l=14; #This is the CCI input length
rec blCCI = if swinglow then reference CCI(length=l).CCI else blCCI[1];
rec brCCI = if swinghigh then reference CCI(length=l).CCI else brCCI[1];

And there you go. If you also want the lower study, you change it up a bit. The swing point checks are reversed in that you check CCI values for swing highs and lows, and then you define your bullish and bearish divergence recursive functions above to get the value of price if you are at a CCI swing high or CCI swing low, like this:

input l=14; #This is the CCI input length
def CCI=reference CCI(length=l).CCI;
Def swinghigh = if CCI > CCI[1] and CCI > CCI[2] and CCI > CCI[-1] and CCI > CCI[-2] then 1 else 0;
Def swinglow = if CCI < CCI[1] and CCI < CCI[2] and CCI < CCI[-1] and CCI < CCI[-2] then 1 else 0;
rec blPRICE = if swinglow then low else blPRICE[1];
rec brPRICE = if swinghigh then high else brPRICE[1];

Then plot what you want, and go from there! Personally, I think the lower study is less useful than the upper, but you may feel differently.

That’s it! If you are making your own, leave a comment if you have any questions. If you just want to grab mine, donate away:

### 7 Responses to “CCI Divergence Indicator for Think or Swim”

let’s see some ninja scripting!

2. rmccall Says:

In Price Headley’s book ‘Big Trends in Trading’, Chapter 8 is dedicated to his Momentum Divergence indicator. The only charting system where I can find this indicator is in OptionVue. Has anyone developed the formula for ThinkorSwim?

3. RSI Divergence Indicator for Think or Swim « Read the Prospectus Says:

[...] a similar vein to my MACD and CCI Divergence indicators, here’s an indicator that checks for divergences between RSI and price. [...]

4. Elliot Says:

How would I open your study files with .ts extension? My media player would not open it even though I downloaded MPEG-2 ts codec. Thanks in advance for your prompt response.

5. Prospectus Says:

Also, these .ts files are just a text file with a fancy extension. You can open it with notepad on windoze or TextEdit on a Mac and see the script code.

6. Elliot Says:

Thank you, Prospectus.
I’ve managed to open .ts files with MS Notepad.
However, Notepad saved it with .txt extension.
When I tried to import the script as a new study, TOS
could not see it in Browse with .txt extension. It was
looking for *study.ts extention. Any idea what I’ve done
wrong, if anything? I’ve made it working though, by
simply using Copy and Paste.

7. Prospectus Says:

That link I gave tells how to import it directly. But you can also copy/paste like you did.