Heikin-Ashi Candles in lower section?

Status
Not open for further replies.
I used the code from Bon Bon. It does show Heikin Ashi Candles in lower study. However, the normal candles disappear in upper study. Could you please help me to figure out what causes the upper candle disappeared?

Ruby:
#Heiken_Ashi based on Sylvan Verboort's Trading with HA Candlestick Oscillator
#Bon Bon _last update Jan 17th 2021
declare lower;
input period = 1;
input hideCandles = yes;
input candleSmoothing = {default Valcu, Vervoort};
input show_bubble_labels = yes;
input bubbles = yes;
input arrows = yes;

input movingAverageType = {default  TEMA, Exponential, Hull };

def openMA;
def closeMA;
def highMA;
def lowMA;

switch (movingAverageType) {
case Exponential:
    openMA = CompoundValue(1, ExpAverage(open, period), open);
    closeMA = CompoundValue(1, ExpAverage(close, period), close);
    highMA = CompoundValue(1, ExpAverage(high, period), high);
    lowMA = CompoundValue(1, ExpAverage(low, period), low);
case Hull:
    openMA = CompoundValue(1, HullMovingAvg(open, period), open);
    closeMA = CompoundValue(1,  HullMovingAvg(close, period), close);
    highMA = CompoundValue(1,  HullMovingAvg(high, period), high);
    lowMA = CompoundValue(1,  HullMovingAvg(low, period), low);
case TEMA:
    openMA = CompoundValue(1, TEMA(open, period), open);
    closeMA = CompoundValue(1, TEMA(close, period), close);
    highMA = CompoundValue(1, TEMA(high, period), high);
    lowMA = CompoundValue(1, TEMA(low, period), low);

}


HidePricePlot(hideCandles);

def haOpen;
def haClose;

switch (candleSmoothing){
case Valcu:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);
case Vervoort:
    haOpen = CompoundValue(1, ( (haOpen[1] + (openMA[1] + highMA[1] + lowMA[1] + closeMA[1]) / 4.0 ) / 2.0), open);
    haClose = ((((openMA + highMA + lowMA + closeMA) / 4.0) + haOpen + Max(highMA, haOpen) + Min(lowMA, haOpen)) / 4.0);

}

plot o = haOpen;
o.AssignValueColor(if o > o[1] then Color.cyan else if o < o[1] then Color.magenta else color.gray);
o.SetLineWeight (5);
o.Hide();

def haLow =  Min(lowMA, haOpen);
def haHigh = Max(highMA, haOpen);

def avg = 34;
def TMA1 = reference TEMA(haClose, avg); # triple exponential moving average (TEMA) of 34 bars
def TMA2 =  reference TEMA(TMA1, avg);
def Diff = TMA1 - TMA2;
def ZlHa = TMA1 + Diff; #Zero-lagging TEMA average on closing prices - medium term uptrend;


def TMA1_ = reference TEMA((high + low) / 2, avg);
def Diff2 = TMA1_ - TMA2;
def ZlCl = TMA1_ + Diff2; #Zero-lagging TEMA average on closing prices - medium term doenwardtrend;

def ZlDif = ZlCl - ZlHa; # Zero-Lag close - Zero-Lag HA(green candle) Uptrend when ZlDif is equal to or greater than zero

def keep1 = if (haClose >= haOpen and haClose[1] >= haOpen[1]) then 1 else 0;
def keep2 = if ZlDif >= 0 then 1 else 0;
def keep3 = if (AbsValue(close - open) < ((high - low) * 0.35)) and high >= low[1] then 1 else 0;
def keeping = if (keep1 or keep2) then 1 else 0;
def keepall = if keeping or (keeping[1]) and close >= open or close >= (close[1]) then 1 else 0;

def utr = if keepall or (keepall[1]) and keep3 then 1 else 0;


