Heiken Ashi Scan

darkelvis

Member
Is it possible to create a scanner for ThinkorSwim that will find green Heikin Ashi candles within the last 2 bars or would that be impossible? Thanks in advance.
 
Last edited by a moderator:
Here is the scan code for this indicator... I recommend saving two separate scans, one for Longs and one for Shorts... I have tested against my main Watchlist using various timeframes with successful results... Enjoy...

UPDATES:

# v1.0 : 2021-08-13 : Initial release.
# v1.1 : 2021-08-17 : Added ability to scan for "unconfirmed" (Yellow) signals.
# v1.2 : 2021-08-25 : Fixed logic for proper scan results and added more usage comments.


Love all the support you have given on the Hiekin Ashi Scanning. I do have a question/request. I am using the scan above and wanted to know if it could be amended to only show in the results the underlying stocks whose last candle did not have a tail if they are an Green Candle or a wick if they are a Red Candle? Also, can you set this up to only display Yellow Candles if they have a wick or a tail, but not both. Looking for candles that are more decisive. Thank you!
 
Here is the scan code for this indicator... I recommend saving two separate scans, one for Longs and one for Shorts... I have tested against my main Watchlist using various timeframes with successful results... Enjoy...

UPDATES:

# v1.0 : 2021-08-13 : Initial release.
# v1.1 : 2021-08-17 : Added ability to scan for "unconfirmed" (Yellow) signals.
# v1.2 : 2021-08-25 : Fixed logic for proper scan results and added more usage comments.


Love all the support you have given on the Hiekin Ashi Scanning. I do have a question/request. I am using the scan above and wanted to know if it could be amended to only show in the results the underlying stocks whose last candle did not have a tail if they are an Green Candle or a wick if they are a Red Candle? Also, can you set this up to only display Yellow Candles if they have a wick or a tail, but not both. Looking for candles that are more decisive. Thank you!
You could try to modify this script which identifies the wicks and tails:
https://usethinkscript.com/threads/...p-down-on-chart-with-no-wick.9057/#post-83016
 
Is there a way to have this indicator show up on TOS mobile app? I have it on my computer ok but on the app it shows up as solid purple line?
Thanks

I should have been more specific. Im talking about the indicator code in Post #9.
 
Last edited by a moderator:
Is there a way to have this indicator show up on TOS mobile app? I have it on my computer ok but on the app it shows up as solid purple line?
Thanks

I should have been more specific. Im talking about the indicator code in Post #9.
TOS Mobile App
The TOS built-in mobile indicators work on the TOS mobile app.
ToS Mobile does not support custom indicators that utilize vertical lines, labels, bubbles, clouds, "color changes for slopes and lines", renko, or multiple timeframes.

Here are some workarounds --> https://usethinkscript.com/threads/indicators-not-working-in-thinkorswim-mobile-app.232/
Here are some ToS Mobile Friendly Indicators --> https://usethinkscript.com/threads/tos-mobile-friendly-indicators.1071/
 
TOS Mobile App
The TOS built-in mobile indicators work on the TOS mobile app.
ToS Mobile does not support custom indicators that utilize vertical lines, labels, bubbles, clouds, "color changes for slopes and lines", renko, or multiple timeframes.

Here are some workarounds --> https://usethinkscript.com/threads/indicators-not-working-in-thinkorswim-mobile-app.232/
Here are some ToS Mobile Friendly Indicators --> https://usethinkscript.com/threads/tos-mobile-friendly-indicators.1071/
I will check those indicators out Thanks.
 
Here is the Heikin_Ashi_Trend_Dashboard which can be added to charts to show the Heikin Ashi trend reversals... It also contains code for potential trend reversal alerts based on the yellow bars, includes colorbar code to color the chart candles, and the dashboard can also be disabled...

yRTUvxj.png


UPDATES:

# v1.0 : 2021-08-17 : Initial release
# v1.1 : 2021-08-18 : Modified to 10 bars from 5
# v1.2 : 2021-08-27 : Added option to hide Dashboard

