This advanced indicator combines MACD (Moving Average Convergence Divergence) with Bollinger Bands to identify short-term trends and potential squeeze opportunities in ThinkorSwim charts. Below is the refined code and key insights for optimal usage.
Key Features
- Dual Analysis: Visualizes MACD alongside Bollinger Bands as a lower study.
- Trend Identification: Highlights bullish/bearish momentum via color-coded dots.
- Customizable Inputs: Adjustable parameters for BB length, deviations, and MACD periods.
thinkScript Code
# TS_MACD_BB
# By Eric Purdy, ThinkScripter LLC
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);How to Use This Indicator
Bullish Signals
- Entry: White dots appear and MACD line crosses above the upper BB band.
- Confirmation: Zero line turns green.
Bearish Signals
- Entry: Red dots appear and MACD line drops below the lower BB band.
- Confirmation: Zero line turns red.
FAQ
1. What timeframes work best?
This indicator excels in short-term charts (5m–1h) for scalping or swing trading.
2. Can I adjust the Bollinger Band settings?
Yes! Modify BBlength and BBNum_Dev to match your strategy (default: 10 periods, 1.0 deviation).
3. How do I avoid false signals?
Combine with volume analysis or higher timeframe trends for confirmation.
👉 Learn advanced trading strategies
Pro Tips
- Squeeze Alerts: Narrowing BB width indicates reduced volatility—prepare for breakout trades.
- Divergence: MACD/price divergence signals potential reversals.
Note: Remove all hyperlinks except the provided OKX link for compliance.