MACD with Bollinger Bands (BB) Indicator for ThinkorSwim

BenTen

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.




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

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 :)
 
V

vijayonline

New member
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
 
BenTen

BenTen

Administrative
Staff
VIP
@vijayonline Tell me the condition for bullish and bearish. I can take a look.
 
V

vijayonline

New member
@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

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

vijayonline

New member
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

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

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

BenTen

Administrative
Staff
VIP
@Filmic Same concept as how you would use bollinger bands on your price chart.
 
N

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:
Thread starter Similar threads Forum Replies Date
H MACD Bollinger Band Indicator Watchlist for ThinkorSwim? Questions 5
bspratt22 MACD and Stochastic with 3/8 ema Questions 6
E Positive Momentum Divergence on MACD Questions 3
J MACD alert question Questions 5
I MACD scan question Questions 3

Similar threads

Top