- Why the Standard MACD Indicator is Broken
- The Secret-Sauce: Automatic Higher Timeframe Detection
- Two Settings That Actually Make Sense
- How the Color Logic Actually Works
- Building It Step by Step
- Real Trading Applications
- The Three Settings You Should Test First
- What It Looks Like in Action
- Common Problems and How to Fix Them
- Making It Your Own
- Bonus: Smarter MACD Scans for ThinkOrSwim
Introduction
This is a continuation to our MACD video series. Watch Part 1 here.
The Moving Average Convergence Divergence (MACD) indicator is one of the most popular technical indicators used. The famous 12-26 settings can be recognized nearly anywhere.
However, the default MACD indicator that comes built-in to most charting platforms like ThinkOrSwim can often seem noisy and difficult to read.
In this post, I will walk you through how to build a Smarter MACD indicator from scratch in ThinkOrSwim. This customized MACD indicator simplifies the default MACD and makes it easier to determine trend direction at a glance.
By the end of this post, you’ll have a thorough understanding of how to build a more useful MACD indicator in ThinkOrSwim that better fits your personal trading style and needs.
Why the Standard MACD Indicator is Broken
If you’ve ever used the built-in MACD indicator in ThinkOrSwim, you already know the problem. You get a histogram, two different lines, a zero line, and a bunch of settings that make your head spin. The chart becomes cluttered and noisy, making it nearly impossible to make quick trading decisions.
The Smarter MACD indicator fixes this by taking all that messy information and turning it into one clean line that changes color. Green when momentum is bullish, red when it’s bearish. That’s it.
The Secret-Sauce: Automatic Higher Timeframe Detection
Here’s what makes this MACD different. Instead of just looking at your current chart timeframe, it automatically pulls data from a higher timeframe. The code uses ThinkOrSwim’s GetAggregationPeriod() function to figure out what timeframe you’re on, then grabs MACD data from the next level up.
Here’s exactly how the mapping works:
- If you’re on 1, 2, 3, or 4-minute charts → uses 5-minute data
- If you’re on 5 or 10-minute charts → uses 15-minute data
- If you’re on 15-minute charts → uses 30-minute data
- If you’re on 30-minute charts → uses hourly data
- And it scales all the way up to monthly using yearly data
This means when you’re scalping on a 2-minute chart, you’re actually seeing 5-minute MACD momentum. Way more reliable than the choppy signals you’d get from 2-minute MACD data alone.
Two Settings That Actually Make Sense
Most MACD indicators give you three or four confusing length settings. The Smarter MACD gives you two simple controls:
Lever: How quickly do you want to react to price changes? Fast uses 3/8 exponential averages for quick reactions. Medium sticks with the standard 12/26 exponential setup. Slow uses 10/20 simple averages for more stable signals.
Mode: How much confirmation do you want before the line changes color? Aggressive switches colors quickly. Conservative waits longer for confirmation.
Mix and match these settings and you get six different personalities for the indicator. Fast + Aggressive for day trading. Slow + Conservative for swing trading. Medium + Aggressive for most situations.
How the Color Logic Actually Works
The color changes aren’t random. The code creates two variables called “upSwitch” and “downSwitch” that track momentum changes. When the current MACD value is higher than the previous bar, upSwitch triggers and the line turns green. When it’s lower, downSwitch triggers and the line turns red.
The brilliant part is how it maintains these states. Once an upSwitch happens, the line stays green until a definitive downSwitch occurs. No more guessing about crossovers or trying to interpret histogram bars.
Building It Step by Step
We start with ThinkOrSwim’s built-in MACD code. You can find this by clicking the Studies icon, searching for MACD, then clicking the scroll icon to see the source code. Copy all that code into a new ThinkScript editor.
First, we delete everything below the “average” line since we don’t need the histogram or multiple outputs. Then we add the higher timeframe detection logic using a series of if/else statements that check your current timeframe and set the appropriate higher timeframe variable.
Next, we create the lever logic using a switch statement. Each case (fast, medium, slow) sets different values for fast length, slow length, and moving average type. The mode logic works similarly, determining how much smoothing to apply to the final output.
Finally, we add the trend detection variables and color assignments. The upSwitch and downSwitch logic gets plugged into the line color, and we increase the line weight to 2 so it’s easier to see on the chart.
Real Trading Applications
This indicator shines in trend reversal situations. Watch for color changes from red to green near support levels, or green to red near resistance. The higher timeframe data filters out most false signals.
For day trading, use Fast + Aggressive settings on lower timeframes. The 5-minute MACD data backing your 2-minute chart gives you the speed you need with better reliability than pure 2-minute signals.
Swing traders should start with Medium + Conservative. This combination catches major trend changes without getting chopped up in sideways markets.
The Three Settings You Should Test First
Based on testing different market conditions, these three combinations work best:
Fast + Aggressive: Perfect for day trading volatile stocks. You’ll get early signals but need to be quick on exits.
Medium + Aggressive: The sweet spot for most traders. Good balance of speed and reliability.
Slow + Conservative: For swing traders who want to catch big moves and don’t mind waiting for confirmation.
What It Looks Like in Action
Look at any strong trending stock and compare the settings. Take a stock that dropped hard then reversed – something like what happened with many tech stocks in 2022. The Fast + Aggressive setting would have caught the reversal early in the move. Medium + Conservative would have waited for more confirmation but still caught most of the upside. Slow + Conservative might have missed the early part but would have kept you in the trend longer.
Each setting has its place depending on your trading style and risk tolerance.
Common Problems and How to Fix Them
If the line isn’t changing colors, check that you’ve copied the switch statements correctly. The lever and mode variables need to properly update the length settings, or the color logic won’t work.
If the indicator seems slow or unresponsive, make sure your ThinkOrSwim platform has access to the higher timeframe data it needs. Sometimes you need to load a higher timeframe chart first to populate the data.
If you’re getting too many signals, try switching from Aggressive to Conservative mode. If you’re missing moves, try switching from Slow to Fast lever settings.
Making It Your Own
The code is designed to be modified. Don’t like the 3/8 settings for Fast mode? Change them to 5/13 or whatever works for your style. Want different timeframe mapping? Modify the GetAggregationPeriod logic to use 4-hour data instead of daily, or whatever makes sense for your trading.
You can also add more color states. Maybe yellow for extremely strong momentum, or orange for consolidation periods. The framework is there – just extend the logic.
The Smarter MACD takes one of the most popular but frustrating indicators and makes it actually useful. By automatically handling the timeframe analysis and simplifying the display, you can focus on what matters: making good trading decisions instead of trying to interpret complex signals.
Bonus: Smarter MACD Scans for ThinkOrSwim
The Smarter MACD scans are included for free with a Volatility Box membership. Click here to join.
#TOS Indicators
#Home of the Volatility Box
#Indicator Name: Smarter MACD
#Full tutorial here: tosindicators.com/indicators/smarter-macd
declare lower;
// ... 70 more lines ...Here are some resources that you may find useful: