Woodies CCI Indicator and Scanner for ThinkorSwim

tenacity11

Active member
2019 Donor
Would greatly appreciate if someone could set up a scan for me. I'm looking for anytime a yellow histogram bar appears either above or below the zero line.
Here's the code and thanks so much
Code:
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#
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 TCCI = cci(length = shortLength);
plot "CCI Hist" = CCI;
plot "CZ +100" = if IsNaN(close) then Double.NaN else 100;
plot "CZ -100" = if IsNaN(close) then Double.NaN else -100;
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(0));
CCI.SetLineWeight(3);
TCCI.SetDefaultColor(Color.YELLOW);
def colorState;
if Crosses(0, CCI, CrossingDirection.Below) {
colorState = 1;
} else if Crosses(0, CCI, CrossingDirection.Above) {
colorState = -1;
} else if (cci[1] > 0) {
colorState = ColorState[1] + 1;
} else if (cci[1] < 0) {
colorState = ColorState[1] - 1;
} else {
colorState = 0;
}
def histColor = {default "Neutral", "Negative", "Positive", "Last neutral"};
if AbsValue(colorState) == 1 {
if colorState[1] == 0 or histColor[1] == histColor."Positive" or histColor[1] == histColor."Negative" {
histColor = histColor."Neutral";
} else {
histColor = if colorState > 0 then histColor."Positive" else histColor."Negative";
}
} else if AbsValue(colorState) > 1 and AbsValue(colorState) < 5 {
histColor = histColor[1];
} else if AbsValue(colorState) == 5 {
if histColor[1] == histColor."Neutral" {
histColor = histColor."Last neutral";
} else {
histColor = histColor[1];
}
} else if AbsValue(colorState) > 5 {
histColor = if colorState > 0 then histColor."Positive" else histColor."Negative";
} else {
histColor = histColor."Neutral";
}
"CCI Hist".DefineColor("Neutral", Color.GRAY);
"CCI Hist".DefineColor("Last Neutral", Color.YELLOW);
"CCI Hist".DefineColor("Positive", Color.GREEN);
"CCI Hist".DefineColor("Negative", Color.RED);
"CCI Hist".SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
"CCI Hist".SetLineWeight(3);
"CCI Hist".HideTitle();
"CCI Hist".AssignValueColor(
if histColor == HistColor."Neutral" then "CCI Hist".color("Neutral")
else if histColor == HistColor."Negative" then "CCI Hist".color("Negative")
else if histColor == HistColor."Positive" then "CCI Hist".color("Positive")
    else "CCI Hist".color("Last Neutral"));
"CZ +100".DefineColor("Dark Red", Color.DARK_RED);
"CZ +100".DefineColor("Light Red", Color.LIGHT_RED);
"CZ +100".DefineColor("Dark Orange", Color.DARK_ORANGE);
"CZ +100".DefineColor("Light Orange", Color.LIGHT_ORANGE);
"CZ +100".DefineColor("Yellow", Color.YELLOW);
"CZ +100".DefineColor("Lime", Color.LIME);
"CZ +100".DefineColor("Light Green", Color.LIGHT_GREEN);
"CZ +100".DefineColor("Dark Green", Color.DARK_GREEN);
"CZ +100".DefineColor("Cyan", Color.CYAN);
"CZ +100".SetDefaultColor(GetColor(1));
"CZ +100".SetLineWeight(2);
"CZ +100".SetPaintingStrategy(PaintingStrategy.DASHES);
"CZ +100".HideTitle();
"CZ +100".HideBubble();
"CZ +100".AssignValueColor(
if (AbsValue(diff) < tickSize()) then
"CZ +100".color("Yellow")
else if (tickSize() < diff && diff <= 2 * tickSize()) then
"CZ +100".color("Lime")
else if (2 * tickSize() < diff && diff <= 3 * tickSize()) then
"CZ +100".color("Light Green")
else if (3 * tickSize() < diff && diff <= 4 * tickSize()) then
"CZ +100".color("Dark Green")
else if (4 * tickSize() < diff) then
"CZ +100".color("Cyan")
else if (-tickSize() > diff && diff >= -2 * tickSize()) then
"CZ +100".color("Light Orange")
else if (-2 * tickSize() > diff && diff >= -3 * tickSize()) then
"CZ +100".color("Dark Orange")
else if (-3 * tickSize() > diff && diff >= -4 * tickSize()) then
"CZ +100".color("Light Red")
else
      "CZ +100".color("Dark Red"));
