#
https://usethinkscript.com/threads/macd-with-bollinger-bands-indicator-for-thinkorswim.287/
# 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;
input ERGODICLongLength = 2;
input ERGODICShortLength = 10;
input ERGODICSignalLength = 36;
input ERGODICAverageType = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};
input ShowMACDDots = No;
def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);
# plot MACD_Dots = MACD_Data;
# Ergodic
def Ergodic_Data = ErgodicOsc("long length" = ERGODICLongLength, "short length" = ERGODICShortLength, "signal length" = ERGODICSignalLength, "average type" = ERGODICAverageType).ErgodicOsc;
# def Ergodic_Max = Max(Ergodic_Data);
def Ergodic_Data_Max = Max(Ergodic_Data, TickSize());
def MACD_Data_Max = Max(MACD_Data, TickSize());
#Normalize MAC and Ergodic scales
def ERGO_Scale = StDev(MACD_Data) / StDev(Ergodic_Data);
plot eo = Ergodic_Data * ERGO_Scale;
eo.AssignValueColor(if Ergodic_Data < 0 then Color.RED else Color.GREEN);
eo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
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_Line.AssignValueColor(
if MACD_Line > 0 then if MACD_Line > MACD_Line[1] then Color.GREEN else Color.DARK_GREEN
else if MACD_Line < 0 and MACD_Line > MACD_Line[1] then Color.DARK_RED else Color.RED);
#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 eoDots = eo;
eoDots.SetStyle(Curve.POINTS);
eoDots.SetLineWeight(2);
eoDots.AssignValueColor(if eo > eo[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);