Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Heikin Ashi Smoothed code help (Color)
Updated October 25, 2020
trending_up
13,125 views
thumb_up
3 thanks given
group
2 followers
forum
4 posts
attach_file
1 attachments
Heikin Ashi Smoothed code help (Color)
February 17th, 2015, 11:36 PM
New York, New York / United States
Experience: Beginner
Platform: ThinkOrSwim
Trading: CL, ES, Currencies
Posts: 38 since Feb 2015
Thanks Given: 13
Thanks Received: 22
I recently found a code for smoothed heiken ashi bars, however for some reason all the bars are red (down trend). I'm pretty sure I should be putting some if else statements at the end there. Any ideas?? Thanks!
Source Code:
input period = 6;
input hideCandles = YES;
input candleSmoothing = {default Valcu, Vervoort};
DefineGlobalColor("RisingMA", color.green);
DefineGlobalColor("FallingMA", color.red);
input movingAverageType = {default Simple, Exponential, Weighted, Hull, Variable, TEMA};
def openMA;
def closeMA;
def highMA;
def lowMA;
switch (movingAverageType) {
case Simple:
openMA = compoundValue(1, Average(open, period), open);
closeMA = compoundValue(1, Average(close, period), close);
highMA = compoundValue(1, Average(high, period), high);
lowMA = compoundValue(1, Average(low, period), low);
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 Weighted:
openMA = compoundValue(1, WMA(open, period), open);
closeMA = compoundValue(1, WMA(close, period), close);
highMA = compoundValue(1, WMA(high, period), high);
lowMA = compoundValue(1, WMA(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 variable:
openMA = compoundValue(1, VariableMA(open, period), open);
closeMA = compoundValue(1, VariableMA(close, period), close);
highMA = compoundValue(1, VariableMA(high, period), high);
lowMA = compoundValue(1, VariableMA(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) ;
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.hide();
def haLow = min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);
AddChart(high = haHigh, low = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
February 18th, 2015, 06:10 PM
Puerto Rico
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441
The last part is an unsupported feature, it's not documented anywhere. With the last update to the platform it stopped working. The growColor is being ignored. It used to work fine before the last update, hopefully they will fix it in the future but since it is a hidden feature who knows.
AddChart(high = haHigh, low = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);
February 18th, 2015, 10:50 PM
New York, New York / United States
Experience: Beginner
Platform: ThinkOrSwim
Trading: CL, ES, Currencies
Posts: 38 since Feb 2015
Thanks Given: 13
Thanks Received: 22
rmejia
The last part is an unsupported feature, it's not documented anywhere. With the last update to the platform it stopped working. The growColor is being ignored. It used to work fine before the last update, hopefully they will fix it in the future but since it is a hidden feature who knows.
AddChart(high = haHigh, low = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);
Thanks for the comment! I figured this out last night. Do you think there's a way around it? Pseudocode looks something like:
AssignPriceColor(
if haclose > haopen then color.GREEN,
if haopen > close then color.RED,
else then color.GREY);
I'm not quite sure if anything like this is possible but it seems plausible. I just don't know enough about thinkscript, or coding, or pretty much trading in general.
Thanks again!
February 19th, 2015, 07:50 AM
Puerto Rico
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 441
Unfortunately I don't know of anything that can be done. I use the addchart on a lower study where the candles used to be red and green but after this broke I just changed it to black. At least the candles are different by fill so there is contrast from that, tho not as clear as using 2 colors.
October 25th, 2020, 07:21 PM
Spring Hill Kansas
Posts: 4 since Jan 2018
Thanks Given: 1
Thanks Received: 1
Here is a link to one that worked for me.
https: // tos .mx/8UUAc2
This is a TOS shared link.
Open in TOS to view/rename and save it
I don't have enough post to be able to post links
Take the spaces out of the link
afoxperson
I recently found a code for smoothed heiken ashi bars, however for some reason all the bars are red (down trend). I'm pretty sure I should be putting some if else statements at the end there. Any ideas?? Thanks!
Source Code:
input period = 6;
input hideCandles = YES;
input candleSmoothing = {default Valcu, Vervoort};
DefineGlobalColor("RisingMA", color.green);
DefineGlobalColor("FallingMA", color.red);
input movingAverageType = {default Simple, Exponential, Weighted, Hull, Variable, TEMA};
def openMA;
def closeMA;
def highMA;
def lowMA;
switch (movingAverageType) {
case Simple:
openMA = compoundValue(1, Average(open, period), open);
closeMA = compoundValue(1, Average(close, period), close);
highMA = compoundValue(1, Average(high, period), high);
lowMA = compoundValue(1, Average(low, period), low);
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 Weighted:
openMA = compoundValue(1, WMA(open, period), open);
closeMA = compoundValue(1, WMA(close, period), close);
highMA = compoundValue(1, WMA(high, period), high);
lowMA = compoundValue(1, WMA(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 variable:
openMA = compoundValue(1, VariableMA(open, period), open);
closeMA = compoundValue(1, VariableMA(close, period), close);
highMA = compoundValue(1, VariableMA(high, period), high);
lowMA = compoundValue(1, VariableMA(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) ;
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.hide();
def haLow = min(lowMA, haOpen);
def haHigh = max(highMA,haOpen);
AddChart(high = haHigh, low = haLow, open = o, close = haclose, type = ChartType.CANDLE, growColor = GlobalColor("RisingMA"), fallColor = GlobalColor("FallingMA"), neutralColor = color.gray);
Last Updated on October 25, 2020