Smarter MACD

Turn the basic MACD into a powerful indicator, with built-in higher time frame analysis and multiple levers and modes.

youtube-video-thumbnail
Note:

If you need help importing the indicator into ThinkOrSwim, here is a step-by-step tutorial which walks through the entire process.

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.

Smarter MACD Indicator for ThinkOrSwim

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.

 

Volatility Box Invite

We are TOS Indicators.com, home of the Volatility Box.

The Volatility Box is our secret tool, to help us consistently profit from the market place. We’re a small team, and we spend hours every day, after the market close, doing nothing but studying thousands of data points to keep improving and perfecting the Volatility Box price ranges.

We have two different Volatility Boxes - a Futures Volatility Box and a Stock Volatility Box.

Futures Volatility Box - Trade Major Markets With an Edge

Designed For: Futures, Micro-Futures and Index Market Traders
Supported Models: Hourly Volatility Box models
Supported Markets: 10 Major Futures Markets

The Futures Volatility Box comes with:

  • 5 Volatility Models for each market
  • Support for 10 Futures Markets (/ES, /NQ, /YM, /RTY, /CL, /GC, /SI, /ZB, /HG, /NG)
  • Video Setup Guide
  • Trade Plan
  • Access to all members-only resources, including Squeeze Course

Learn More About the Futures Volatility Box

Trade futures and micro futures with a consistent volatility edge

Stock Volatility Box - Powerful Web Based Volatility Platform

Designed For: Stock and Options Traders
Supported Models: Hourly and Daily Volatility Box models
Supported Markets: 10,000+ Stocks and ETFs (new markets added frequently)

A Stock Volatility Box membership includes access to: 

  • Live Scanner - A powerful scanner we've built from scratch, to scan 10,000 symbols every 2 seconds for new volatility breaches
  • Dashboard - A quick and easy way to view daily volatility model levels online
  • Short Interest Scanner - Short interest, Squeeze, and EMA data to find short squeezes
  • Squeeze Course - All of our proprietary squeeze tools, including robust backtesters
  • All Members Only Indicators - We don't nickel and dime you. Everything really is included.
  • And much more!

Learn More About the Stock Volatility Box

Trade stocks and options with a consistent volatility edge

Why Build a Smarter MACD Indicator?

The default MACD indicator outputs a lot of information - there is the MACD line itself, the signal line, the histogram, and the zero line. With so many outputs plotted on your chart, it can easily get noisy and difficult to interpret.

Additionally, the default MACD allows you to tweak many different settings like the fast length, slow length, and MACD average type. This allows for the infamous, analysis paralysis.

The goal of building a smarter MACD indicator is to simplify all of this information into one easy-to-read output line that clearly defines if price momentum is increasing or decreasing.

We want to build an indicator that answers two key questions for the trader:

  1. How reactive to price changes do you want the indicator to be?
  2. How long should the indicator wait for “confirmation” before determining a change in trend?

To accomplish this, we will build in user-adjustable “levers” that allow customization based on personal trading style.

 

Overview of Features

Here are some of the key features we will build into our custom Smarter MACD indicator:

  • Automatically references a higher timeframe's MACD value for more accuracy
  • User-adjustable "Lever" setting to control reactivity to price
  • User-adjustable "Mode" setting to control length of trend confirmation
  • Condense all information into a single easy-to-read colored line defining trend

Now let’s dive into ThinkOrSwim and start custom building our indicator!

 

Higher Time Frame Mapping

The first thing we want to do is have our indicator reference a higher timeframe's MACD value in its calculation, rather than just using the timeframe we are viewing. This makes the indicator more accurate, especially for very short-term charts.

We do this by creating a mapping that looks at whatever timeframe chart you have loaded, and references the next higher timeframe for its MACD calculation.

For example, if you are viewing a 1-minute chart, our indicator will reference the 5-minute chart's MACD.

Similarly, if you are viewing a 15-minute chart, it will reference the 30-minute chart's MACD.

This continues all the way up to referencing the monthly MACD if you are viewing the weekly chart, and the yearly if you are on a monthly time frame or higher.

Here is a link to all of the Aggregation Periods supported within thinkScript.

