Heikin_Ashi Indicator For ThinkOrSwim

Hey this is an extremely useful indicator but I am trying to scan for the trend reversal and I can't quite figure out how to do so, any help would be much appreciated.
 
could you share the link to the chart with all indicators please? Thanks for you help.
@alexR This is the lower Code...

Code:
#BonBon - Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update 2/1/2021, Jan 17th 2021,
#Influenced by script from HoboTheClown / blt,[URL]http://www.thinkscripter.com[/URL], TD Hacolt etc., Thinkscript Cloud, TOS & Thinkscript Collection
#update 1/2/21 - changed the default moving average to TEMA.  Changed the period to 35.
#update changed reversal arrows to reversal bubbles with price
#PLEASE DO NOT REMOVE THE HASHTAGS!!!! ONLY REMOVE THEM IF YOU PLAN ON USING THAT PARTICULAR SIGNAL. THERE ARE 3 DIFFERENT SIGNALS IN THE SCRIPT!!!!! IF YOU REMOVE ALL THE HASHTAGS YOU WILL HAVE NUMEROUS SIGNALS ON YOUR CHART!!!!!!!!!


declare lower;

input UsePeriod5 = AggregationPeriod.FIVE_MIN;
input UsePeriod15 = AggregationPeriod.FIFTEEN_MIN;
input UsePeriod30 = AggregationPeriod.thirty_MIN;
input UsePeriod60 = AggregationPeriod. HOUR;
input UsePeriod4hr = AggregationPeriod. FOUR_HOURS;
input UsePeriodday = AggregationPeriod.DAY;

input  Con_Cri = 3;

input Main_Heikin_Plot = Yes;


#Timeframe1 5 min

def aOpen5 = open(period = UsePeriod5);
def aClose5 = close(period = UsePeriod5);
def aHigh5 = high(period = UsePeriod5);
def aLow5 = low(period = UsePeriod5);

def haClose5 = (aOpen5 + aClose5 + aHigh5 + aLow5) / 4;
def haOpen5 = (haOpen5[1] + haClose5[1]) / 2;

def trend5 = if haClose5 >= haOpen5 then 1 else if haClose5[1] < haOpen5[1] then -1 else 0;
plot HA_Up5 = if IsNaN(UsePeriod5) then Double.NaN else 6;
HA_Up5.SetPaintingStrategy(PaintingStrategy.POINTS);#SetStyle(curve.Points);
HA_Up5.AssignValueColor(if haClose5 >= haOpen5 then Color.GREEN else if haClose5[1] < haOpen5[1] then Color.RED else Color.CURRENT);
HA_Up5.SetLineWeight(4);
############################################

#Timeframe2 15 mins

def aOpen15 = open(period = UsePeriod15);
def aClose15 = close(period = UsePeriod15);
def aHigh15 = high(period = UsePeriod15);
def aLow15 = low(period = UsePeriod15);

def haClose15 = (aOpen15 + aClose15 + aHigh15 + aLow15) / 4;
def haOpen15 = (haOpen15[1] + haClose15[1]) / 2;


def trend15 = if haClose15 >= haOpen15 then 1 else if haClose15[1] < haOpen15[1] then -1 else 0;
plot HA_Up15 = if IsNaN(UsePeriod15) then Double.NaN else 5;
#plot HA_Up15 = if haClose15 >= haOpen15 then 1 else 0;
HA_Up15.SetPaintingStrategy(PaintingStrategy.Points);#SetStyle(Curve.POINTS);
HA_Up15.AssignValueColor(if haClose15 >= haOpen15 then Color.GREEN else if haClose15 [1]< haOpen15[1] then Color.RED else Color.CURRENT);
HA_Up15.SetLineWeight(4);
#######################################

#Timeframe3  30 mins

def aOpen30 = open(period = UsePeriod30);
def aClose30 = close(period = UsePeriod30);
def aHigh30 = high(period = UsePeriod30);
def aLow30 = low(period = UsePeriod30);

def haClose30 = (aOpen30 + aClose30 + aHigh30 + aLow30) / 4;
def haOpen30 = (haOpen30[1] + haClose30[1]) / 2;