Ruby:
# Heikin_Ashi_Trend_Dashboard
# Paints Yellow bar to signal potential trend reversals while Green and Red bars indicate trend direction.
# Optionally sounds alerts on trend reversal while eliminating most false signals.
# Optionally paints candles based on HA trend
# Created by rad14733 for usethinkscript.com
# v1.0 : 2021-08-17 : Initial release
# v1.1 : 2021-08-18 : Modified to 10 bars from 5
# v1.2 : 2021-08-27 : Added option to hide Dashboard

input useAlerts = no;
input alertType = Alert.BAR;
input buySound = Sound.DING;
input sellSound = Sound.BELL;
input colorBars = no;
input hideDashboard = no;

def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
  if haTrendUp == 1 and haTrendUp[1] == 1 then 1
  else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
  else 0
;

DefineGlobalColor("Label", Color.ORANGE);
DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.YELLOW);

AddLabel(!hideDashboard, "HA Trend:", GlobalColor("Label"));

AddLabel(!hideDashboard, " ",
  if haSignal[9] == 1 then GlobalColor("UpTrend")
  else if haSignal[9] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[8] == 1 then GlobalColor("UpTrend")
  else if haSignal[8] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[7] == 1 then GlobalColor("UpTrend")
  else if haSignal[7] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[6] == 1 then GlobalColor("UpTrend")
  else if haSignal[6] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[5] == 1 then GlobalColor("UpTrend")
  else if haSignal[5] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[4] == 1 then GlobalColor("UpTrend")
  else if haSignal[4] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[3] == 1 then GlobalColor("UpTrend")
  else if haSignal[3] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[2] == 1 then GlobalColor("UpTrend")
  else if haSignal[2] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[1] == 1 then GlobalColor("UpTrend")
  else if haSignal[1] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

Alert(useAlerts and haSignal[1] == 0 and haSignal == 1, "HA Buy Signal", alertType, buySound);
Alert(useAlerts and haSignal[1] == 0 and haSignal == -1, "HA Sell Signal", alertType, sellSound);

AssignPriceColor(if colorBars then
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
  else Color.CURRENT
);

# END - Heikin_Ashi_Trend_Dashboard

I'm looking to have this same label, but I'd like it to be specifically for SPY with the aggregation set at 1-Hr. My goal is to have it on different charts with different timeframes, but always displaying the Heikin Ashi trend for SPY at the 1-Hr time frame. Thanks for any help!
 
I'm looking to have this same label, but I'd like it to be specifically for SPY with the aggregation set at 1-Hr. My goal is to have it on different charts with different timeframes, but always displaying the Heikin Ashi trend for SPY at the 1-Hr time frame. Thanks for any help!
I edited the original code (see lines 7 and 9 below). I'm halfway there, as it's now locked into SPY like I want. However, I still can't get the aggregation locked in, despite adding "input aggregationPeriod = AggregationPeriod.HOUR;". It still changes to whatever the current timeframe is on my charts.

Code:
input useAlerts = no;
input alertType = Alert.BAR;
input buySound = Sound.DING;
input sellSound = Sound.BELL;
input colorBars = no;
input hideDashboard = no;
input aggregationPeriod = AggregationPeriod.HOUR;

def haClose = ohlc4 ("SPY");
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
  if haTrendUp == 1 and haTrendUp[1] == 1 then 1
  else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
  else 0
;

DefineGlobalColor("Label", Color.ORANGE);
DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.YELLOW);

AddLabel(!hideDashboard, "HA Trend:", GlobalColor("Label"));