The code does this timeframe mapping automatically with the following:

def higherTF = if getAggregationPeriod() < AggregationPeriod.Five_Min then AggregationPeriod.Five_Min
else if getAggregationPeriod() < AggregationPeriod.Fifteen_Min then AggregationPeriod.Fifteen_Min
else if getAggregationPeriod() < AggregationPeriod.Thirty_Min then AggregationPeriod.Thirty_Min
else if getAggregationPeriod() < AggregationPeriod.Hour then AggregationPeriod.Hour
else if getAggregationPeriod() < AggregationPeriod.Day then AggregationPeriod.Day
else if getAggregationPeriod() < AggregationPeriod.Week then AggregationPeriod.Week
else if getAggregationPeriod() < AggregationPeriod.Month then AggregationPeriod.Month
else AggregationPeriod.Year;

We assign this to the closing price used in the MACD calculation, so now it is using our higher timeframe mapping, no matter what chart you are viewing:

def Value = MovingAverage(averageType, close(period = higherTF), fastLength) - MovingAverage(averageType, close(period = higherTF), slowLength);

This gives us accuracy in our MACD calculation on any timeframe, and lets us have built-in higher time frame analysis.

 

Adding User-Adjustable Levers

Now let’s add in user-adjustable “levers” that allow customization of the indicator based on personal trading style.

We will add two inputs that can be changed in the indicator settings:

  • Lever - Controls how reactive you want the indicator to be to price changes. Options are “Fast”, “Medium”, or “Slow”. Each option uses different length moving averages and average types.
  • Mode - Controls how long to wait for "confirmation" before determining a trend change. Options are “Aggressive” or “Conservative”. Each option uses different length for the average line

Based on what the user chooses for these options, the calculation of the MACD will change dynamically.

We set this up in code with:

input lever = {default "Fast", "Slow", "Medium"};
input mode = {default "Aggressive", "Conservative"};

def fastLength;
def slowLength;
def averageType;
switch(lever){
case "Fast":
   fastLength = 3;
   slowLength = 8;
   averageType = AverageType.Exponential;
case "Slow":
   fastLength = 10;
   slowLength = 20;
   averageType = AverageType.Simple;
case "Medium":
   fastLength = 12;
   slowLength = 26;
   averageType = AverageType.Exponential;
}

def outputLength;
switch(mode){
case "Aggressive":
   outputLength = fastLength;
case "Conservative":
   outputLength = slowLength;
}

Feeding this into our MACD calculation gives the user full control to customize it.

Condensing the Information into a Colored Line

Up to this point, we have a customized MACD that leverages higher timeframes and has user inputs. But the output is still just a typical MACD line, which can be hard to interpret.

To take this a step further, we want to condense all the information into a single colored line that clearly defines if momentum is increasing (green) or decreasing (red) to define trend.

We do this with the following code:

def upSwitch = if smarterMACD > smarterMACD[1] then 1 else if smarterMACD < smarterMACD[1] then 0 else upSwitch[1];
def downSwitch = if smarterMACD < smarterMACD[1] then 1 else if smarterMACD > smarterMACD[1] then 0 else downSwitch[1];
smarterMACD.AssignValueColor(if upSwitch then color.green else if downSwitch then color.red else color.gray);

And to make the line stand out more, we increase the thickness:

 
smarterMACD.setLineWeight(2);

Bringing It All Together

Now when you apply the complete indicator with all the code combined, you have a single colored line that tells you clearly whether upside or downside momentum is increasing.

It automatically references higher timeframes for accuracy, and you can customize the calculation to your trading style with the lever and mode selections.

The levers we built in for reactivity and trend confirmation are powerful for tailoring the analysis to different trading timeframes and risk preferences.

The end result is a MACD indicator simplified into an easy-to-use colored trend line!

You now have the building blocks to create a smarter customized MACD indicator in ThinkOrSwim tailored to your needs.

 

Bonus: Smarter MACD Scans for ThinkOrSwim

The Smarter MACD scans are included for free with a Volatility Box membership. Click here to join.

Table of Contents
    Add a header to begin generating the table of contents