CCI Watchlist / Scan / Label / Strategy for ThinkorSwim

jimmy rr

New member
i have been trying to plot cci studay on the lower plot with green dot when it crosses above zero line and red when it crosses down through the 100 i would also like to be able to change the length of cci and be able to put it in a watch list . thank for any help.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@jimmy rr Taking a look at your request, it seems that the signals might be visually more apparent is arrows were used, so here is a study with GREEN arrows when CCI crosses above zero line and RED arrows when CCI crosses below the 100 line. The length of the CCI can be changed via the user interface so nothing to do there. The watchlist can be done quite easily as well - you've got to be real precise about what you'd like to see on the watchlist. Provide as much details as possible so there won't be any misinterpretation.

Here is your completed CCI study. I have also added labels and alerts to that chart study

Code:
# CCI Buy Sell Signals
# tomsk
# 1.12.2020

declare lower;

input length = 14;
input over_sold = -100;
input over_bought = 100;
input showBreakoutSignals = no;

def price = close + low + high;
def linDev = lindev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;
plot UpSignal = if CCI crosses above 0 then 0 else Double.Nan;
plot DownSignal = if CCI crosses below 100 then 100 else Double.Nan;

CCI.setDefaultColor(GetColor(9));
OverBought.setDefaultColor(GetColor(5));
ZeroLine.setDefaultColor(GetColor(5));
OverSold.setDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(5);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(5);

Alert(UpSignal, "CCI crosses above 0", Alert.BAR, Sound.Ring);
Alert(DownSignal, "CCI crosses below 100", Alert.BAR, Sound.Bell);
AddLabel(UpSignal, "CCI crosses above 0", Color.GREEN);
AddLabel(DownSignal, "CCI crosses below 100", Color.RED);
# End CCI Buy Sell Signals
 
Code:
# ToS CCI with downsignla changed to cross below 100 the overbought line.
# Horserider 1/12/2020 on request from jimmyrr

declare lower;

input length = 14;
input over_sold = -100;
input over_bought = 100;
input showBreakoutSignals = no;

def price = close + low + high;
def linDev = lindev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
plot OverBought = over_bought;
plot ZeroLine = 0;
plot OverSold = over_sold;
plot UpSignal = if CCI crosses above ZeroLine then ZeroLine else Double.Nan;
plot DownSignal = if CCI crosses below  OverBought then  OverBought else Double.Nan;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

CCI.setDefaultColor(GetColor(9));
OverBought.setDefaultColor(GetColor(5));
ZeroLine.setDefaultColor(GetColor(5));
OverSold.setDefaultColor(GetColor(5));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.POINTS);
 
Was curious how to remove duplicate/extra buy and sell signals from indicator? Id like to keep the first of a new signal and remove all others. Ive basically taken the CCI average indicator (lower) study and made it an (upper) study with buy and sell signals.
Code:
declare upper;

input cciLength = 14;
input cciAvgLength = 9;
input over_sold = -100;
input over_bought = 100;

def CCI = CCI(length = cciLength);
def CCIAvg = Average(CCI, cciAvgLength);
def OverBought = over_bought;
def OverSold = over_sold;

plot UpSignal = CCI crosses above oversold;
plot DownSignal = CCI crosses below overbought;

UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
This is probably best for @BenTen but anyone would be my hero.

I've scanned through this site and found multiple threads for CCI. But I can't find (or I'm overlooking it) this... Is there a way to add a basic alert in the generic TOS-built CCI study whenever the arrows are triggered up or down as they cross the 0 line?
 
Add this to the end of your script:

Code:
# Alerts
Alert(UpSignal, " ", Alert.Bar, Sound.Chimes);
Alert(DownSignal, " ", Alert.Bar, Sound.Bell);
 
Hey guys, I used to do some simple coding in MT4, but I'm new to TOS. This should be very simple, but can someone tell me how to change the arrows so they plot on the chart instead of in the indicator window? Much appreciated!
 
Simply drag the lower study up to the upper study section and, optionally, turn off the all of the plots except UpSignal and DownSignal... Or maybe you'll like the entire study overlaying the chart action like I do with the RSI...

Edited to add: I see now that the arrows plot where the zero line would be so this may not be the best option...
 
Last edited:
I appreciate the suggestion @rad14733, but the arrows do get a tad funky on the chart. Anyone else have suggestion on how to properly get the arrows to display on the main chart?
 
I appreciate the suggestion @rad14733, but the arrows do get a tad funky on the chart. Anyone else have suggestion on how to properly get the arrows to display on the main chart?
If I get a chance, I'll see if I can write a script that references the study above and places arrows at the high or low as an upper study...
 
@sparhawk
Code:
input length = 20;
input showBreakoutSignals = yes;

def price = close + low + high;
def linDev = lindev(price, length);
def CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;

input OverBought = 1;
input OverSold = -1;

plot UpSignal = if CCI crosses above OverBought then OverBought else Double.Nan;
plot DownSignal = if CCI crosses below OverSold then OverSold else Double.Nan;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

UpSignal.SetDefaultColor(Color.GREEN);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.RED);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
@horserider thank you so much! This is perfect for what I need. I really appreciate it.

One final question. Is it possible to make a CCI scanner? Similar to a MA crossover scan it would catch when a crossover occurs, but the CCI scan should catch a crossover of the zero line in either direction. Ideally you would be able to change the time frame.

If anyone can make that scan I'll pass along my simple strategy for catching great swing trades using CCI. I confirm entries using a few MA's and looking at past S/R levels.
 
Last edited by a moderator:
@sparhawk Not a scanner expert. Maybe

CCI()."CCI" crosses CCI()."ZeroLine" within 2 bars

Give crosses both directions. If do not want "within 2 bars" just delete that part.
 
Here is the CCI (Commodity Channel Index) watchlist column for ThinkorSwim.
  • Green = CCI crosses above the oversold level
  • Red = CCI crosses below the overbought level
  • Blue = CCI crosses the Zero line
the shared watchlist column link: http://tos.mx/AeMXnRC Click here for --> Easiest way to load shared links
ygaW022.png


thinkScript Code

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2017-2020
#

declare lower;

input length = 14;
input over_sold = -100;
input over_bought = 100;
input showBreakoutSignals = no;

def price = close + low + high;
def linDev = lindev(price, length);
plot CCI = if linDev == 0 then 0 else (price - Average(price, length)) / linDev / 0.015;
def ZeroLine = 0;

def condition1 = CCI crosses above over_sold;
def condition2 = CCI crosses below over_bought;
def condition3 = CCI crosses Zeroline;

AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);
 
Last edited by a moderator:
Thanks, Ben. Actually I am waiting for it for quite a while. How do you make the colour in CCI column?
 
@hoojsn What do you mean? Are you asking about the code that specifies the color background?

Here it is:

Code:
AssignBackgroundColor(if condition1 then color.dark_green else if condition2 then color.dark_red else if condition3 then color.blue else color.gray);
 
UpSignal.SetDefaultColor(Color.GREEN); UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); DownSignal.SetDefaultColor(Color.RED); DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
In a lower study can the Up and Down Arrows always appear at the very top of the Window?
 
@horserider hi. thank you for share with us, a quick question, i see the script have overbought 1 and oversold -1, that mean 100 and -100? can you do overbought 200 and oversold -200? thanks
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
403 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top