AddLabel(!hideDashboard, " ",
  if haSignal[9] == 1 then GlobalColor("UpTrend")
  else if haSignal[9] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[8] == 1 then GlobalColor("UpTrend")
  else if haSignal[8] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[7] == 1 then GlobalColor("UpTrend")
  else if haSignal[7] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[6] == 1 then GlobalColor("UpTrend")
  else if haSignal[6] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[5] == 1 then GlobalColor("UpTrend")
  else if haSignal[5] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[4] == 1 then GlobalColor("UpTrend")
  else if haSignal[4] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[3] == 1 then GlobalColor("UpTrend")
  else if haSignal[3] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[2] == 1 then GlobalColor("UpTrend")
  else if haSignal[2] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[1] == 1 then GlobalColor("UpTrend")
  else if haSignal[1] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

Alert(useAlerts and haSignal[1] == 0 and haSignal == 1, "HA Buy Signal", alertType, buySound);
Alert(useAlerts and haSignal[1] == 0 and haSignal == -1, "HA Sell Signal", alertType, sellSound);

AssignPriceColor(if colorBars then
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
  else Color.CURRENT
);
 
I edited the original code (see lines 7 and 9 below). I'm halfway there, as it's now locked into SPY like I want. However, I still can't get the aggregation locked in, despite adding "input aggregationPeriod = AggregationPeriod.HOUR;". It still changes to whatever the current timeframe is on my charts.
All of your calculations need to make use of the aggregation period selected, especially those Heikin Ashi ohlc calculations...
 
All of your calculations need to make use of the aggregation period selected, especially those Heikin Ashi ohlc calculations...
Thank you for the reply. Sadly, this is still beyond my current ability of coding. I think I might have line 9 correct now, but no matter what I try, I cannot figure out where to put (period = aggregationperiod) in lines 10-16. From what I understand, I believe that is what you're telling me needs to be done. I've tried looking at other scripts for reference, but no matter what I try, I still can't figure it out. I also just read somewhere that when writing a code for a specific aggregation, the code will not work in higher time frames than what the code specifies. My goal is to have the Heikin Ashi Trend Dashboard displayed on a daily chart and always show/provide information for 1-Hr candles. Is this even a possibility? Thanks again. Sorry for being such an amateur 😐

Code:
input useAlerts = no;
input alertType = Alert.BAR;
input buySound = Sound.DING;
input sellSound = Sound.BELL;
input colorBars = no;
input hideDashboard = no;
input aggregationPeriod = AggregationPeriod.HOUR;

def haClose = ohlc4 ("SPY", period = aggregationperiod);
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
  if haTrendUp == 1 and haTrendUp[1] == 1 then 1
  else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
  else 0;

DefineGlobalColor("Label", Color.ORANGE);
DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.YELLOW);

AddLabel(!hideDashboard, "SPY Trend:", GlobalColor("Label"));

