HeikinAshiDiff indicator in TOS

drho

New member
VIP
In TOS, there is an indicator HeikinAshiDiff (HAD). I observed this indicator and it follows the HA paint bars. When the HAD, is above the zero line, the chart candle is green and when it crosses below zero line the candle is red. I need some help in making the indicator to be green when rising and red when going lower. Or like a Histogram where up is green and down is red. Sometimes when the HAD indicator reverses before it approaches the zero line, it is warning that the paint bar is going to change soon. Thank you in advance.

THINKSCRIPT

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

declare lower;

input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));


# END

VGVbAGS.jpg
 
  • Love
Reactions: IPA

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@drho I don't know if this is right...IF the line is supposed to be RED below the 0 and GREEN above the ZERO than the pic you posted is off...Double check with HA candles...This more looks like the change in slope of the line...which reflects GREEN/RED...There is also a script that paints standard candles in HA format.
 
You can detect trend changes by following the trend color changes. I add the colors to the indicator for you.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

declare lower;

input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

HADiff.DefineColor("Bullish", GetColor(1));
HADiff.DefineColor("Bearish", GetColor(0));HADIFF.AssignValueColor(if HADiff > HADiff[1] then HADiff.color("Bullish") else HADiff.color("Bearish"));
Avg.DefineColor("Bullish", GetColor(1));
Avg.DefineColor("Bearish", GetColor(0));
Avg.AssignValueColor(if Avg > Avg[1] then Avg.color("Bullish") else Avg.color("Bearish"));
 
Last edited:
HADiff.assignvaluecolor(if HADiff > HADiff[1] then color.GREEN else color.RED);

You can detect trend changes by following the trend color changes. I add the colors to the indicator for you.

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

declare lower;

input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));

HADiff.DefineColor("Bullish", GetColor(1));
HADiff.DefineColor("Bearish", GetColor(0));HADIFF.AssignValueColor(if HADiff > HADiff[1] then HADiff.color("Bullish") else HADiff.color("Bearish"));
Avg.DefineColor("Bullish", GetColor(1));
Avg.DefineColor("Bearish", GetColor(0));
Avg.AssignValueColor(if Avg > Avg[1] then Avg.color("Bullish") else Avg.color("Bearish"));
Can you convert this into upper indicator? Thanks!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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