def trend30 = if haClose30 >= haOpen30 then 1 else if haClose30[1] < haOpen30[1] then -1 else 0;
plot HA_Up30 = if IsNaN(UsePeriod30) then Double.NaN else 4;
#plot HA_Up60 = if haClose60 >= haOpen60 then 1 else 0;
HA_Up30.SetPaintingStrategy(PaintingStrategy.Points);#SetStyle(Curve.POINTS);
HA_Up30.AssignValueColor(if haClose30 >= haOpen30 then Color.GREEN else if haClose30[1] < haOpen30[1] then Color.RED else Color.CURRENT);
HA_Up30.SetLineWeight(4);

################################
#Timeframe4  60mins

def aOpen60 = open(period = UsePeriod60);
def aClose60 = close(period = UsePeriod60);
def aHigh60 = high(period = UsePeriod60);
def aLow60 = low(period = UsePeriod60);

def haClose60 = (aOpen60 + aClose60 + aHigh60 + aLow60) / 4;
def haOpen60 = (haOpen60[1] + haClose60[1]) / 2;

def trend60 = if haClose60 >= haOpen60 then 1 else if haClose60[1] < haOpen60[1] then -1 else 0;
plot HA_Up60 = if IsNaN(UsePeriod60) then Double.NaN else 3;
#plot HA_Up60 = if haClose60 >= haOpen60 then 1 else 0;
HA_Up60.SetPaintingStrategy(PaintingStrategy.Points);#SetStyle(Curve.POINTS);
HA_Up60.AssignValueColor(if haClose60 >= haOpen60 then Color.GREEN else if haClose60[1] < haOpen60[1] then Color.RED else Color.CURRENT);
HA_Up60.SetLineWeight(4);

##################################
#Timeframe5 4hrs

def aOpen4hr = open(period = UsePeriod4hr);
def aClose4hr = close(period = UsePeriod4hr);
def aHigh4hr = high(period = UsePeriod4hr);
def aLow4hr = low(period = UsePeriod4hr);

def haClose4hr = (aOpen4hr + aClose4hr + aHigh4hr + aLow4hr) / 4;
def haOpen4hr = (haOpen4hr[1] + haClose4hr[1]) / 2;

def trend4hr = if haClose4hr >= haOpen4hr then 1 else if haClose4hr < haOpen4hr then -1 else 0;
plot HA_Up4hr = if IsNaN(UsePeriod4hr) then Double.NaN else 2;
#plot HA_Up60 = if haClose60 >= haOpen60 then 1 else 0;
HA_Up4hr.SetPaintingStrategy(PaintingStrategy.Points);#SetStyle(Curve.POINTS);
HA_Up4hr.AssignValueColor(if haClose4hr >= haOpen4hr then Color.GREEN else if haClose4hr[1] < haOpen4hr[1] then Color.RED else Color.CURRENT);
HA_Up4hr.SetLineWeight(4);
#######################################

#Timeframe6 Day

def aOpenday = open(period = UsePeriodday);
def aCloseday = close(period = UsePeriodday);
def aHighday = high(period = UsePeriodday);
def aLowday = low(period = UsePeriodday);

def haCloseday = (aOpenday + aCloseday + aHighday + aLowday) / 4;
def haOpenday = (haOpenday[1] + haCloseday[1]) / 2;

def trendday = if haCloseday >= haOpenday then 1 else if haCloseday [1] < haOpenday[1] then -1 else 0;
plot HA_Upday = if IsNaN(UsePeriodday) then Double.NaN else 1;
#plot HA_Up60 = if haClose60 >= haOpen60 then 1 else 0;
HA_Upday.SetPaintingStrategy(PaintingStrategy.Points);#SetStyle(Curve.POINTS);
HA_Upday.AssignValueColor(if haCloseday >= haOpenday then Color.GREEN else if haCloseday[1] < haOpenday[1] then Color.RED else Color.CURRENT);
HA_Upday.SetLineWeight(4);

####################################
#def Trend1 = if haClose5 >= haOpen5 then 1 else if haClose5[1] < haOpen5[1] then -1 else 0;
#def Trend2 = if haClose15 >= haOpen15 then 1 else if haClose15[1] < haOpen15[1] then -1 else 0;
#def Trend3 = if haClose60 >= haOpen60 then 1 else if haClose60[1] < haOpen60[1] then -1 else 0;
#def Trend4 = if haClose4hr >= haOpen4hr then 1 else if haClose4hr[1] < haOpen4hr[1] then -1 else 0;
#def Trend5_ = if  haCloseday >= haOpenday then 1 else if haCloseday[1] < haOpenday[1] then -1 else 0;

