Heiken-Ashi Moving Average (HAMA) for ThinkorSwim

Not much to say beyond the title. It is a strategy utilizing 3 HAMAs.

MxcZ1wn.png


Code:
# START
input paintBars = yes;
input length1 = 35;
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;

plot HAMA = Average(HAclose, length1);

HAMA.DefineColor("Up", GetColor(1));
HAMA.DefineColor("Down", GetColor(0));
HAMA.AssignValueColor(if HAMA > HAMA[1] then HAMA.color("Up") else HAMA.color("Down"));
# END

# START
input length2 = 70;


plot HAMA1 = Average(HAclose, length2);

HAMA1.DefineColor("Up", GetColor(1));
HAMA1.DefineColor("Down", GetColor(0));
HAMA1.AssignValueColor(if HAMA1 > HAMA1[1] then HAMA1.color("Up") else HAMA1.color("Down"));
# END

# START
input length3 = 100;


plot HAMA3 = Average(HAclose, length2);

HAMA3.DefineColor("Up", GetColor(1));
HAMA3.DefineColor("Down", GetColor(0));
HAMA3.AssignValueColor(if HAMA3 > HAMA3[1] then HAMA3.color("Up") else HAMA3.color("Down"));
# END

def GreenPrice = HAMA > HAMA[1] and HAMA1 > HAMA1[1] and HAMA3 > HAMA3[1];
def RedPrice = HAMA < HAMA[1] and HAMA1 < HAMA1[1] and HAMA3 < HAMA3[1];

plot Bullish = GreenPrice;
plot Neutral = !GreenPrice and !RedPrice;
plot Bearish = RedPrice;

Bullish.SetDefaultColor(Color.UPTICK);
Bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bullish.SetLineWeight(3);
Bullish.hide();
Neutral.SetDefaultColor(Color.BLUE);
Neutral.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Neutral.SetLineWeight(3);
Neutral.hide();
Bearish.SetDefaultColor(Color.DOWNTICK);
Bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
Bearish.SetLineWeight(3);
Bearish.hide();

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"));


addOrder(OrderType.BUY_AUTO, Bullish);
addOrder(OrderType.SELL_TO_CLOSE, Neutral);
addOrder(OrderType.SELL_AUTO, Bearish);
addOrder(OrderType.BUY_TO_CLOSE, Neutral);
 
@tenacity11 - this chart looks amazing to me as far a potential entry/exit signals. I also like the other indicators you have on there. any chance you have a TOS grid with these studies? Thanks. Joe
 
@Nicholas Correct. All backtesting strategies in ThinkorSwim are for testing only. The platform does not support auto trading.
 
@Nicholas Correct. All backtesting strategies in ThinkorSwim are for testing only. The platform does not support auto trading.
Thank you. Yes I’m using this strategy /MES, 3/3 day green.... today 740am-840 very choppy , 930-934 caught 10 points...
I’m using HAMA weighted 35/111/200
 
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

Code:
#HK
#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);
anyway to scan for this?
 
anyway to scan for this?
Heiken Ashi Transition Scan
Shared Scan Link: http://tos.mx/UPqddCS Click here for --> Easiest way to load shared links
ZNz44D1.png

Ruby:
#HK SCAN ONLY
#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;

plot scan =  hatransition;
 
@HighBredCloud Per your request here's a version of SuperTrend using Heiken Ashi from Mobius. Please enjoy this!

Code:
# 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.SetHiding(!PlotLine);
SuperTrend.AssignValueColor(if close < ST then Color.RED else Color.GREEN);
SuperTrend.SetPaintingStrategy(PaintingStrategy.Line);
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;
ST_point.SetStyle(Curve.Points);
ST_point.SetLineWeight(3);
ST_point.SetDefaultColor(Color.Yellow);
# End Code SuperTrend HeikenAshi
Thank you for posting this code. I managed to add vertical lines as an additional visual confirmation with

addverticalLine( if ST > ST [1] then high else double.nan, "B U Y", color.green, curve.firm);
addverticalLine( if ST < ST [1] then low else double.nan, "S E L L", color.RED, curve.firm);

This add-on paints lines for every candle, to the right side of the candle. Is it possible to change the code to draw vertical line once per color change and to the left side of the candle? An option to add audible alert would be awesome. Thanks in advance for your time.

Managed to add audible alert with

Alert((ST > ST [1]) or ( ST < ST [1]), "ST Color Change", Alert.BAR, Sound.RING);. The recurring vertical line problem eludes me.
 
Last edited:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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