MACD with HMA For ThinkOrSwim

BillW

Member
VIP
One way of interpreting MACD with HMA​

We know using HMA on MACD is kind 'a weird. But using it with Wilders Histogram can make it useful when looking at what happens when the hull value AVG cross in relation to the histogram.
I've included a couple of moving averages that are included in the shared style link. (IMO) SuperSmootherFilter with a period of 50 is a better (smoother) than the tried and true 20 period SMA. Hann moving average is included too.

I always recommend watching something that is new to you for a few days. Don't be a noob and fall in love with hindsight.

mod note:
see another version here:
https://usethinkscript.com/threads/macd-with-hma-for-thinkorswim.21795/#post-157995

and upper chart version here:
https://usethinkscript.com/threads/macd-with-hma-for-thinkorswim.21795/#post-158001

https://tos.mx/!vg023o8Y
Screen Shot 11-11-25 at 01.49 PM.jpg




Code:
# MACD HULL with Wilders Histogram

declare lower;

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(CreateColor(0, 0, 0));

input colorNormLength1 = 2;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.HULL;
input showBreakoutSignals = no;
plot Value = MACD(fastLength, slowLength, MACDLength, averageType).Value;
plot Avg = MACD(fastLength, slowLength, MACDLength, averageType).Avg;

Value.DefineColor("Highest", CreateColor(127, 255, 255)) ;
Value.DefineColor("Lowest", CreateColor(128, 0, 255));
Value.AssignNormGradientColor(colorNormLength1, Value.Color("Lowest"), Value.Color("Highest"));
Value.HideBubble();

Avg.DefineColor("Up", CreateColor(200, 200, 0)) ;
Avg.DefineColor("Down", CreateColor(0, 200, 200)) ;
Avg.DefineColor("Flat", Color.GRAY);
Avg.HideBubble();

Avg.AssignValueColor(if Avg[0] > Avg[1] then Avg.Color("Up") else if Avg[0] <
Avg[1] then Avg.Color("Down") else Avg.Color("Flat"));

plot Diff = Value - Avg;

diff.hide();

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);

Alert(UpSignal == ZeroLine, "Up Arrow Alert", Alert.BAR, Sound.Chimes);
Alert(DownSignal == ZeroLine, "Down Arrow Alert", Alert.BAR, Sound.Chimes);

input fastLength2 = 12;
input slowLength2 = 26;
input MACDLength2 = 9;
input averageType2 = AverageType.Wilders;

plot Diff2 = MACD(fastLength2, slowLength2, MACDLength2, averageType2).Diff *1;

Diff2.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff2.SetLineWeight(3);
Diff2.DefineColor("Positive and Up", CreateColor(44, 139, 53));
Diff2.DefineColor("Positive and Down", CreateColor(130,139, 44));
Diff2.DefineColor("Negative and Down", CreateColor(53, 44, 139));
Diff2.DefineColor("Negative and Up", CreateColor(139,44,130));

Diff2.AssignValueColor(if Diff2 >= 0 then if Diff2 > Diff2[1] then Diff2.color("Positive and Up") else Diff2.color("Positive and Down") else if Diff2 < Diff2[1] then Diff2.color("Negative and Down") else Diff2.color("Negative and Up"));
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Can this be done? This isn't a crossover, but rather a 'peak and valley,' yes, I know it will repaint until bar closes.
I'd like to see a script that will print an arrow based on the arrow of lower indicator.

This script is from "The Thinkscript Collection" https://usethinkscript.com/threads/...ipt-your-one-stop-research-shop.300/post-5057

Code:
#MACD based on Hull Moving Average W/peak/ebb arrows
#TOS title = MACD_via_Hull_MA_fav

declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, EMA, default HULL};

plot Value;
plot Avg;
switch (AverageType) {
  case SMA:
    Value = Average(close, fastLength) - Average(close, slowLength);
    Avg = Average(Value, MACDLength);
  case EMA:
    Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
    Avg = ExpAverage(Value, MACDLength);
  case HULL:
    Value =  MovingAverage(AverageType.HULL, close, fastLength) -  MovingAverage(AverageType.HULL, close, slowLength);
    Avg = Average(Value, MACDLength);
}

