MACD with Bollinger Bands Indicator for ThinkorSwim

BenTen

Administrative
Staff
VIP
This indicator (most people called it MACD BB) plots MACD along with the Bollinger Bands as a lower study on your ThinkorSwim chart. The usage is fairly simple and up for interpretation. You can use it to identify short term trends or search for squeeze.

Y5YNfKx.png

VuKsabx.png


thinkScript Code

Code:
# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# [email protected]
# Last Update 07 Feb 2011

declare lower;

input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;

def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);

plot MACD_Dots = MACD_Data;
plot MACD_Line = MACD_Data;

plot BB_Upper = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand;
plot BB_Lower = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband;
plot BB_Midline = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine;

BB_Upper.SetDefaultColor(Color.GRAY);
BB_Lower.SetDefaultColor(Color.GRAY);
BB_Midline.SetDefaultColor(Color.GRAY);
BB_Midline.SetStyle(Curve.SHORT_DASH);

MACD_Line.SetDefaultColor(Color.WHITE);

MACD_Dots.SetStyle(Curve.POINTS);
MACD_Dots.SetLineWeight(2);
MACD_Dots.AssignValueColor(if MACD_Line > MACD_Line[1] then Color.White

else Color.DARK_RED);

plot zero = 0;
zero.AssignValueColor(if MACD_Line < 0 then Color.RED else Color.GREEN);
zero.SetLineWeight(2);

Shareable Link

https://tos.mx/fK5Zaj

Note: The default Bollinger Bands indicator in ThinkorSwim uses the 20 Simple Moving Average with 2.0 Standard Deviation. If you want to keep it that way make sure you adjust the settings for this indicator.
 

adii800

Member
Does this come with the difference histogram like the stock MACD already available on the TOS platform?
Thanks!

Also, does it change between does the Macd dots switch between red and white depending on the slope of the Macd?
Thanks again :)
 

vijayonline

New member
VIP
Hi @BenTen thanks for sharing this indicator.. is there any way for you to write the code to add green or red arrow on the main chart to indicate bullish and bearish
 

vijayonline

New member
VIP
@BenTen bullish alert on the main chart when the dots on MACD signal line turns is white and the signal line is move upper band of BB, bearish alert on the main chart when the dots on MACD signal line turns iso red and MACD signal line is below the lower band of BB
 

BenTen

Administrative
Staff
VIP
@vijayonline Here you go:

Code:
# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
# http://www.thinkscripter.com
# [email protected]
# Last Update 07 Feb 2011

input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;

def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);

def MACD_Dots = MACD_Data;
def MACD_Line = MACD_Data;

def BB_Upper = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand;
def BB_Lower = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband;
def BB_Midline = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine;

def red_cond = !MACD_Line > MACD_Line[1];
def cond1 = MACD_Line > MACD_Line[1] and MACD_Line > BB_Upper;
def cond2 = red_cond and MACD_Line < BB_Lower;

# Plot Signals
plot bullish = cond1;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.GREEN);
bullish.SetLineWeight(1);
plot bearish = cond2;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.RED);
bearish.SetLineWeight(1);
 

vijayonline

New member
VIP
Thanks @BenTen for the quick response however there seem to be some problem its plotting green arrows continuously when the macD signal line stays above the upper BB also I see the bearish signal might need some work
 

BenTen

Administrative
Staff
VIP
@vijayonline I'm just following the conditions above. Feel free to point out what needs to change. If you can, please post some screenshots of your idea as well.
 

Filmic

New member
@BenTen Hello, you said that it is up for interpretation but I am curious how do the bollinger bands and the MACD line relate to each other? Thank you.
 

Nica33

New member
Hi @BenTen ...Wondering if this fits here or a new thread should be started. This is for a strategy to apply to 30 mins. chart:
Go long when price crosses above mid line of BB and RSI (14,exponential) is or crosses above 60, as long as price is above premarket high. If the crossing happened in premarket, it should trigger when price crosses above PM high. Apply only when price is above or crosses above EMA21.
Close position when price closes below an Exp. MA, i.e. 5 EMA
 
Last edited:

Hypoluxa

Well-known member
VIP
Ben...you're a genius with this indicator! I've been testing it for a week or so and put it to use this week. I've tweaked it with different timeframes 2/6/10 and each has a different setting since it needs to adjust for those timeframes - 2min is 20, 6min is 15 and the 10min is 12. For a put...I wait until all 3 have crossed below the bottom line of the Bollinger band and for a call all 3 need to be above the top line of the Bollinger band, I also use the MACD histogram for additional confirmation - that is set to 48/104/36 on each timeframe.

I'm 3 for 3 this week for $7500 profit. This indicator has made me become very patient, by waiting for the "perfect" moment when they have all crossed over.

Thank you for having the ability to see that indicators like this would be helpful!

Kbnmv0E.jpg
 

s1111

Active member
I used it today. seems to work as he said but I need patient. Being new to trading and FOMO I end up losing. Come Monday I won't get in trade until all there is a match. I also found a script and put it on a watchlist so , if all works then I can just check the watchlist to see which one is moving.
I like to thank usethinkscript community @BenTen and other coders, thank you @Hypoluxa for sharing those settings. I also use your dmi+/- a setting of 100. Learning every day to better self.

Here is some link of watchlist post of macd BB. Here are my watchlist and 10 minute chart macd BB lower settings.
 

germanburrito

Active member
@s1111 added red bands to keep yo out of the bollinger if you like.

Code:
# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
# [URL]http://www.thinkscripter.com[/URL]
# [EMAIL][email protected][/EMAIL]
# Last Update 07 Feb 2011

declare lower;

input price = close;
input BBlength = 10;
input BBNum_Dev = 1.0;
input MACDfastLength = 12;
input MACDslowLength = 26;
input MACDLength = 5;

def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);

plot MACD_Dots = MACD_Data;
plot MACD_Line = MACD_Data;

plot BB_Upper = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).UpperBand;
plot BB_Lower = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).Lowerband;
plot BB_Midline = reference BollingerBands(price = MACD_Line, length = BBlength, Num_Dev_Dn = -BBNum_Dev, Num_Dev_Up = BBNum_Dev).MidLine;

BB_Upper.SetDefaultColor(Color.GRAY);
BB_Lower.SetDefaultColor(Color.GRAY);
BB_Midline.SetDefaultColor(Color.GRAY);
BB_Midline.SetStyle(Curve.SHORT_DASH);

MACD_Line.SetDefaultColor(Color.WHITE);

MACD_Dots.SetStyle(Curve.POINTS);
MACD_Dots.SetLineWeight(2);
MACD_Dots.AssignValueColor(if MACD_Line > MACD_Line[1] then Color.White

else Color.DARK_RED);

plot zero = 0;
zero.AssignValueColor(if MACD_Line < 0 then Color.RED else Color.GREEN);
zero.SetLineWeight(2);


AddCloud( bb_Upper, bb_Lower, Color.light_RED );
 

Deltapants

New member
Do the tickers in the watchlist change based on scan results or are they always the same tickers? Thanks, everyone for putting this together
 

s1111

Active member
Do the tickers in the watchlist change based on scan results or are they always the same tickers? Thanks, everyone for putting this together
You can change them to whichever has the highest number to stay on top of the watchlist. I have my watchlist to show the highest amount change .
 
Last edited:

Similar threads

Top