# Heikin Ashi Calcualtion

#### rvaidyamath

##### New member
Here is my Code
#code Begin
def o = open;
def c = close ;
def h = high;
def l = low;

#AddChartBubble( YES , HIGH , "OPEN :" + open[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "HIGH :" + HIGH[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "LOW:" + LOW[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "CLOSE :" + CLOSE[0], Color.WHITE, yes);
#def HAopen = CompoundValue(1, (o[1] + c[1]) / 2, (o[1] + c[1]) / 2);

def HAopen = (o[1] + c[1] ) / 2 ;
def HAclose = (o + h + l + c) / 4;
def HAhigh = Max(Max(h, HAopen), HAclose);
def HAlow = Min(Min(l, HAopen), HAclose);

def HA_green = if HAclose >= HAopen then 1 else 0;
def HA_red = if HAclose < HAopen then 1 else 0;

AddChartBubble( HA_green , HIGH , "Green: " + HA_green[0], Color.green, yes);
AddChartBubble( HA_red , HIGH , "Red: " + HA_red[0], Color.red, yes);

# code End

Screen shot below is marked where the Code is giving the wrong signals ;

Apprecaite the help - Raj

#### Attachments

• HA Jpeg Thinkscript.png
173.5 KB · Views: 149
Here is my Code
#code Begin
def o = open;
def c = close ;
def h = high;
def l = low;

#AddChartBubble( YES , HIGH , "OPEN :" + open[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "HIGH :" + HIGH[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "LOW:" + LOW[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "CLOSE :" + CLOSE[0], Color.WHITE, yes);
#def HAopen = CompoundValue(1, (o[1] + c[1]) / 2, (o[1] + c[1]) / 2);

def HAopen = (o[1] + c[1] ) / 2 ;
def HAclose = (o + h + l + c) / 4;
def HAhigh = Max(Max(h, HAopen), HAclose);
def HAlow = Min(Min(l, HAopen), HAclose);

def HA_green = if HAclose >= HAopen then 1 else 0;
def HA_red = if HAclose < HAopen then 1 else 0;

AddChartBubble( HA_green , HIGH , "Green: " + HA_green[0], Color.green, yes);
AddChartBubble( HA_red , HIGH , "Red: " + HA_red[0], Color.red, yes);

# code End

Screen shot below is marked where the Code is giving the wrong signals ;

Apprecaite the help - Raj

See changes in bold

Rich (BB code):
``````#code Begin
def o = open;
def c = close ;
def h = high;
def l = low;

#AddChartBubble( YES , HIGH , "OPEN :" + open[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "HIGH :" + HIGH[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "LOW:" + LOW[0], Color.WHITE, yes);
#AddChartBubble( YES , HIGH , "CLOSE :" + CLOSE[0], Color.WHITE, yes);
#def HAopen = CompoundValue(1, (o[1] + c[1]) / 2, (o[1] + c[1]) / 2);

#def HAopen = (o[1] + c[1] ) / 2 ;
def HAclose = (o + h + l + c) / 4;
def HAopen  = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
def HAhigh = Max(Max(h, HAopen), HAclose);
def HAlow = Min(Min(l, HAopen), HAclose);

def HA_green = if HAclose >= HAopen then 1 else 0;
def HA_red = if HAclose < HAopen then 1 else 0;

AddChartBubble( HA_green ,haHIGH , "Green: " + HA_green[0], Color.green, yes);
AddChartBubble( HA_red , haHIGH , "Red: " + HA_red[0], Color.red, yes);``````

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