# How to Scan for Heikin-Ashi Candles in ThinkorSwim

#### darkelvis

##### Member
Hi, random guy that knows nothing about coding here for my monthly check in again. 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.

#### joshua74133

##### Member
VIP
Scan for a 5 Bar Bullish Heikin Ash Trend change

Code:
``````# Heikin Ashi 5 Bar Bearish Trend Change _JQ

# v01 dated 9.23.2018
# Scans for a 5 Bar change in the Heikin Ashi Trend to Bull from Bear
# relies on RHouser HA candle description code

def xClose  = ( open + high + low + close ) / 4;
rec xOpen   = compoundValue( 1, ( xOpen[1] + xClose[1] ) / 2, xClose );
def Bullish = if ( xClose - xOpen ) >= 0 then yes else no;
def Bearish = if ( xClose - xOpen ) <= 0 then yes else no;
def BullishChange = if ( xClose - xOpen ) >= 0 and ( xClose[1] - xOpen[1] ) <= 0 then yes else no;
def BearishChange = if ( xClose - xOpen ) <= 0 and ( xClose[1] - xOpen[1] ) >= 0 then yes else no;
def BullishChange2Bar = if ( xClose - xOpen ) >= 0 and ( xClose[1] - xOpen[1] ) >= 0 and ( xClose[2] - xOpen[2] ) <= 0 then yes else no;
def BearishChange2Bar = if ( xClose - xOpen ) <= 0 and ( xClose[1] - xOpen[1] ) <= 0 and ( xClose[2] - xOpen[2] ) >= 0 then yes else no;

def BullishChange5Bar = if ( xClose - xOpen ) >= 0
and ( xClose[1] - xOpen[1] ) >= 0
and ( xClose[2] - xOpen[2] ) >= 0
and ( xClose[3] - xOpen[3] ) >= 0
and ( xClose[4] - xOpen[4] ) >= 0
and ( xClose[5] - xOpen[5] ) <= 0
then yes else no;

def BearishChange5Bar = if ( xClose - xOpen ) <= 0
and ( xClose[1] - xOpen[1] ) <= 0
and ( xClose[2] - xOpen[2] ) <= 0
and ( xClose[3] - xOpen[3] ) <= 0
and ( xClose[4] - xOpen[4] ) <= 0
and ( xClose[5] - xOpen[5] ) >= 0
then yes else no;

##    Plot Section.  Choose one plot only
#plot Scan   = Bullish;
#plot Scan   = Bearish;
#plot Scan   = BullishChange;
#plot Scan   = BearishChange;
#plot Scan   = BullishChange2Bar;
#plot Scan   = BearishChange2Bar;
plot Scan   = BullishChange5Bar;
#plot Scan   = BearishChange5Bar;``````

#### HighBredCloud

##### Well-known member
VIP
Try this...comment out which one you're not using...I think BullishChange and BearishChange scan for stocks that just switched from from Bullish to Bearish and vice versa...than Bullish or Bearish which scan for stocks already in the specific condition.

Code:
``````# Heikin Ashi Bullish/Bearish Trend Change _JQ

# v01 dated 9.23.2018

# Scans for a change in the Heikin Ashi Trend to Bull from Bear

# relies on RHouser HA candle description code

def xClose = ( open + high + low + close ) / 4;

rec xOpen = compoundValue( 1, ( xOpen[1] + xClose[1] ) / 2, xClose );

def Bullish = if ( xClose - xOpen ) >= 0 then yes else no;

def Bearish = if ( xClose - xOpen ) <= 0 then yes else no;

def BullishChange = if ( xClose - xOpen ) >= 0 and ( xClose[1] - xOpen[1] ) <= 0 then yes else no;

def BearishChange = if ( xClose - xOpen ) <= 0 and ( xClose[1] - xOpen[1] ) >= 0 then yes else no;

#plot Scan = Bullish;

#plot Scan = Bearish;

plot Scan = BullishChange;

#plot Scan = BearishChange;``````

#### JonPM

##### New member
I found the following in think_Script Cloud OneNote.

