# Count Heiken Ashi bars?

#### derpderp

##### New member
Hi all,
Is it possible to use ThinkScript to count the number of consecutive Heiken Ashi bars in a sequence before it flips?
I saw this post/script but doesn't seem to work for HA.
What I'd like it to do is count a series of green before it flips to red and then put a bubble over the last bar w/ the number. Then on the red side, count those and put a bubble under the last red bar w/ the number like this picture attached.
I have struggled w/ ThinkScript for some time so I'm reaching out for help!
Thanks!
DerpDerp

Solution
Closest I could get in a short time... it's close to what you want.

Code:
``````def HC = (open+high+low+close)/4;
def HO = (HO[1]+HC[1])/2;
def Direction = if HC > HO then 1 else -1;

def sumUp = compoundValue(1, if Direction == -1 then 0 else if Direction == 1 then sumUp[1]+1 else sumUp[1],0);
def sumDown =  compoundValue(1, if Direction == 1 then 0 else if Direction == -1 then sumDown[1]+1 else sumDown[1],0);

addChartBubble(sumUp < sumUp[1], high[1], sumUp[1], color.green, yes);
addChartBubble(sumDown < sumDown[1], low[1], sumDown[1], color.red, no);``````

It'll show the bubble one bar later (since it has to know the trend ended) and I'm not sure if the bubble can go back a day.

Closest I could get in a short time... it's close to what you want.

Code:
``````def HC = (open+high+low+close)/4;
def HO = (HO[1]+HC[1])/2;
def Direction = if HC > HO then 1 else -1;

def sumUp = compoundValue(1, if Direction == -1 then 0 else if Direction == 1 then sumUp[1]+1 else sumUp[1],0);
def sumDown =  compoundValue(1, if Direction == 1 then 0 else if Direction == -1 then sumDown[1]+1 else sumDown[1],0);

addChartBubble(sumUp < sumUp[1], high[1], sumUp[1], color.green, yes);
addChartBubble(sumDown < sumDown[1], low[1], sumDown[1], color.red, no);``````

It'll show the bubble one bar later (since it has to know the trend ended) and I'm not sure if the bubble can go back a day.

Last edited:

87k+ Posts
353 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?