CCI Watchlist / Scans / Labels for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
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:

hoojsn

New member
Thanks, Ben. Actually I am waiting for it for quite a while. How do you make the colour in CCI column?
 

BenTen

Administrative
Staff member
Staff
VIP
@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);
 

Branch

Member
VIP
Share: I combined the WoodieCCI with the Volume Current Percentage (A code I found on this site)

What it does: This code will let you know if the CCI is falling or rising and will provide the percentage, label color with +200, Zero and -200 breakout lines. It also will let you see the current Volume percentage. If the percentage is greater than 50% then the Shorts/Bears/Sells are in control and vice versa.

How I use it: When Volume in trending in the same direction of the CCI I make my trades with that trend and this is good especially on your Day Chart and 1 hour Chart even on the 1000tick.

Code:
declare lower;
input shortLength = 6;
input longLength = 14;
input lowerSideWinderLimit = 30.0;
input upperSideWinderLimit = 100.0;
input hideSideWinder = No;

def LinearReg = Inertia(close, 25);
def expAvg = ExpAverage(close, 34);
def diff = close - expAvg;
def yyyyMmDd = getYyyyMmDd();
def session_duration_minutes = (regularTradingEnd(yyyyMmDd) - regularTradingStart(yyyyMmDd)) / AggregationPeriod.MIN;
def interval_size_raw;
def aggregation = getAggregationPeriod();
if (aggregation == AggregationPeriod.DAY) {
    interval_size_raw = session_duration_minutes * 60;
} else if (aggregation == AggregationPeriod.TWO_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 2;
} else if (aggregation == AggregationPeriod.THREE_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 3;
} else if (aggregation == AggregationPeriod.FOUR_DAYS) {
    interval_size_raw = session_duration_minutes * 60 * 4;
} else if (aggregation == AggregationPeriod.WEEK) {
    interval_size_raw = session_duration_minutes * 60 * 5;
} else if (aggregation == AggregationPeriod.MONTH or aggregation == AggregationPeriod.OPT_EXP) {
    interval_size_raw = session_duration_minutes * 60 * 22;
} else if (aggregation >= AggregationPeriod.MIN) {
    interval_size_raw = aggregation / AggregationPeriod.MIN;
} else {
    interval_size_raw = aggregation;
}

def ema_angle_factor = Sqrt(interval_size_raw / 180);
def avg_ema = (expAvg[2] + expAvg[1]) / 2;
def avg_lsma = (LinearReg[2] + LinearReg[1]) / 2;
def lsma_slope = (LinearReg - avg_lsma) / tickSize();
def lsma_angle = ATan(lsma_slope / ema_angle_factor) / Double.Pi * 180;
def ema_slope = (expAvg - avg_ema) / tickSize();
def ema_angle = ATan(ema_slope / ema_angle_factor) / Double.Pi * 180;
def sw = lsma_angle + ema_angle;
def swabs = AbsValue(sw);

plot CCI = cci(length = longLength);
plot "CCI Hist" = CCI;
plot "SW +200" = if IsNaN(close) then Double.NaN else 200;
plot "SW -200" = if IsNaN(close) then Double.NaN else -200;
plot ZeroLine = if IsNaN(close) then Double.NaN else 0;

CCI.SetDefaultColor(GetColor(1));
CCI.SetLineWeight(1);

"SW +200".SetDefaultColor(GetColor(1));
"SW +200".SetLineWeight(2);
"SW +200".SetPaintingStrategy(PaintingStrategy.DASHES);
"SW +200".HideTitle();
"SW +200".HideBubble();
"SW +200".DefineColor("Trending", Color.GREEN);
"SW +200".DefineColor("Normal", Color.YELLOW);
"SW +200".DefineColor("Flat", Color.RED);
"SW +200".AssignValueColor(
    if swabs >= upperSideWinderLimit then "SW +200".color("Trending")
    else if swabs >  lowerSideWinderLimit then "SW +200".color("Normal")
    else "SW +200".color("Flat"));

