Heiken-Ashi Moving Average (HAMA) for ThinkorSwim


Active member
2019 Donor
I'm looking for the HAMA Heiken Ashi indicator for ThinkorSwim. Can anyone help me find it?

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

@MBF Here is a Heiken Ashi Moving Average study you may like to check out.

Feel free to edit the length of the moving average to suit your requirements:

def length = 8;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
HAclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen then Color.GREEN else color.RED);
plot HAMA = Average(HAclose, length);
Last edited:
Heikin Ashi concept is very interesting . In essence its 2 period smoothing of price action, which visually represents what actually happens in trend better than individual candles. However it can be misleading when used in some timeframes. Back to your question. There is this study I made while playing with HKA - it color candles pink when there is HKA trend transition. It can be used both on regular and HKA charts

#Use bar to figure trendDown or confirm.
#heikin ashi bars. close=OHLC/4.  open=1/2(open[1]+close[1])  and HA trend
def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def hahigh=max(open,max(close,high));def halow=min(open,min(close,high));

def HAtrendUP  = haclose > haclose[1];
def upBar = if HAtrendUP then upBar[1] + 1 else 0;
def HATrendDown = haclose <= haclose[1];
def downBar = if HATrendDown then downBar[1] + 1 else 0;
def bars = upBar + downBar;
#the one with body small relative to wicks . let say less than 0.3
def HAtransition=absvalue((haopen-haclose)/(hahigh-halow))<0.3;
def HARed = HAOpen > HAclose;
def HAGreen = !HARed;
def HADecidedRed = HARed and HAHigh == HAopen;
def HADecidedGreen = HAGreen and HAlow == HAOpen;

plot data=0;
AssignPriceColor( if hatransition then color.MAGENTA
    else Color.CURRENT);
Yeah it looks good . Like every trending chart does : ) . The issue with trends is that its not hard to identify and paint them postfactum with all the nice entries. I wrote dozens of indicators which do that with 99% accuracy on trending stocks (without repainting). Key is how to get something which will NOT show the signals on things which do not result in trends. Most losses comes from the chop. So indicators which shows trends with 100% accuracy is pretty worthless when it also shows non-trends often. As most price movement is chop odds of getting into chop are very high to start with

p.s. I am now of opinion that inidcator based on the single timeframe can never do that. In fact probably no indicator can do that with high probability if its single timeframe, price action based only. There are other factors which determine that.
I really get that but, say you were to apply the RVOL condition? Knowing that a stock will trend one way the other might be helpful in at least picking stocks for the day that have a higher probability to trend.
Since you mentioned SMB capital ( I watched their videos a lot) - its what they call "stocks in play". Stocks with catalyst, and rvol etc. One problem with RVOL in TOS - it doesn't have one. You need something which will show relative volume AT TIME OF DAY compared to average volume done at this time of day. And yeah playing stock in play increased the odds of "something" happening. However what actually happens - it might be varied chop and then trend. it might be trend which is gone and done by 945 and then chop. It might be both way fakeouts and then sqz sideways. Many things. So you would narrow down to "something happening" (maybe!) but still problem of knowing when trend starts and not of various fakeouts/chops remains.

I been doing stocks in play for a while now - its far from easy! (at least for me)
@skynetgen Right now that is about all I can play. I have been trying to find a decent RVOL on TOS. I just don't get how they have all these complicated scripts or cool scripts but can't find a decent RVOL. THAT is my most complicated area right now is finding stocks to play. I need high IV or at least a very liquid stock that trades $60 and below ATM. Drives me nuts!
To find stocks in play I use simply premarket gapper approach . Filtering by price, capitalization and average volume per day (to weed out penny and/ or illiquid stocks). Out of average 15-30 names which pop on scanners 2-4 stocks I pick have at least one mover "stock in play". That is done premarket so I don't have to scramble with scans intraday

Here is this very simple scan: https://tos.mx/WXUxaCb