HA Bullish/Bearish scan

RE: [TOS_thinkscript] Re: Heikin Ashi Candle Charts - Scan for Bullish and Bearish Shift By R. Houser

Actually, I used the calculations for haClose contained on page 55 of Sylvain Vervoort's book, "Capturing Profit with Technical Analysis," 2009, Marketplace Books, Inc.

A careful analysis of TOS Heikin-Ashi bars shows that on their charts they use this formula for calculating haClose, "def xClose = round( ( open + high + low + close ) / 4, 2 );"

If you feel more comfortable using the alternate calculation for the scan, here's the script.

Code:
``````######### scan ###################
rec HAopen = compoundValue(1, (HAopen[1] + ohlc4) / 2, ohlc4);
def HAclose = (HAopen + Max(high, HAopen) + Min(low, HAopen) + ohlc4) / 4;
def Bullish = if ( HAclose - HAopen ) >= 0 then yes else no;
plot Scan   = Bullish;
########### EOC ############``````

Though the alternate calculation produces a somewhat smoother plot than the accepted formula, used in the scan it returns the same result set as the my original script, the difference is, apparently, not material in practice.

My own philosophy is that given the choice, in scans and such, I'll use 1st) TOS actual values and 2nd) when that's not available I'll use calculations that produce results that match TOS's. In charts, particularly in other's studies, I'll use the calculation of the author as they usually have a reason for deviating from accepted formula.

#### Sree6

##### New member
@HighBredCloud Hi, Can you please help with the code to scan Bearish or Bullish DOJI's on a Heikin Ashi candles. Thank you!

#### FOTM_8888

##### Member
VIP
i use a strategy with Heikin Ashi, for day and swin trades. but i will like to know if someone can help me build a indicator that will be very good for this amazing community.
here is the condition:
if is a green heikin ashi candles then the indicator plot a Green Dot or Squeare, if the Heiking Ashi is changes to red then a Yellow Dot or Squeare, if is two red Heikin Ashi candles then a Red Dot or Squeare, now if is a green heikin ashi candles then plot a Yellow Dot or Squeare, if is a two green heikin ashi candles then a green Dot or Squeare. will be nice a lower indicator, thank you some in advance.

#### LuckyPlayer2

##### New member
Hi Guys, love the site! I’m working on my thinkscript skills, but must admit I’m still a novice.

I’m trying to build a simple screener on TOS:
A scan that searches for stocks with last candle (Heikin Ashi) has turned from Red to Green on a 1000 tick chart.

Should this be easy? Sorry I’m a boomer that struggles getting out of the starting blocks trying to script sometimes

##### Well-known member
VIP
@LuckyPlayer2 I'm glad you are coming along with your coding skills... The crux of the matter is that we don't scan for color change but, rather, what it is that causes the color change and that is usually a trend reversal... Off the top of my head I don't recall the logic that paints Heiki Ashi candles aside from the fact that they usually start at the mid-range of the previous candle... That logic might be different than standard candles and perhaps there is where you should look next... If you can't come up with good results I might be able to look into this later... Please post your working in progress code and I'll see if anything jumps right out at me...

#### Pensar

##### Well-known member
VIP
@LuckyPlayer2 Please also keep in mind that the scanner can only use specific timeframes (1 min, 3 min, 5 min, 10 min, 15 min, 20 min, 30 min, 1 hr, 2 hr, 4 hr, Day, Week, and Month); it does'nt support tick charts or range bars. Scans also update only once every three minutes at best, so even if it was possible to scan using tick aggregations, the scanner would miss most trades anyway.

#### rayed31

##### New member
Could someone help me code up a scan for HA candles where the candles are downtrending and the last two candles are a Doji followed buy a green candle with a flat bottom.

#### mikegfel

##### New member
Could someone help me code up a scan for HA candles where the candles are downtrending and the last two candles are a Doji followed buy a green candle with a flat bottom.
@rayed31 If you find this will you share? Thanks mikegfel

#### DudeDastic

##### New member
Anyone figure out how to scan for a HA doji candle?