CCI and Bollinger Bands For ThinkOrSwim

swing4sure

New member
Can someone help me to convert below TV script (CCI + Bollinger) to match Thinkorswim platform. Any help is greatly appreciated.
Here is the link.

I am specifically looking for equivalent code for Thinkorswim the below snippet of the code in Tradingview. This indicator will help to take trades very precisely.

https://www.tradingview.com/script/IkciCgbh/

//bgcolor -----
c1 = cci > upper
c2 = cci < upper and cci > basis
c3 = cci > lower and cci < basis
c4 = cci < lower
cci_color = c1 ? #F8B856 : c2 ? #F6AD3C : c3 ? #F5A21B : #F39800
fill_bb_color = c1 ? lime : c2 ? green : c3 ? maroon : red


p1 = plot(upper, color=#0099cc, title="uppper band")
p2 = plot(lower, color=#0099cc, title="lower band")
fill(p1, p2, color=fill_bb_color, transp=80, title="BB fill")
 
Last edited:

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

Can someone help me to convert below TV script (CCI + Bollinger) to match Thinkorswim platform. Any help is greatly appreciated.
Here is the link.

I am specifically looking for equivalent code for Thinkorswim the below snippet of the code in Tradingview. This indicator will help to take trades very precisely.

https://www.tradingview.com/script/IkciCgbh/

//bgcolor -----
c1 = cci > upper
c2 = cci < upper and cci > basis
c3 = cci > lower and cci < basis
c4 = cci < lower
cci_color = c1 ? #F8B856 : c2 ? #F6AD3C : c3 ? #F5A21B : #F39800
fill_bb_color = c1 ? lime : c2 ? green : c3 ? maroon : red


p1 = plot(upper, color=#0099cc, title="uppper band")
p2 = plot(lower, color=#0099cc, title="lower band")
fill(p1, p2, color=fill_bb_color, transp=80, title="BB fill")
check out the below.

CSS:
#study(shorttitle="CCI & BB", title="CCI and Bollinger Bands")
# Converted by Sam4Cok@Samer800 - 11/2022
declare lower;
#//input ------
input cci_len = 14;    # "CCI length"
input cci_src = close; # "CCI source"

input length = 14;   # "BB length"
input mult = 2.0;    # "Deviations"

input adD_8_lines = no;
input line1 = 100;
input line2 = 200;
input line3 = 300;
input line4 = 400;

def na = Double.NaN;
#//CCI -----
def price = cci_src;
def linDev = lindev(price, cci_len);
def nCCI = if linDev == 0 then 0 else (price - Average(price, cci_len)) / linDev / 0.015;
def cci =nCCI;

#//BB -----
def bb_src = cci;
def basis = Average(bb_src, length);
def dev = mult * stdev(bb_src, length);
def upper = basis + dev;
def lower = basis - dev;

#//bgcolor -----
def c1 = cci > upper;
def c2 = cci < upper and cci > basis;
def c3 = cci > lower and cci < basis;
def c4 = cci < lower;

def color = if c1 then 2 else if c2 then 1 else if c3 then -1 else -2;#? #F8B856 : c2 ? #F6AD3C : c3 ? #F5A21B : #F39800
#def fill_bb_color = c1 ? lime : c2 ? green : c3 ? maroon : red

def cross_color_1 = if crosses(cci, 100, CrossingDirection.ABOVE) then 100 else
                    if crosses(cci, -100, CrossingDirection.ABOVE) then -100 else na;
def cross_color_2 = if crosses(cci, 100, CrossingDirection.BELOW) then 100 else
                    if crosses(cci, -100, CrossingDirection.BELOW) then -100 else na;

plot SigUp = cross_color_1;
plot SigDn = cross_color_2;

SigUp.SetPaintingStrategy(PaintingStrategy.POINTS);
SigUp.SetDefaultColor(Color.GREEN);
SigUp.SetLineWeight(3);
SigDn.SetPaintingStrategy(PaintingStrategy.POINTS);
SigDn.SetDefaultColor(Color.RED);
SigDn.SetLineWeight(3);

#//plot -----

plot p1 = upper;     # "uppper band"
p1.SetDefaultColor(CreateColor(0,153,204));
plot p2 = lower;     # "lower band"
p2.SetDefaultColor(CreateColor(0,153,204));


plot CenterLine = basis;   # "center line"
CenterLine.SetDefaultColor(CreateColor(0,153,204));
CenterLine.SetStyle(Curve.MEDIUM_DASH);
plot cciLine = cci;        # "CCI"
cciLine.SetDefaultColor(Color.ORANGE);
cciLine.SetLineWeight(2);

plot ZeroLine = if isNaN(close) then na else 0; # "zero line"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);
plot h1 = if isNaN(close) then na else 100;     # "upper line"
h1.SetDefaultColor(Color.DARK_GRAY);
h1.SetStyle(Curve.MEDIUM_DASH);
plot h2 = if isNaN(close) then na else -100;    # "lower line"
h2.SetDefaultColor(Color.DARK_GRAY);
h2.SetStyle(Curve.MEDIUM_DASH);

AddCloud(h1, h2, color.DARK_GRAY);    # "CCI fill"
AddCloud(if color==2 then p1 else na, p2, Color.GREEN); #"BB fill")
AddCloud(if color==1 then p1 else na, p2, Color.DARK_GREEN); #"BB fill")
AddCloud(if color==-1 then p1 else na, p2, Color.DARK_RED); #"BB fill")
AddCloud(if color==-2 then p1 else na, p2, Color.RED); #"BB fill")

plot "1" = if isNaN(close) then na else if(!adD_8_lines, na,line1);
plot "2" = if isNaN(close) then na else if(!adD_8_lines, na,line2);
plot "3" = if isNaN(close) then na else if(!adD_8_lines, na,line3);
plot "4" = if isNaN(close) then na else if(!adD_8_lines, na,line4);
plot "-1"= if isNaN(close) then na else if(!adD_8_lines, na,-line1);
plot "-2"= if isNaN(close) then na else if(!adD_8_lines, na,-line2);
plot "-3"= if isNaN(close) then na else if(!adD_8_lines, na,-line3);
plot "-4"= if isNaN(close) then na else if(!adD_8_lines, na,-line4);

"1".SetDefaultColor(Color.DARK_GRAY);
"2".SetDefaultColor(Color.DARK_GRAY);
"3".SetDefaultColor(Color.DARK_GRAY);
"4".SetDefaultColor(Color.DARK_GRAY);
"-1".SetDefaultColor(Color.DARK_GRAY);
"-2".SetDefaultColor(Color.DARK_GRAY);
"-3".SetDefaultColor(Color.DARK_GRAY);
"-4".SetDefaultColor(Color.DARK_GRAY);

#--- END Code
 
check out the below.

CSS:
#study(shorttitle="CCI & BB", title="CCI and Bollinger Bands")
# Converted by Sam4Cok@Samer800 - 11/2022
declare lower;
#//input ------
input cci_len = 14;    # "CCI length"
input cci_src = close; # "CCI source"

input length = 14;   # "BB length"
input mult = 2.0;    # "Deviations"

input adD_8_lines = no;
input line1 = 100;
input line2 = 200;
input line3 = 300;
input line4 = 400;

def na = Double.NaN;
#//CCI -----
def price = cci_src;
def linDev = lindev(price, cci_len);
def nCCI = if linDev == 0 then 0 else (price - Average(price, cci_len)) / linDev / 0.015;
def cci =nCCI;

#//BB -----
def bb_src = cci;
def basis = Average(bb_src, length);
def dev = mult * stdev(bb_src, length);
def upper = basis + dev;
def lower = basis - dev;

#//bgcolor -----
def c1 = cci > upper;
def c2 = cci < upper and cci > basis;
def c3 = cci > lower and cci < basis;
def c4 = cci < lower;

def color = if c1 then 2 else if c2 then 1 else if c3 then -1 else -2;#? #F8B856 : c2 ? #F6AD3C : c3 ? #F5A21B : #F39800
#def fill_bb_color = c1 ? lime : c2 ? green : c3 ? maroon : red

def cross_color_1 = if crosses(cci, 100, CrossingDirection.ABOVE) then 100 else
                    if crosses(cci, -100, CrossingDirection.ABOVE) then -100 else na;
def cross_color_2 = if crosses(cci, 100, CrossingDirection.BELOW) then 100 else
                    if crosses(cci, -100, CrossingDirection.BELOW) then -100 else na;

plot SigUp = cross_color_1;
plot SigDn = cross_color_2;

SigUp.SetPaintingStrategy(PaintingStrategy.POINTS);
SigUp.SetDefaultColor(Color.GREEN);
SigUp.SetLineWeight(3);
SigDn.SetPaintingStrategy(PaintingStrategy.POINTS);
SigDn.SetDefaultColor(Color.RED);
SigDn.SetLineWeight(3);

#//plot -----

plot p1 = upper;     # "uppper band"
p1.SetDefaultColor(CreateColor(0,153,204));
plot p2 = lower;     # "lower band"
p2.SetDefaultColor(CreateColor(0,153,204));


plot CenterLine = basis;   # "center line"
CenterLine.SetDefaultColor(CreateColor(0,153,204));
CenterLine.SetStyle(Curve.MEDIUM_DASH);
plot cciLine = cci;        # "CCI"
cciLine.SetDefaultColor(Color.ORANGE);
cciLine.SetLineWeight(2);

plot ZeroLine = if isNaN(close) then na else 0; # "zero line"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);
plot h1 = if isNaN(close) then na else 100;     # "upper line"
h1.SetDefaultColor(Color.DARK_GRAY);
h1.SetStyle(Curve.MEDIUM_DASH);
plot h2 = if isNaN(close) then na else -100;    # "lower line"
h2.SetDefaultColor(Color.DARK_GRAY);
h2.SetStyle(Curve.MEDIUM_DASH);

AddCloud(h1, h2, color.DARK_GRAY);    # "CCI fill"
AddCloud(if color==2 then p1 else na, p2, Color.GREEN); #"BB fill")
AddCloud(if color==1 then p1 else na, p2, Color.DARK_GREEN); #"BB fill")
AddCloud(if color==-1 then p1 else na, p2, Color.DARK_RED); #"BB fill")
AddCloud(if color==-2 then p1 else na, p2, Color.RED); #"BB fill")

plot "1" = if isNaN(close) then na else if(!adD_8_lines, na,line1);
plot "2" = if isNaN(close) then na else if(!adD_8_lines, na,line2);
plot "3" = if isNaN(close) then na else if(!adD_8_lines, na,line3);
plot "4" = if isNaN(close) then na else if(!adD_8_lines, na,line4);
plot "-1"= if isNaN(close) then na else if(!adD_8_lines, na,-line1);
plot "-2"= if isNaN(close) then na else if(!adD_8_lines, na,-line2);
plot "-3"= if isNaN(close) then na else if(!adD_8_lines, na,-line3);
plot "-4"= if isNaN(close) then na else if(!adD_8_lines, na,-line4);

"1".SetDefaultColor(Color.DARK_GRAY);
"2".SetDefaultColor(Color.DARK_GRAY);
"3".SetDefaultColor(Color.DARK_GRAY);
"4".SetDefaultColor(Color.DARK_GRAY);
"-1".SetDefaultColor(Color.DARK_GRAY);
"-2".SetDefaultColor(Color.DARK_GRAY);
"-3".SetDefaultColor(Color.DARK_GRAY);
"-4".SetDefaultColor(Color.DARK_GRAY);

#--- END Code
Do you know if it's possible to put an audio alert when CCI touches either top or bottom of the Bollinger Bands?
 
Do you know if it's possible to put an audio alert when CCI touches either top or bottom of the Bollinger Bands?
check the below

CODE:

CSS:
#study(shorttitle="CCI & BB", title="CCI and Bollinger Bands")
# Converted by Sam4Cok@Samer800 - 11/2022
declare lower;
#//input ------
input alerts   = yes;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input cci_len = 14;    # "CCI length"
input cci_src = close; # "CCI source"
input length = 14;   # "BB length"
input mult = 2.0;    # "Deviations"
input adD_8_lines = no;
input line1 = 100;
input line2 = 200;
input line3 = 300;
input line4 = 400;

def na = Double.NaN;
#//CCI -----
def price = cci_src;
def linDev = lindev(price, cci_len);
def nCCI = if linDev == 0 then 0 else (price - Average(price, cci_len)) / linDev / 0.015;
def cci =nCCI;

#//BB -----
def bb_src = cci;
def basis = Average(bb_src, length);
def dev = mult * stdev(bb_src, length);
def upper = basis + dev;
def lower = basis - dev;

#//bgcolor -----
def c1 = cci > upper;
def c2 = cci < upper and cci > basis;
def c3 = cci > lower and cci < basis;
def c4 = cci < lower;

def color = if c1 then 2 else if c2 then 1 else if c3 then -1 else -2;#? #F8B856 : c2 ? #F6AD3C : c3 ? #F5A21B : #F39800
#def fill_bb_color = c1 ? lime : c2 ? green : c3 ? maroon : red

def cross_color_1 = if crosses(cci, 100, CrossingDirection.ABOVE) then 100 else
                    if crosses(cci, -100, CrossingDirection.ABOVE) then -100 else na;
def cross_color_2 = if crosses(cci, 100, CrossingDirection.BELOW) then 100 else
                    if crosses(cci, -100, CrossingDirection.BELOW) then -100 else na;

plot SigUp = cross_color_1;
plot SigDn = cross_color_2;

SigUp.SetPaintingStrategy(PaintingStrategy.POINTS);
SigUp.SetDefaultColor(Color.GREEN);
SigUp.SetLineWeight(3);
SigDn.SetPaintingStrategy(PaintingStrategy.POINTS);
SigDn.SetDefaultColor(Color.RED);
SigDn.SetLineWeight(3);

#//plot -----

plot p1 = upper;     # "uppper band"
p1.SetDefaultColor(CreateColor(0,153,204));
plot p2 = lower;     # "lower band"
p2.SetDefaultColor(CreateColor(0,153,204));


plot CenterLine = basis;   # "center line"
CenterLine.SetDefaultColor(CreateColor(0,153,204));
CenterLine.SetStyle(Curve.MEDIUM_DASH);
plot cciLine = cci;        # "CCI"
cciLine.SetDefaultColor(Color.ORANGE);
cciLine.SetLineWeight(2);

plot ZeroLine = if isNaN(close) then na else 0; # "zero line"
ZeroLine.SetDefaultColor(Color.DARK_GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);
plot h1 = if isNaN(close) then na else 100;     # "upper line"
h1.SetDefaultColor(Color.DARK_GRAY);
h1.SetStyle(Curve.MEDIUM_DASH);
plot h2 = if isNaN(close) then na else -100;    # "lower line"
h2.SetDefaultColor(Color.DARK_GRAY);
h2.SetStyle(Curve.MEDIUM_DASH);

AddCloud(h1, h2, color.DARK_GRAY);    # "CCI fill"
AddCloud(if color==2 then p1 else na, p2, Color.GREEN); #"BB fill")
AddCloud(if color==1 then p1 else na, p2, Color.DARK_GREEN); #"BB fill")
AddCloud(if color==-1 then p1 else na, p2, Color.DARK_RED); #"BB fill")
AddCloud(if color==-2 then p1 else na, p2, Color.RED); #"BB fill")

plot "1" = if isNaN(close) then na else if(!adD_8_lines, na,line1);
plot "2" = if isNaN(close) then na else if(!adD_8_lines, na,line2);
plot "3" = if isNaN(close) then na else if(!adD_8_lines, na,line3);
plot "4" = if isNaN(close) then na else if(!adD_8_lines, na,line4);
plot "-1"= if isNaN(close) then na else if(!adD_8_lines, na,-line1);
plot "-2"= if isNaN(close) then na else if(!adD_8_lines, na,-line2);
plot "-3"= if isNaN(close) then na else if(!adD_8_lines, na,-line3);
plot "-4"= if isNaN(close) then na else if(!adD_8_lines, na,-line4);

"1".SetDefaultColor(Color.DARK_GRAY);
"2".SetDefaultColor(Color.DARK_GRAY);
"3".SetDefaultColor(Color.DARK_GRAY);
"4".SetDefaultColor(Color.DARK_GRAY);
"-1".SetDefaultColor(Color.DARK_GRAY);
"-2".SetDefaultColor(Color.DARK_GRAY);
"-3".SetDefaultColor(Color.DARK_GRAY);
"-4".SetDefaultColor(Color.DARK_GRAY);


#---- Alerts
def CrossUp = Crosses(cciLine, p1);
def CrossDn = Crosses(cciLine, p2);
Alert(alerts and CrossUp, "CCI Crosses Upper Band", Alert.BAR, sound);
Alert(alerts and CrossDn, "CCI Crosses Lower Band", Alert.BAR, sound);


#--- END Code
 
this is the code, pls help to convert tradingview pine script to thinkorswim script :
from ( matsu_bitmex CCI and Bollinger Bands )
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
479 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