Another proxy for stocks in play I use is sizzle index. (>2 is wide critera, >5 picks something with big catalyst practically every day)
Thank you @skynetgen! I don't really understand that last part, (>2 is wide critera, >5 picks something with big catalyst practically every day).
If you add stocks to your watchlist and add sizzle index column just sort by it . - indicates increased activity - basically a proxy to relvol (very often you will see significantly increased volume on those stocks).

There is small bug here (uses close instead of haclose). Anyhow this HA code works better than one I was using before. Integrated it with my transition code https://tos.mx/aA77lzO
  • Love
Reactions: MBF
Here is the revised code:

def length = 8;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
HAclose = (HAopen + HAclose[1] + HAlow + close) / 4;
AssignPriceColor(if HAclose > HAopen then Color.GREEN else color.RED);
plot HAMA = Average(HAclose, length);
This is a comparison I did using the HA_MA 10 with the VWMA 10. The green line is the HA_MA and the cyan/brn line is the VWMA




  • RrvvZ9z.png
    154.9 KB · Views: 80
  • RrvvZ9z.png
    154.9 KB · Views: 109
following this...From my testing thus far of various SuperTrends...its hard to beat good ole Heikin Ashi...What I am wondering about tho is if anyone was able to make a SuperTrend based on Heikin Ashi but to use regular candles? I have seen many that overlap regular candles with Heikin Ashi candles...but that's not the same as Heikin Ashi trend on regular candles...
@HighBredCloud Per your request here's a version of SuperTrend using Heiken Ashi from Mobius. Please enjoy this!

# Mobius
# SuperTrend HeikenAshi
# V03.10.2015
# Up = (HIGH + LOW) / 2 + Multiplier * ATR
# Down = (HIGH + LOW) / 2 – Multiplier * ATR
# When the change of trend occurs, the indicator flips

input AtrMult = .70;
input nATR = 4;
input AvgType = AverageType.HULL;
input PaintBars = yes;
input BubbleOn = no;
input ShowLabel = no;
input AlertOn = no;
input PlotLine = no;

def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close) / 2);
HAhigh = Max(high, close[1]);
HAlow = Min(low, close[1]);
haclose = (HAopen + HAclose[1] + HAlow + close) / 4;
def v = volume;
def bar = barNumber();
def EOD = if SecondsTillTime(1545) == 0 and
             SecondsFromTime(1545) == 0
          then 1
          else 0;
def NotActive = if SecondsFromTime(1545) > 0
                then 1
                else 0;
def ATR = MovingAverage(AvgType, TrueRange(HAhigh, HAclose, HAlow), nATR);
def UP = HL2 + (AtrMult * ATR);
def DN = HL2 + (-AtrMult * ATR);
def ST = if close < ST[1]
         then Round(UP / tickSize(), 0) * tickSize()
         else Round(DN / tickSize(), 0) * tickSize();
plot SuperTrend = ST;
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
AssignPriceColor(if PaintBars and close < ST
                 then Color.RED
                 else if PaintBars and close > ST
                      then Color.GREEN
                      else Color.CURRENT);
plot ST_point = if isNaN(close[-1])
                then ST
                else double.nan;
# End Code SuperTrend HeikenAshi
@tomsk OK...so I was able to test out the Heiken Ashi SuperTrend script you provided earlier...I have not seen this particular one yet so thank you for providing it here as it does come very useful for what I want to do next, however, it does not seem to follow the exact Heiken Ashi trend...Please refer to the pic...Perhaps I need to adjust the settings in order for the SuperTrend to read exactly as the Heikin Ashi...? I don't know.


I have seen scripts where actual Heiken Ashi candles appear and overlay the regular candles sticks...its not what I am looking for but am curious if somehow instead of just overlaying the regular candles with Heiken Ashi...the regular candles can just be painted in the Heikin Ashi trend instead. Any ideas on this would be helpful...

This is what I had in mind:

