# Heikin Ashi candle color control

**URL:** <https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771>\
**Category:** Custom Indicators\
**Created:** [July 26, 2021, 1:17am UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771 "2021-07-26T01:17:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MadCat](https://sea1.discourse-cdn.com/flex015/user_avatar/community.tradovate.com/madcat/32/1416_2.png) [@MadCat](https://community.tradovate.com/u/MadCat)\
**Post date:** [July 26, 2021, 1:17am UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/1 "2021-07-26T01:17:40Z")

</div>

Is it possible to have an overlay indicator created to change the color of a candle when it forms a particular way?

I want to be able to control the color of Heikin Ashi candle when it is considered strongly directional. when price movement is strong Heikin Ashi candles only print a wick on one side of the candle, when price is more indecisive it prints wicks on both sides of the candle. When the Candle prints with one wick on one side i want to be able to control the color for quick glance clarity. Unless you are zoomed in on Heikin Ashi charts you can miss Candles with small double wicks.

 ![Screen Shot 2021-07-25 at 5.42.54 PM](https://us1.discourse-cdn.com/flex015/uploads/tradingforum/original/2X/7/799b519c11838758077d031fa0064a89fb478267.png)

Hey @latter-day-trader do you have any experience with this?

Is this even possible with Tradovate’s Java Script?

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [July 26, 2021, 8:17pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/2 "2021-07-26T20:17:22Z")

</div>

@MadCat

Yes, you should be able to. I didn’t implement your logic, but I have other candle coloring indicator and it seems to work on a Heikin Ashi chart. Here is a snippet you can use modify at the end of your map() function:

```auto
        // return a blank object as default
        let rtn = {};
        
        
        // put your conditions for coloring 
        if (!d.isLast() && (buy || sell)) {
            // if conditions are met, set you color
            const color = buy ? this.props.BuyColor : this.props.SellColor;

            // this is where the coloring of the candlestick actually happens
            rtn["candlestick"] = { color: color };
        }
        
        return rtn;
```

---

<div class="post-metadata">

**Author:** ![KE\_vf](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@KE\_vf](https://community.tradovate.com/u/KE_vf)\
**Post date:** [October 19, 2021, 3:15am UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/3 "2021-10-19T03:15:24Z")

</div>

Hi.  
I was looking to do something similar to what you outlined here. I was trying to change the color of a Heikin Ashi candle when I have MA lines go through it during the same period ( ex: 2min or 5 min candle). Can you give a suggestion?

I appreciate any help you can offer

Thanks

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [October 19, 2021, 4:35am UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/4 "2021-10-19T04:35:05Z")

</div>

You would obviously need to copy or create an indicator that calculates the MA. Then in the map() function and using the previous code snippet as a model, you would just have to check for the conditions you care about. Here is an incomplete example:

```auto
// TODO: Calculate the mavg here. See the moving average indicators

let rtn = {};
let candleColor = undefined;

if (d.open() < d.close() && mavg > d.open() && mavg < d.close()) {
    // mavg is between the body of a bullish candle
    candleColor = "dodgerBlue"; 
} else if (d.open() > d.close() && mavg < d.open() && mavg > d.close()) {
    // mavg is between the body of a bearish candle
    candleColor = "pink";
} else if (mavg > d.low() && mavg < d.high()) {
    // mavg is between the high and lows of the candle
    candleColor = "gray";
}

// Remove the !d.isLast() if you want to also change the color on the current bar
if (!d.isLast() && candleColor) {
    rtn["candlestick"] = { color: candleColor };
}

return rtn;

```

---

<div class="post-metadata">

**Author:** ![KE\_vf](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@KE\_vf](https://community.tradovate.com/u/KE_vf)\
**Post date:** [October 19, 2021, 1:20pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/5 "2021-10-19T13:20:23Z")

</div>

I have a few MAs, (3 SMA & 1 WMA). Is the below code that I added sufficient to account for all the MAs so that it can turn the candle a different color when all of them intersect the same candle time frame.

When completed, do I just add this as a expression in worksheets?

Thanks for taking the time to assist

_// TODO: Calculate the mavg here. See the moving average indicators_

class simpleMovingAverage {

init() {

this.sma = SMA(this.props.period);

}

map(d) {

return this.sma(d.value());

}

}

let rtn = {};

let candleColor = undefined;

**if** (d. **open** () \< d.close() && mavg \> d. **open** () && mavg \< d.close()) {

_// mavg is between the body of a bullish candle_

candleColor = “dodgerBlue”;

} **else**  **if** (d. **open** () \> d.close() && mavg \< d. **open** () && mavg \> d.close()) {

_// mavg is between the body of a bearish candle_

candleColor = “pink”;

} **else**  **if** (mavg \> d.low() && mavg \< d.high()) {

_// mavg is between the high and lows of the candle_

candleColor = “gray”;

}

_// Remove the !d.isLast() if you want to also change the color on the current bar_

**if** (!d.isLast() && candleColor) {

rtn[“candlestick”] = { color: candleColor };

}

**return** rtn;

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [October 19, 2021, 4:15pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/6 "2021-10-19T16:15:18Z")

</div>

Sorry, I have never used the worksheet. The above code was for a custom indicator. Not sure if it would work with worksheets.

---

<div class="post-metadata">

**Author:** ![KE\_vf](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@KE\_vf](https://community.tradovate.com/u/KE_vf)\
**Post date:** [October 19, 2021, 6:52pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/7 "2021-10-19T18:52:47Z")

</div>

can I ask what software you use to create and export tools into Code Explorer? I wanted to add a wma.js to a indicators tools but it won’t allow me so it looks like I have to try and create a new indicator.

Thanks

---

<div class="post-metadata">

**Author:** ![latter-day-trader](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@latter-day-trader](https://community.tradovate.com/u/latter-day-trader)\
**Post date:** [October 19, 2021, 8:01pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/8 "2021-10-19T20:01:07Z")

</div>

You can create a new file in Code Explorer and name it wma.js or whatever you like. Then copy the code from from the file you have into that new file in Code Explorer. Just first delete all the default code that Code Explorer puts there.

Then you can just reference that file by using a require statement in your indicator.

---

<div class="post-metadata">

**Author:** ![KE\_vf](https://avatars.discourse-cdn.com/v4/letter/k/f0a364/32.png) [@KE\_vf](https://community.tradovate.com/u/KE_vf)\
**Post date:** [October 19, 2021, 9:21pm UTC](https://community.tradovate.com/t/heikin-ashi-candle-color-control/2771/9 "2021-10-19T21:21:17Z")

</div>

First thanks for your help…  
Is it hard to either have a Candle change color or add a arrow or dot above the the candle if multiple moving averages intersect the same time frame candle (2 min chart 3 sma lines go through the same candle during the 11:11am time frame)?  
I needed to add another moving average line to a indicator but this is what I’m trying to accomplish.  
Thanks