AddLabel(!hideDashboard, " ",
  if haSignal[9] == 1 then GlobalColor("UpTrend")
  else if haSignal[9] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition"));

AddLabel(!hideDashboard, " ",
  if haSignal[8] == 1 then GlobalColor("UpTrend")
  else if haSignal[8] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition"));

AddLabel(!hideDashboard, " ",
  if haSignal[7] == 1 then GlobalColor("UpTrend")
  else if haSignal[7] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition"));
 
My goal is to have the Heikin Ashi Trend Dashboard displayed on a daily chart and always show/provide information for 1-Hr candles. Is this even a possibility? Thanks again. Sorry for being such an amateur 😐
A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on.
On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.

As such, you can overlay daily on hourly but how cannot use hourly on your daily chart.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation
 
A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on.
On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.

As such, you can overlay daily on hourly but how cannot use hourly on your daily chart.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation
Thank you for the confirmation. I'll keep the script as it is on my daily chart, then simply toggle to the 1h timeframe when I want to see the corresponding SPY trend. Thanks again to you and rad14733 for your assistance (y)
 
I'm looking to have this same label, but I'd like it to be specifically for SPY with the aggregation set at 1-Hr. My goal is to have it on different charts with different timeframes, but always displaying the Heikin Ashi trend for SPY at the 1-Hr time frame. Thanks for any help!
Hi Everybody, I want to thank everybody who contributed to writing the code and giving feedback to make using Heiken Ashi better for all of us. Thank you. I have a question - since we have the Heiken Ashi scan and dashboard, is there a way to have a script so you could keep track of the watchlist when the Heiken Ashi changes trend (green to yellow to red or just green and red. Ex, if you're using 5min chart, the watchlist script will let me know the direction (color) and the signal would stay in the script for 2-3 bars. Appriciate the help.
 
I'm just becoming familiar with the useful clarity of Heiken Ashi candles. Is there a way to scan for issues where the green Heiken Ashi candles' opening and low price of the candle are the same (using either weekly or monthly charts)? Thank you for any help.
In case anyone wants the scan parameter as I inquired above, here it is. Still trying to figure out how to scan for candles that are appearing as such for the first time (i.e. beginning of new trend after perhaps a lots of chop or a decline):

##As weekly or monthly scanning parameter for Heiken-Ashi Bullish Candle with low same as opening, and higher close

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

plot noWickBullish = haClose > haOpen and haOpen == haLow;
 
Here is the Heikin_Ashi_Trend_Dashboard which can be added to charts to show the Heikin Ashi trend reversals... It also contains code for potential trend reversal alerts based on the yellow bars, includes colorbar code to color the chart candles, and the dashboard can also be disabled...

View attachment 11633

UPDATES:

# v1.0 : 2021-08-17 : Initial release
# v1.1 : 2021-08-18 : Modified to 10 bars from 5
# v1.2 : 2021-08-27 : Added option to hide Dashboard

Ruby:
# Heikin_Ashi_Trend_Dashboard
# Paints Yellow bar to signal potential trend reversals while Green and Red bars indicate trend direction.
# Optionally sounds alerts on trend reversal while eliminating most false signals.
# Optionally paints candles based on HA trend
# Created by rad14733 for usethinkscript.com
# v1.0 : 2021-08-17 : Initial release
# v1.1 : 2021-08-18 : Modified to 10 bars from 5
# v1.2 : 2021-08-27 : Added option to hide Dashboard

input useAlerts = no;
input alertType = Alert.BAR;
input buySound = Sound.DING;
input sellSound = Sound.BELL;
input colorBars = no;
input hideDashboard = no;

def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
  if haTrendUp == 1 and haTrendUp[1] == 1 then 1
  else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
  else 0
;

DefineGlobalColor("Label", Color.ORANGE);
DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.YELLOW);

AddLabel(!hideDashboard, "HA Trend:", GlobalColor("Label"));

AddLabel(!hideDashboard, " ",
  if haSignal[9] == 1 then GlobalColor("UpTrend")
  else if haSignal[9] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[8] == 1 then GlobalColor("UpTrend")
  else if haSignal[8] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[7] == 1 then GlobalColor("UpTrend")
  else if haSignal[7] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[6] == 1 then GlobalColor("UpTrend")
  else if haSignal[6] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[5] == 1 then GlobalColor("UpTrend")
  else if haSignal[5] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[4] == 1 then GlobalColor("UpTrend")
  else if haSignal[4] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[3] == 1 then GlobalColor("UpTrend")
  else if haSignal[3] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[2] == 1 then GlobalColor("UpTrend")
  else if haSignal[2] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal[1] == 1 then GlobalColor("UpTrend")
  else if haSignal[1] == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

AddLabel(!hideDashboard, " ",
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
);

Alert(useAlerts and haSignal[1] == 0 and haSignal == 1, "HA Buy Signal", alertType, buySound);
Alert(useAlerts and haSignal[1] == 0 and haSignal == -1, "HA Sell Signal", alertType, sellSound);

AssignPriceColor(if colorBars then
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
  else Color.CURRENT
);

# END - Heikin_Ashi_Trend_Dashboard
Please can you write the above script for thinkscript custom column so same dashboard show in watchlist Thanks
 
Please can you write the above script for thinkscript custom column so same dashboard show in watchlist Thanks
Ruby:
# Heikin_Ashi Watchlist
# requested by suunys

def haClose = ohlc4;
def haOpen = (haOpen[1] + haClose[1]) / 2;
def haTrendUp = if haClose >= haOpen then 1 else 0;
def haTrendDn = if haClose < haOpen then 1 else 0;
def haSignal =
  if haTrendUp == 1 and haTrendUp[1] == 1 then 1
  else if haTrendDn == 1 and haTrendDn[1] == 1 then -1
  else 0
;

AddLabel(yes, " ");
AssignBackgroundColor(
  if haSignal == 1 then color.green
  else if haSignal == -1 then color.red
  else color.yellow
);
 

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