#Down Trend
#def Trend1a = if haClose5 < haOpen5 then 1 else if haClose5[1] >= haOpen5[1] then -1 else 0;
#def Trend2b = if haClose15 < haOpen15 then 1 else if haClose15[1] >= haOpen15[1] then -1 else 0;
#def Trend3c = if haClose60 < haOpen60  then 1 else if haClose60[1]>= haOpen60[1] then -1 else 0;
#def Trend4d = if haClose4hr < haOpen4hr then 1 else if haClose4hr[1] >= haOpen4hr[1] then -1 else 0;
#def Trend5e = if  haCloseday < haOpenday  then 1 else if haCloseday[1] >= haOpenday[1] then -1 else 0;

#Up Trend
def Trend1 = if haClose5 >= haOpen5 then 1 else if haClose5[1] < haOpen5[1] then -1 else 0;
def Trend2 = if haClose15 >= haOpen15 then 1 else if haClose15[1] < haOpen15[1] then -1 else 0;
def Trend3 = if haClose30>= haOpen30 then 1 else if haClose30[1] < haOpen30[1] then -1 else 0;
def Trend4 = if haClose60 >= haOpen60 then 1 else if haClose60[1] < haOpen60[1] then -1 else 0;
def Trend5_ = if haClose4hr >= haOpen4hr then 1 else if haClose4hr[1] < haOpen4hr[1] then -1 else 0;
def Trend6 = if  haCloseday >= haOpenday then 1 else if haCloseday[1] < haOpenday[1] then -1 else 0;

#Down Trend
def Trend1a = if haClose5 < haOpen5 then 1 else if haClose5[1] >= haOpen5[1] then -1 else 0;
def Trend2b = if haClose15 < haOpen15 then 1 else if haClose15[1] >= haOpen15[1] then -1 else 0;
def Trend3c = if haClose30 < haOpen30 then 1 else if haClose30[1] >= haOpen30[1] then -1 else 0;
def Trend4d = if haClose60 < haOpen60  then 1 else if haClose60[1] >= haOpen60[1] then -1 else 0;
def Trend5e= if haClose4hr < haOpen4hr then 1 else if haClose4hr[1] >= haOpen4hr[1] then -1 else 0;
def Trend6f = if  haCloseday < haOpenday  then 1 else if haCloseday[1] >= haOpenday[1] then -1 else 0;

#plot MTF_TREND = 6;
#MTF_TREND.SetPaintingStrategy(PaintingStrategy.Points);
#MTF_TREND.SetLineWeight(lineWeight = 3);
#MTF_TREND.DefineColor("Buy", GetColor(5));
#MTF_TREND.DefineColor("Sell", GetColor(6));
#MTF_TREND.AssignValueColor(if (Trend1 + Trend2 + Trend3 + Trend4 + Trend5_) >= 3 then Color.GREEN else Color.RED);

#MTF_TREND.AssignValueColor(if PaintBars is false and (Trend1 + Trend2 + Trend3 + Trend4 + Trend5_) >= 3 #then Color.GREEN else if PaintBars is false and (Trend1 + Trend2 + Trend3 + Trend4 + Trend5_) < 3 then #Color. RED else Color.CURRENT);

def HA_MTF_TrendUP = (Trend1 + Trend2 + Trend3 + Trend4) >=  Con_Cri ;
def HA_MTF_TrendDN = (Trend1a + Trend2b + Trend3c + Trend4d) >=  Con_Cri;

plot Main_Heikin = 7;
Main_Heikin.SetPaintingStrategy(PaintingStrategy.POINTS);
Main_Heikin.AssignValueColor(if HA_MTF_TrendUP == 1 then Color.Green else if HA_MTF_TrendDN == 1 then color.red else Color.Black);
Main_Heikin.SetLineWeight(4);

#End code
#######################################################
 
Thank you @AspaTrader :) I am seeing what you mean, chart is clean and effective. I created a backtest using the TMO code adding this:
plot MainUp = if Main > Signal and Main[1] < os then 1 else 0;
plot MainDown = if Main < Signal and Main[1] > ob and Main < ob then 1 else 0; Makes a pretty reliable trigger. Nice trade on the ES this morning!!(y)
@AspaTrader Could you please share the TMO script/code after you did the backtesting for the trigger please? Thanks
 
