Fast and Slow HMA for Trends & Chop In ThinkOrSwim

Ban-Bet

New member
I primarily trade trends and reversals intraday. A problem that I would find myself running into frequently was beginning my day having missed the beginning of a trend and then trying to get a reversal entrance before there was a meaningful breakdown in trend quality to support a reversal entrance. My next problem was that I would exit trades well before there was a meaningful reason to do so.

I wanted to make an indicator that would help to identify the current trend direction and quality, my requirements were that I didn't want anything that would be visually overwhelming/clutter my charts (like having lots of moving averages plotted) and that I could immediately interpret even from a distance to understand the current market bias/direction. I ultimately wanted something simple and readable while still being customizable to the market conditions

I ended up settling on two HMA on different lengths, a fast HMA that would plot early signs of trend weakening and a long HMA that would plot the bigger momentum in action. I pair it with bollinger bands to help identify chop vs trend market conditions to decide if I need early trend direction indicators (i.e. we're chopping and the Fast HMA should be used as the lead in determining direction) or if I need to wait until there is a meaningful breakdown in trend quality before I enter/exit (i.e. we're trending and the Slow HMA should be used as the lead in determining direction). The Chop option can also be used if you're more of a scalper and the Trend if you're more of a momentum-er.
HMA Trend.png

This is a screenshot showing what the trend condition recolors as using a 2000 tick chart

HMA Chop.png

This is a screenshot that shows how the chop conditions recolor on a 2000 tick chart

You can of course change the fast and slow lengths to whatever your preference is for your strategy and can use it on what ever time frame that you typically use, although please optimize the settings to capture your trading strategy and style best. The bright red and cyan areas indicate strong trend directions while the muted red and cyan indicates weakening (this alters depending on if you've chosen Chop or Trend market conditions).

Code:
############################################################
# Fast and Slow HMA Oscillator - Trend and Chop Conditions #
############################################################

# Last updated 6/12/2025

# Trend: Ideal for identifying longer enduring changes in trend direction, also helpful if you're trying to capture longer trades
# Chop: Ideal for identifying early changes in trend within a range bound/choppy market, also helpful if you're scalping

############
# Fast HMA
############

input colorBars = yes;
input showMarketBiasLabel = yes;
input MarketConditions = {default Trend, Chop};

input HMAFastprice = HL2;
input HMAFast_Length = 22;

def FastHMA = HullMovingAvg(price = HMAFastPrice, length = HMAFast_Length);

def FastHMAUp = FastHMA > FastHMA[1];
def FastHMADown = FastHMA < FastHMA[1];

############
# Slow HMA
############

input HMASlowprice = HL2;
input HMASlow_Length = 80;

def SlowHMA = HullMovingAvg(price = HMASlowprice, length = HMASlow_Length);

def SlowHMAUp = SlowHMA > SlowHMA[1];
def SlowHMADown = SlowHMA < SlowHMA[1];

############
# Colors
############

DefineGlobalColor("StrongCyan" , CreateColor(33, 166, 153));
DefineGlobalColor("MutedCyan" , CreateColor(24, 104, 96));
DefineGlobalColor("StrongRed" , CreateColor(166, 38, 51));
DefineGlobalColor("MutedRed" , CreateColor(104, 24, 32));

def isrealtime = !isNaN(close);
def signalcolor;

switch(MarketConditions) {
case Trend:
  signalcolor = if isrealtime then
  if (SlowHMAup) and (FastHMAUp) then 2 else
  if (SlowHMAup) and (FastHMADown)  then 1 else
  if (SlowHMADown) and (FastHMADown) then -2 else
  if (SlowHMADown) and (FastHMAUp)  then -1 else signalcolor[1] else signalcolor[1];

case Chop:
  signalcolor = if isrealtime then
  if (SlowHMAUp) and (FastHMAUp) then 2 else
  if (SlowHMADown) and (FastHMAUp)  then 1 else
  if (SlowHMADown) and (FastHMADown) then -2 else
  if (SlowHMAUp) and (FastHMADown)  then -1 else signalcolor[1] else signalcolor[1];
}

############
# Bias Labels
############

AddLabel(showMarketBiasLabel,
    if signalcolor == 2 then "Strong Bullish Bias" else
    if signalcolor == 1 then "Weak Bullish Bias" else
    if signalcolor ==-2 then "Strong Bearish Bias" else
    if signalcolor ==-1 then "Weak Bearish Bias" else "No Bias",
    if signalcolor == 2 then Color.GREEN else
    if signalcolor == 1 then Color.DARK_GREEN else
    if signalcolor ==-2 then Color.RED else
    if signalcolor ==-1 then Color.DARK_RED else Color.GRAY);

############
# Recolor Bars
############

AssignPriceColor(if !colorBars then Color.CURRENT else
    if signalcolor == 2 then GlobalColor("StrongCyan") else
    if signalcolor == 1 then GlobalColor("MutedCyan") else
    if signalcolor == -2 then GlobalColor("StrongRed") else
    if signalcolor == -1 then GlobalColor("MutedRed") else Color.GRAY);

# End of Code
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
476 Online
Create Post

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