def keep1_ = if (haClose < haOpen and haClose[1] < haOpen[1]) then 1 else 0;
def keep2_ = if ZlDif < 0 then 1 else 0;
def keep3_ = if (AbsValue(close - open) < ((high - low) * 0.35)) and low <= high[1] then 1 else 0;
def keeping_ = if (keep1_ or keep2_) then 1 else 0;
def dkeepall_ = if keeping_ or (keeping_[1]) and close < open or close < (close[1]) then 1 else 0;

def dtr = if dkeepall_ or (dkeepall_[1] - 1) and keep3_ == 1 then 1 else 0;  #downtrend
def upw = if dtr and (dtr[1]) and utr then 1 else 0;
def dnw = if !utr and (utr[1] ) and dtr then 1 else 0;

def results = if upw then 1 else if dnw then 0 else results[1];


input charttype = ChartType.CANDLE;

def haopen_ = if haClose <= haOpen
              then haOpen + 0
             else Double.NaN;

def HAhi   = if haClose <= haOpen
              then haHigh
              else Double.NaN;

def HAlo =   if haClose <= haOpen
              then haLow
              else Double.NaN;


AddChart(growColor = Color.red, neutralColor = Color.CURRENT, high = HAhi, low = HAlo, open = haopen_, close = haClose, type = ChartType.CANDLE);

def HAclose1 = ohlc4;
def HAopen1  = if haClose >= haOpen
               then CompoundValue(1, (haOpen[1] + haClose[1]) / 2, (open[1] + close[1]) / 2)
               else Double.NaN;

def haopen_1 = if haOpen <= haClose
               then HAopen1 + 0  else Double.NaN;

def HAhigh1  = haHigh;
def HAlow1   = haLow;


AddChart(growColor = Color.green, neutralColor = Color.CURRENT,  high = HAhigh1, low = HAlow1, open = haopen_1, close = haClose, type = ChartType.CANDLE);
 
Last edited:
Why? Why would you ADD declare lower when they already have declare lower in their scripts because they are already lower chart indicators???
Rich (BB code):
#TSI_HeikinAshi_Bars
# (c) 2009
#Copyright Authorship: ThinkSwimIndicators.com


#==========================================================================
# >>>                H E I K I N - A S H I   B A R S                  <<< [
#.........................................................................[
#                                                                         [
#                         -----=== O ===-----                             [
#                                                                         [
#****COPYRIGHT NOTICE:  "Heikin-Ashi Bars" is free to use by the general  [
# public. Distribution or modification is prohibited. All content, form,  [
# and style, likewise, is protected by copyright.                         [
#                                                                         [
#                         -----=== x ===-----                             [
#                                                                         [
# ThinkSwimIndicators.com  will  CONTINUE  to release FREE indicators--of [
# the  highest quality and caliber--for the Thinkorswim Trading platform, [
# for use by all.  Many of our free indicators surpass the Quality & Use- [
# fulness of indicators offered for "purchase" by other sites. We suggest [
# that  you  visit the free "Learning Center"  at our website for further [
# information on the use of this indicator. "GO: Master the Markets!" (TM)[
#==========================================================================


declare lower;

def haclose = (open + high + low + close) / 4;
https://usethinkscript.com/threads/pairs-trading-via-lower-heikin-ashi-chart.2268/
This code is not working by copying and pasting. I think that ThinkorSwim disables this code. You can take a try. I tried those below this code by adding "declare lower;". They are not working either.
 
i see part of the confusion.
i just loaded benten post#3 , ashi study for lower, is actually histogram bars, that are the full height of chart.
it is not 'ashi candles'
https://usethinkscript.com/threads/pairs-trading-via-lower-heikin-ashi-chart.2268/#post-27987
so his post is misleading.

to get candles drawn in a lower chart, will require a study that uses addchart() to draw them.

why try to put ashi in the lower?
why not make a grid of charts , 1 chart for normal candles and 1 chart for ashi?
 
I used the code from Bon Bon. It does show Heikin Ashi Candles in lower study. However, the normal candles disappear in upper study. Could you please help me to figure out what causes the upper candle disappearing?

it is this line

HidePricePlot(hideCandles);

put a # in front of it and your upper candles will be displayed
 