plot Diff = Value - Avg;
plot ZeroLine = 0;
Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

#*********plot Min arrows**********
def MinArrow = if (Value < Value[1] and value[1] < Value[2] and value[2] < Value[3] and value[-1] > Value and value < 0)
  then 0
  else if (Value > Value[1])
  then double.nan
  else double.nan;

plot UpArrow = if(MinArrow == 0, value, double.nan);
UpArrow.AssignValueColor(Color.Green);
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetLineWeight(1);
UpArrow.HideBubble();

#*********plot Max arrows**********
def MaxArrow = if (Value > Value[1] and value[1] > Value[2] and value[2] > Value[3] and value[-1] < Value and value > 0)
  then 0
  else if (Value > Value[1])
  then double.nan
  else double.nan;

plot DwnArrow = if(MaxArrow == 0, value, double.nan);
DwnArrow.AssignValueColor(Color.cyan);
DwnArrow.SetPaintingStrategy(PaintingStrategy.ARROW_Down);
DwnArrow.SetLineWeight(1);
DwnArrow.HideBubble();

#*********plot Max signal(Avg) arrows**********
def SignalArrow = if (Avg > Avg[1] and Avg[1] > Avg[2] and Avg[2] > Avg[3] and Avg[-1] < Avg and Avg > 0)
  then 0
  else if (Avg > Avg[1])
  then double.nan
  else double.nan;

plot downSignalArrow = if(SignalArrow == 0, avg, double.nan);
downSignalArrow.AssignValueColor(Color.yellow);
downSignalArrow.SetPaintingStrategy(PaintingStrategy.ARROW_Down);
downSignalArrow.SetLineWeight(1);
downSignalArrow.HideBubble();

AddCloud(ZeroLine, Value, color.RED, color.GREEN);


Screen Shot 11-15-25 at 04.25 PM.jpg
 
below is a trimmed ThinkScript that keeps the original MACD-via-HULL logic but draws the three arrows on the price (upper) chart
aPAmHBf.png

Ruby:
# MACD_via_Hull_MA_fav — arrows only on price chart
# Plots: UpArrow (green) for Value minima, DwnArrow (cyan) for Value maxima,
# and downSignalArrow (yellow) for Avg maxima — positioned on price pane.

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, EMA, default HULL};

def Value;
def Avg;
switch (AverageType) {
    case SMA:
        Value = Average(close, fastLength) - Average(close, slowLength);
        Avg = Average(Value, MACDLength);
    case EMA:
        Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
        Avg = ExpAverage(Value, MACDLength);
    case HULL:
        Value = MovingAverage(AverageType.HULL, close, fastLength) - MovingAverage(AverageType.HULL, close, slowLength);
        Avg = Average(Value, MACDLength);
}


def MinArrow = Value < Value[1] and Value[1] < Value[2] and Value[2] < Value[3] and Value[-1] > Value and Value < 0;
def MaxArrow = Value > Value[1] and Value[1] > Value[2] and Value[2] > Value[3] and Value[-1] < Value and Value > 0;
def SignalArrow = Avg > Avg[1] and Avg[1] > Avg[2] and Avg[2] > Avg[3] and Avg[-1] < Avg and Avg > 0;

plot UpArrow = MinArrow ;
UpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpArrow.SetDefaultColor(Color.GREEN);
UpArrow.SetLineWeight(2);
UpArrow.HideBubble();

plot DwnArrow = MaxArrow ;
DwnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DwnArrow.SetDefaultColor(Color.CYAN);
DwnArrow.SetLineWeight(2);
DwnArrow.HideBubble();

plot downSignalArrow = SignalArrow ;
downSignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downSignalArrow.SetDefaultColor(Color.YELLOW);
downSignalArrow.SetLineWeight(2);
downSignalArrow.HideBubble();
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
549 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top