"SW -200".AssignValueColor("SW +200".TakeValueColor());
"SW -200".SetDefaultColor(GetColor(1));
"SW -200".SetLineWeight(2);
"SW -200".SetPaintingStrategy(PaintingStrategy.DASHES);
"SW -200".HideTitle();
"SW -200".HideBubble();

ZeroLine.SetDefaultColor(GetColor(9));
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetLineWeight(1);
ZeroLine.HideTitle();

AddLabel (yes,if close then " CCI " else "", Color.CYAN);
#Label Rise and Fall-------------------------------------------------------------------------------------

input n = 1;

def VUP = CCI > CCI[n];
def VDN = CCI < CCI[n];
AddLabel(1, " CCI : " + Round(CCI, 1) + (if VUP then "   RISING " + ""  else if VDN then "   FALLING " + "" else " --NEUTRAL"),
if VUP then Color.green else if VDN then color.RED else Color.YELLOW);

#end CCI-----------------------------

input Show30DayAvg = yes;
input ShowTodayVolume = yes;
input ShowPercentOf30DayAvg = yes;
input UnusualVolumePercent = 200;
input Show30BarAvg = yes;
input ShowCurrentBar = yes;
input ShowPercentOf30BarAvg = yes;
input ShowSellVolumePercent = yes;

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);

#Volume Data

def volLast30DayAvg = (volume(period = "DAY")[1] + volume(period = "DAY")[2] + volume(period = "DAY")[3] + volume(period = "DAY")[4] + volume(period = "DAY")[5] + volume(period = "DAY")[6] + volume(period = "DAY")[7] + volume(period = "DAY")[8] + volume(period = "DAY")[9] + volume(period = "DAY")[10] + volume(period = "DAY")[11] + volume(period = "DAY")[12] + volume(period = "DAY")[13] + volume(period = "DAY")[14] + volume(period = "DAY")[15] + volume(period = "DAY")[16] + volume(period = "DAY")[17] + volume(period = "DAY")[18] + volume(period = "DAY")[19] + volume(period = "DAY")[20] + volume(period = "DAY")[21] + volume(period = "DAY")[22] + volume(period = "DAY")[23] + volume(period = "DAY")[24] + volume(period = "DAY")[25] + volume(period = "DAY")[26] + volume(period = "DAY")[27] + volume(period = "DAY")[28] + volume(period = "DAY")[29] + volume(period = "DAY")[30]) / 30;
def today = volume(period = "DAY");
def percentOf30Day = Round((today / volLast30DayAvg) * 100, 0);
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4] + volume[5] + volume[6] + volume[7] + volume[8] + volume[9] + volume[10] + volume[11] + volume[12] + volume[13] + volume[14] + volume[15] + volume[16] + volume[17] + volume[18] + volume[19] + volume[20] + volume[21] + volume[22] + volume[23] + volume[24] + volume[25] + volume[26] + volume[27] + volume[28] + volume[29] + volume[30]) / 30;
def curVolume = volume;
def percentOf30Bar = Round((curVolume / avg30Bars) * 100, 0);
def SellVolPercent = Round((Selling / Volume) * 100, 0);

# Labels-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AddLabel (yes,if close then " V " else "", Color.CYAN);
AddLabel(ShowSellVolumePercent, "  Volume  %: " + SellVolPercent, (if SellVolPercent >= 51 then Color.RED else if SellVolPercent < 49 then Color.GREEN else Color.GREEN));

#Branch Moving Averages Label ---------------------------------------------------------------------------

#MOVING AVERAGES-----------------------------------------------------------------
input length2 = 2;
input length5 = 5;
input length8 = 8;
input length10 = 10;
input length13 = 13;
input length21 = 21;
input length35 = 35;
input length50 = 50;
input length100 = 100;
input length200 = 200;
input over_Bought = 80;
input over_Sold = 20;
input price = close;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = no;
input averageType1 = AverageType.SIMPLE;

input crossingType = {default above, below};