1. Heikin Ashi Trend on regular candlesticks by painting the bars.
2. Create an indicator as the one pictured below that allows you to run no more than 3 popular SuperTrends, such as the one you shared above, simultaneously.


@netarchitech This is what I was referring to in post #208 as something for you to keep in mind while you work on the MACD...FREMA...PPO indicator in that same format.

I figured I would post here to keep it relevant and to make it easy to find for others...Save @BenTen the trouble of moving the thread.

@skynetgen There are so many SuperTrend type indicators out there just on this site alone...and I find that they still work slightly differently than others in their default settings...I actually wanted to see IF there is a way to do what I described in post #21...

In regards do time frames and SuperTrends...I am currently testing a SuperTrend code by Mobius that allowed for time aggregation...So in my case on a 5 min chart I set the SuperTrend to paint the candlesticks as if on a 15 min chart. The problem that I had was when the 15 min chart started to repaint the candle bar within the 15 min timespan 3 of the candlesticks on the 5 min time frame also repainted, naturally. This was a bit confusing to me as what was once thought of a "trend" quickly became a question of a pullback or a reversal.

I still find that original Heikin Ashi works the best as far as the trend goes...perhaps there are other SuperTrends that I have not seen yet...I know @tomsk provided a script above that I've not seen yet...I reviewed it again and changed the setting from .7 to .4 and the candles resemble Heikin Ashi more...but I wasn't able to see if that script repaints a lot or not.

I would be very curious to see how something described in post #21 would play out...but with SuperTrends focusing on different aspects...such as price...Have you seen the Price Trend Indicator?


  • mJ6XWgi.png
    387.5 KB · Views: 55
  • mqFIvAD.png
    364.8 KB · Views: 58
I don't remember who did it (maybe tomsk) but there is working MTF ST script which does not repaint. Nor HKA nor ST are magical even with MTF though. Integrating the signals into stock picking and execution process is still a crux of a problem. I experimented with hundreds of indicators in complex combination, combined with scanners- its not easy to get a reliable combo. You can find something which works extremely well in certain conditions and produce a lot of false signals in other condition.

Regarding MTF - I already run 2-3 timeframes windows in my analysis so its usually not really necessary to have MTF on a single timeframes

I like ST - its one of better price action based indicators imho, especially as confirmation for some finer grainer entry indicators. HKA is useful in certain ways - I like to use it for trend transition and trend visualization when I don't care about precision and entries. But honestly I can achieve similar results just using multiple moving averages system.

What is the "price trend" indicator you mentioned?
Last edited:
@skynetgen Agreed...I have seen several as you mentioned...Some are better than others...some repaint more than others etc. Now I am curious to see if it was @tomsk who posted that SuperTrend as you thought...I don't have any experience how such SuperTrends react with scanners...that's not something I have experience in.

Here is the Price Trend "SuperTrend"

# Price Trend
# Drew Griffith

#hint: Color candlesticks based on price movement. New highs are green; New lows are red; Sideways trading are grey.

declare upper;

input trail = 1;
input displace = 1;
input aggregationperiod = aggregationperiod.day;

def new_high = close > highest(high(period = aggregationperiod), trail)[displace];
def new_low = close < lowest(low(period = aggregationperiod), trail)[displace];

def greenprice = if new_high then yes else if new_low then no else new_high[1];
def redprice = if new_low then yes else if new_high then no else new_low[1];

plot bullish = greenprice;
plot neutral = !greenprice and !redprice;
plot bearish = redprice;

plot rating =
if greenprice then 1
else if redprice then .5
else 0;

def paintbars = yes;


defineglobalcolor("bullish", color.uptick);
defineglobalcolor("neutral", color.gray);
defineglobalcolor("bearish", color.downtick);
assignpricecolor(if !paintbars then color.current else if greenprice then globalcolor("bullish") else if redprice then globalcolor("bearish") else globalcolor("neutral"));

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
264 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.