@AspaTrader Could you please share the TMO script/code after you did the backtesting for the trigger please? Thanks
@AspaTrader did not post a backtest, I just used the code in the shared link and added a trigger. It may not be accurate but it was just an attempt to simulate TMO rising from the green zone.
Here is the primary code that is TMO:
Code:
# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
input length = 14;
input calcLength = 5;
input smoothLength = 3;
def o = open;
def c = close;
def data = fold i = 0 to length
           with s
           do s + (if c > GetValue(o, i)
                   then 1
                   else if c < GetValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def ob = if IsNaN(c) then Double.NaN else Round(length * .7);
def os = if IsNaN(c) then Double.NaN else -Round(length * .7);
# code below to determine when Main oscillator ascending from Green zone(os) or descending from red zone(ob)
def MainUp = if Main > Signal and Main[1] < os a then 1 else 0;
def MainDown = if Main < Signal and Main[1] > ob and Main < ob then 1 else 0;

Add as a strategy and create AddOrder statements
 
@AspaTrader
See below the TMO with breakouts. This was in my bag of tricks (came across it last year and modified adding breakouts. I did not need all the code and only kept the TMO script.

https%3A//i.imgur.com/5vgGzc7.jpg[/img]']
5vgGzc7.jpg


https://tos.mx/MwNMpuW
Like that TMO - very nice :)
 
@AspaTrader. How did you incorporate the cup and handle? I use the built in that was tweaked by Robert Payne. Can you share the script?
@astpatrader I have been tweaking the TOS script to find intraday cup and handle setups. I tend to find them by site but would prefer to have a script that finds them automatically. The TOS script works more for swing trading.
 
@astpatrader I have been tweaking the TOS script to find intraday cup and handle setups. I tend to find them by site but would prefer to have a script that finds them automatically. The TOS script works more for swing trading.
Hi @BonBon - Thanks for sharing this indicator, appreciate it!

Could you please share the latest study you have, that would be really helpful. Did you use Rick’s changes? Thanks again!
 
@gang the updates from my original code is thread #134. You will have to review the threads after that to find any new script that I posted. No I am not using Rick's changes. I am using my original HA_Smoothing indicator with the updates on #134. I have added and or updated some of the script based such as scans for even more specific reversals etc. As always do your own diligence and know what works for your based on your trading style/trading plan.
 
The price bubbles do not appear until the trend is well on its way. Is that the case or is there something wrong with my setup?
 
HA CANDLE TREND UP/TREND DOWN ALERT AND SCAN (CODE AND PIC BELOW) PROVIDED BY HAHN TECH


If anyone is interested here is an ALERT indicator by Hahn Tech that alerts with sound and arrows when a HEIKEN-ASHI candle is about to change direction. Here is the page and the code:




Code:
#https://www.hahn-tech.com/ans/alert-setting-on-heikin-ashi-candles/

def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def haColor = haClose > haOpen;
plot trendUp = haColor and !haColor[1];
trendUp.SetDefaultColor(Color.CYAN);
trendUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot trendDown = !haColor and haColor[1];
trendDown.SetDefaultColor(Color.MAGENTA);
trendDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Alert(trendUp, "Trend Up", Alert.BAR, Sound.RING);
Alert(trendDown, "Trend Down", Alert.BAR, Sound.RING);


He also includes a scan that also shows when the HA candle is about to change color.
Here is the code:


Code:
#https://www.hahn-tech.com/ans/alert-setting-on-heikin-ashi-candles/

def haClose = ohlc4;
def haOpen = if haOpen[1] == 0 then haClose[1] else (haOpen[1] + haClose[1]) / 2;
def haHigh = Max(high, Max(haClose, haOpen));
def haLow = Min(low, Min(haClose, haOpen));
def haColor = haClose > haOpen;
def trendUp = haColor and !haColor[1];
def trendDown = !haColor and haColor[1];
plot scan = trendUp;
#plot scan = trendDown;

This is for HA candle changing from downward trend to "TREND UP"
If you want the HA candle changing for uptrend to "TREND DOWN" just remove "#" from last line of code and add it to the line above.
 

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
387 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