def NetChgAvg = MovingAverage(averageType, price - price[1], length10);
def TotChgAvg = MovingAverage(averageType, AbsValue(price - price[1]), length10);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def avg2 = MovingAverage(averageType1, price, length2);
def avg5 = MovingAverage(averageType1, price, length5);
def avg8 = MovingAverage(averageType1, price, length8);
def avg10 = MovingAverage(averageType1, price, length10);
def avg13 = MovingAverage(averageType1, price, length13);
def avg21 = MovingAverage(averageType1, price, length21);
def avg35 = MovingAverage(averageType1, price, length35);
def avg50 = MovingAverage(averageType1, price, length50);
def avg100 = MovingAverage(averageType1, price, length100);
def avg200 = MovingAverage(averageType1, price, length200);

#MOVING AVERGERS LABELS-----------------------------------------------------------------------------------
AddLabel (yes, if close then " MA " else "", Color.CYAN);
AddLabel(yes, if close < avg2 then " (2)  " +  Average (close, 2) else "", Color.RED);
AddLabel (yes, if close > avg2 then " (2)  " +  Average (close, 2) else "", Color.GREEN);
AddLabel(yes, if close < avg5 then " (5)  " +  Average (close, 5) else "", Color.RED);
AddLabel (yes, if close > avg5 then " (5)  " +  Average (close, 5) else "", Color.GREEN);
AddLabel(yes, if close < avg8 then " (8)  " +  Average (close, 8) else "", Color.RED);
AddLabel (yes, if close > avg8 then " (8)  " +  Average (close, 8) else "", Color.GREEN);
AddLabel(yes, if close < avg10 then " (10)  " +  Average (close, 10) else "", Color.RED);
AddLabel (yes, if close > avg10 then " (10)  " +  Average (close, 10) else "", Color.GREEN);
AddLabel(yes, if close < avg13 then " (13)  " +  Average (close, 13) else "", Color.RED);
AddLabel (yes, if close > avg13 then " (13)  " +  Average (close, 13) else "", Color.GREEN);
AddLabel (yes, if close < avg21 then " (21)  " +  Average (close, 21) else "", Color.RED);
AddLabel (yes, if close > avg21 then " (21)  " +  Average (close, 21) else "", Color.GREEN);
AddLabel (yes, if close < avg35 then " (35)  " +  Average (close, 35) else "", Color.RED);
AddLabel (yes, if close > avg35 then " (35)  " +  Average (close, 35) else "", Color.GREEN);
AddLabel (yes, if close < avg50 then " (50)  " +  Average (close, 50) else "", Color.RED);
AddLabel (yes, if close > avg50 then " (50)  " +  Average (close, 50) else "", Color.GREEN);
AddLabel (yes, if close < avg100 then " (100)  " +  Average (close, 100) else "", Color.RED);
AddLabel (yes, if close > avg100 then " (100)  " +  Average (close, 100) else "", Color.GREEN);
AddLabel (yes, if close < avg200 then " (200)  " +  Average (close, 200) else "", Color.RED);
AddLabel (yes, if close > avg200 then " (200)  " +  Average (close, 200) else "", Color.GREEN);

#THE END------------------------------------------------------------------------------------------------------------
 
Last edited:

Branch

Member
VIP
Just added these labels.
AddLabel (yes, if close > avg5 and close > avg8 and close > avg10 and close > avg13 then " MA-BUY " else "", Color.GREEN);
AddLabel (yes, if close > avg21 and close > avg35 and close > avg50 and close > avg100 and close > avg200 then " POWERBUY " else "", Color.GREEN);

AddLabel (yes, if close < avg5 and close < avg8 and close < avg10 and close < avg13 then " MA-SELL " else "", Color.RED);
AddLabel (yes, if close < avg21 and close < avg35 and close < avg50 and close < avg100 and close < avg200 then " POWERSELL " else "", Color.RED);
 

nitrous