i see part of the confusion.
i just loaded benten post#3 , ashi study for lower, is actually histogram bars, that are the full height of chart.
it is not 'ashi candles'
https://usethinkscript.com/threads/pairs-trading-via-lower-heikin-ashi-chart.2268/#post-27987
so his post is misleading.

to get candles drawn in a lower chart, will require a study that uses addchart() to draw them.

why try to put ashi in the lower?
why not make a grid of charts , 1 chart for normal candles and 1 chart for ashi?
Thank you very much for your help. I know that I can use a grid of charts to show Heikin Ashi, which take more space than I can display Heikin Ashi in lower study. In addition, I can easily use a mouse to locate normal candle and Heikin Ashi candle at the same time.
 
Last edited:
I can add a copy of candles in a lower study. I would like to know to add colors to the candles in order to show normal candles.

Ruby:
declare lower;
def o = open;
def h = high;
def l = low;
def c = close;

AddChart(high = h, low = l, open = o, close = c, growcolor = color.green, fallcolor = color.red, type = ChartType.CANDLE);
 
Last edited:
Did you see this example?
https://usethinkscript.com/threads/rsi-heiken-ashi-for-thinkorswim.7250/#post-72378

It uses AddChart which is an advance UNSUPPORTED ToS function.
If you search on AddChart, you will find other examples.
Thank you very much for the information. I can add a copy of candles with the same color in a lower study. However, I need to figure out how to show candle colors normally. I used "AddChart(high = h, low = l, open = o, close = c, growcolor = color.green, fallcolor = color.red, type = ChartType.CANDLE);", but it only shows green candles. Could you please advise how to add colors to the candles?
 
Last edited:
I used "
AddChart(growcolor = Color.GREEN, neutralColor = Color.CURRENT, high = UpH, low = UpL, open = UpC, close = UpO, type = ChartType.CANDLE);
AddChart(growcolor = Color.RED, neutralColor = Color.CURRENT, high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE);"

But it still doesn't add any borders to up and down candles.
 
keep on experimenting and trying things, that's how i learned.
search the site for addchart( and look at examples.

don't know what you mean by, borders?
if you mean hollow candles, then you swap the open and close numbers

Code:
# addchart_peter_redgreen

# https://usethinkscript.com/threads/could-i-have-heikin-ashi-candles-in-lower-section-in-thinkorswim.10428/#post-92406

declare lower;
def o = open;
def h = high;
def l = low;
def c = close;

# solid or hollow bars  ( swap open and close)
input solid = yes;



# OHLC UP candle
def UpO;
def UpH;
def UpL;
def UpC;
if o < c
then {
#    UpO = o;
    UpO = if solid then o else c;
    UpH = h;
    UpL = l;
#    UpC = c;
    UpC = if solid then c else o;

} else {
    UpO = Double.NaN;
    UpH = Double.NaN;
    UpL = Double.NaN;
    UpC = Double.NaN;
}

# OHLC DOWN candle
def DnO;
def DnH;
def DnL;
def DnC;
if o > c
then {
#    DnO = o;
    DnO = if solid then o else c;
    DnH = h;
    DnL = l;
#    DnC = c;
    DnC = if solid then c else o;
} else {
    DnO = Double.NaN;
    DnH = Double.NaN;
    DnL = Double.NaN;
    DnC = Double.NaN;
}


AddChart(high = UpH, low = UpL, open = UpC, close = UpO, type = ChartType.CANDLE, growcolor = Color.GREEN);
AddChart(high = DnH, low = DnL, open = DnO, close = DnC, type = ChartType.CANDLE, growcolor = Color.RED);
#
In Appearance of Chart Setting of ThinkorSwim, you can choose Ticks options: Border up, Border down, Fill up and Fill down. I would like to know how to add these features to the candles in the indicator properties.
 
In Appearance of Chart Setting of ThinkorSwim, you can choose Ticks options: Border up, Border down, Fill up and Fill down. I would like to know how to add these features to the candles in the indicator properties.
no idea. i never adjust the settings. i write code to do what i want.

take a look at my code in post 16
 
Status
Not open for further replies.

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