"CZ -100".AssignValueColor("CZ +100".TakeValueColor());
"CZ -100".SetDefaultColor(GetColor(1));
"CZ -100".SetLineWeight(2);
"CZ -100".SetPaintingStrategy(PaintingStrategy.DASHES);
"CZ -100".HideTitle();
"CZ -100".HideBubble();
"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.DefineColor("Above LSMA", Color.GREEN);
ZeroLine.DefineColor("Equal to LSMA", Color.WHITE);
ZeroLine.DefineColor("Below LSMA", Color.RED);
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);
ZeroLine.SetLineWeight(2);
ZeroLine.HideTitle();
ZeroLine.AssignValueColor(
if close < LinearReg then ZeroLine.color("Below LSMA")
else if close > LinearReg then ZeroLine.color("Above LSMA")
    else ZeroLine.color("Equal to LSMA"));
AddLabel(!hideSideWinder and !isNaN(sw), round(sw, 2) +
if swabs >= upperSideWinderLimit then
" Trending"
else if swabs > lowerSideWinderLimit then
" Normal"
else
    " Flat", "SW -200".takeValueColor());
 

tomsk

Well-known member
VIP
@tenacity11 Per your request here is a custom Woodies CCI scan for a yellow histogram bar either above or below the zero line. I have scanned this against the S&P 500 using a daily aggregation and obtained 26 results. I cross checked this against the Woodies CCI study and they match up. Have fun!

Code:
# Woodies CCI Scan
# tomsk
# 1.12.2020

# tomsk: As requested by tenacity11, this is a custom Woodies CCI scan for a
# yellow histogram bar either above or below the zero line. This is based on
# the standard TOS Woodies CCI study

input shortLength = 6;
input longLength = 14;

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);

def CCI = cci(length = longLength);
def CCIHist = CCI;

def colorState;
if Crosses(0, CCI, CrossingDirection.Below) {
    colorState = 1;
} else if Crosses(0, CCI, CrossingDirection.Above) {
    colorState = -1;
} else if (cci[1] > 0) {
    colorState = ColorState[1] + 1;
} else if (cci[1] < 0) {
    colorState = ColorState[1] - 1;
} else {
    colorState = 0;
}

def histColor = {default "Neutral", "Negative", "Positive", "Last neutral"};

if AbsValue(colorState) == 1 {
    if  colorState[1] == 0 or histColor[1] == histColor."Positive" or histColor[1] == histColor."Negative" {
        histColor = histColor."Neutral";
    } else {
        histColor = if colorState > 0 then histColor."Positive" else histColor."Negative";
    }
}
else if AbsValue(colorState) > 1 and AbsValue(colorState) < 5 {
    histColor = histColor[1];
}
else if AbsValue(colorState) == 5 {
    if histColor[1] == histColor."Neutral" {
        histColor = histColor."Last neutral";
    } else {
        histColor = histColor[1];
    }
}
else if AbsValue(colorState) > 5 {
    histColor = if colorState > 0 then histColor."Positive" else histColor."Negative";
}
else {
    histColor = histColor."Neutral";
}

plot scan = histColor == histColor."Last neutral";
# End Woodies CCI Scan
 
Last edited:

tenacity11

Active member
2019 Donor
@tomsk
Greatly appreciated. 2020 is going to be about backtracking to simplicity. Even long time traders can get caught in analysis paralysis and having gone through so much info I needed to get back to just simple and this will work.
 

tomsk

Well-known member
VIP
@tenacity11 You're very welcome, and it is really helpful when you clearly and precisely articulated your requirements. Literally took me about 5 mins effort to construct that scan. Have fun!
 
T

Thomas

Guest
BTW,....Woodie has a desktop reference guide on his system..

Do you have Woodies trading manuel for this strategy? If interested....

Woodie had occasionally visited the ThinkScript chat in TOS,.... he's someone that people should be trying to locate...
 
Last edited by a moderator:

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.
Top