Member
VIP
So if CCI is rising and Volume % is less than 50 = Bullish
If CCI is dropping and volume % is more than 50 = Bearish

Is that how it is meant to be read? Thanks
 

earlyinout

New member
this script is doing exactly what I want however I can't figure out how to get the labels to change color based on their value.

if value is positive number want label to be green
if value is negative number want red label

Code:
input cciAvgLength = 9;
def CCIAvg = Average(CCI(14), cciAvgLength);

addLabel(3,"BAR 3 " + (cciavg[3] - cciAvg[4]));
addLabel(2,"BAR 2 " + (cciavg[2] - cciAvg[3]));
AddLabel(1, "BAR 1 " + (cciavg[1] - cciAvg[2]));

Thanks so much!
 

MerryDay

Administrative
Staff member
Staff
VIP
this script is doing exactly what I want however I can't figure out how to get the labels to change color based on their value.

Code:
input cciAvgLength = 9;
def CCIAvg = Average(CCI(14), cciAvgLength);

addLabel(3,"BAR 3 " + (cciavg[3] - cciAvg[4]), if (cciavg[3] - cciAvg[4])>0 then color.green else color.red);
addLabel(2,"BAR 2 " + (cciavg[2] - cciAvg[3]));
AddLabel(1, "BAR 1 " + (cciavg[1] - cciAvg[2]));
I provided the syntax for Bar3, you should now be able to fill in the rest. HTH
 
Last edited:

Hybety

New member
VIP
@Hybety
Personally, I have little use for most watchlist columns. The only watchlist column that I use consistently is the CCI. If I am watching a stock for a potential trade, I find it provides a good signal for most of my strategies.
Ah, I see. Thank you!
My sense is if 2-3 of the right indicators/columns are lined up in agreement, the odds of success become very high. I'm trying to find that effective mix. And looking at it now I do agree the CCI is a good one. May I ask what triggers you look for there? Do you find it more effective paired with anything else?
 

MerryDay

Administrative
Staff member
Staff
VIP
Screenshot (152).png

CCI Stages Watchlist Column Color Key:
Same data as post#1. Changed up the look a wee bit.
Screenshot (149).png

the shared watchlist column link: http://tos.mx/Pmnncmk Click here for --> Easiest way to load shared links
a1.png

CCI Stages Watchlist code:
Ruby:
# ########################################################
# TOS CCI Average Labels & Watchlist by @MerryDay 12/20
# https://www.stockmarkethacks.com/commodity-channel.html
declare lower;
def cci_length = 14 ;
def cci_avg_length = 9 ;
def over_sold = -100 ;
def over_bought = 100 ;
def CCI =   reference CCIAverage("cci length" = cci_length, "cci avg length" = cci_avg_length)."CCI" ;
def CCIAvg = reference CCIAverage("cci length" = cci_length, "cci avg length" = cci_avg_length)."CCIAvg" ;
# ########################################################
# Charting & Formatting
AddLabel(yes,
if CCI < over_sold and CCI >=CCIAvg     then "BUY " + Round(CCI, 0) else
if CCI < over_sold and CCI > CCI[1]     then "Reversing " + Round(CCI, 0) else
if CCI < over_sold                      then "Bottom " + Round(CCI, 0) else
if CCI >= over_bought and CCI >= CCI[1] then "Strong Trend " + Round(CCI, 0) else
if CCI > over_bought                    then "Watch It "  + Round(CCI, 0) else

if CCI crosses above CCIAvg then "TREND BEGIN " + Round(CCI, 0) else
if CCI crosses below CCIAvg then "TREND END " + Round(CCI, 0) else

if CCI < CCIAvg and CCI>CCI[1] then "pre-trend " + Round(CCI, 0)  else
if CCI > CCI[1]                 then "👍 "         + Round(CCI, 0) else
                                     "👎 "         + Round(CCI, 0) );
AssignBackgroundColor(
if CCI < over_sold and CCI >=CCIAvg then color.cyan else
if CCI < over_sold and CCI > CCI[1] then color.cyan  else
if CCI < over_sold                  then CreateColor(124, 10, 2)    else
if CCI > over_bought and CCI > CCI[1] then color.dark_orange else
if CCI > over_bought                    then CreateColor(153, 153, 255)  else
if CCI crosses above CCIAvg      then CreateColor(0, 0, 255) else
if CCI crosses below CCIAvg      then CreateColor(255, 204, 0)   else
if CCI < CCIAvg and CCI>CCI[1] then color.violet   else
if CCI > CCI[1]                 then color.green   else
CreateColor(225, 0, 0) ) ;

@cabe1332 @Hybety Based on poster feedback, I re-created this post with clear explanations. Hope this helps.
 

MerryDay

Administrative
Staff member
Staff
VIP
@Hybety In answer to your question, as to what other indicators I use.
I am a traditional swing trader. I use the main three types of indicators on 3 higher aggregations:
xJNxVT0.png

I am currently using these three indicators. But almost all the standard trend/momentum, volume , support & resistance studies viewed on several timeframes will result in a successful strategy.
I only trade stocks with strong financials with long-term uptrends. As a swing trader, these stocks have histories of being profitable and forward-looking signals that they will continue to be so.
 
Last edited:

cabe1332

Active member
@cabe1332
As many members use dark mode, could you post your dark-mode friendly version of the watchlist?
@MerryDay per your request of using color.black on text and change "TREND BEGIN" to color.lime. Thanks again. Good luck! @cabe1332

Ruby:
# TOS CCI Average Labels & Watchlist by @MerryDay 12/20
# https://www.stockmarkethacks.com/commodity-channel.html
# declare lower;
def cci_length = 14 ;
def cci_avg_length = 9 ;
def over_sold = -100 ;
def over_bought = 100 ;
def CCI = reference CCIAverage("cci length" = cci_length, "cci avg length" = cci_avg_length)."CCI" ;
def CCIAvg = reference CCIAverage("cci length" = cci_length, "cci avg length" = cci_avg_length)."CCIAvg" ;

# Charting & Formatting
AddLabel(yes,
if CCI < over_sold and CCI >=CCIAvg then "BUY " + Round(CCI, 0) else
if CCI < over_sold and CCI > CCI[1] then "Reversing " + Round(CCI, 0) else
if CCI < over_sold then "Bottom " + Round(CCI, 0) else
if CCI >= over_bought and CCI >= CCI[1] then "Strong Trend " + Round(CCI, 0) else
if CCI > over_bought then "Watch It " + Round(CCI, 0) else

if CCI crosses above CCIAvg then "TREND BEGIN " + Round(CCI, 0) else
if CCI crosses below CCIAvg then "TREND END " + Round(CCI, 0) else

if CCI < CCIAvg and CCI>CCI[1] then "Pre-Trend " + Round(CCI, 0) else
if CCI > CCI[1] then "👍 " + Round(CCI, 0) else
"👎 " + Round(CCI, 0), color.black );
AssignBackgroundColor(
if CCI < over_sold and CCI >=CCIAvg then color.cyan else
if CCI < over_sold and CCI > CCI[1] then color.cyan else
if CCI < over_sold then CreateColor(124, 10, 2) else
if CCI > over_bought and CCI > CCI[1] then color.dark_orange else
if CCI > over_bought then CreateColor(153, 153, 255) else
#if CCI crosses above CCIAvg then CreateColor(0, 0, 255) else
if CCI crosses above CCIAvg then color.lime else
if CCI crosses below CCIAvg then CreateColor(255, 204, 0) else
if CCI < CCIAvg and CCI>CCI[1] then color.violet else
if CCI > CCI[1] then color.green else
CreateColor(225, 0, 0) ) ;

# code end
JRDGSTK.png


VZgpvOc.png
 
Last edited by a moderator:

Lesnewby

New member
Awsome, you people are really great to share all this. I ran it against my zero based CCI watchlist indicator and it confirms my choices. thx
 

Similar threads

Top