Note from Towards Data Science’s editors:_ While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details._

Quantitative traders know that they need to extract as much information as possible from price charts. Price action is a very useful technique to spot trading opportunities, but it’s sometimes difficult to read because candlestick charts might be messy or noisy. So, traders need a tool to smooth price action and remove noise. Heikin Ashi candles can help us. Let’s see how.

What are Heikin Ashi candles?

Heikin Ashi candles (sometimes called Heiken Ashi) are a particular kind of candlestick chart that tries to remove noise from price action. Particularly, in this kind of chart, there are no gaps.

Let’s see a chart of S&P 500 with plain candlesticks.

S&P 500 chart. Image by the author.

As you can see, there are a lot of daily gaps and the shadows of the candles are sometimes wide and make it difficult to decide what to do.

Heikin Ashi candles are calculated this way:

  • Open: (Open (previous candle) + Close (previous candle))/2
  • Close: (Open + Low + Close + High)/4
  • High: the same of the actual candle
  • Low: the same of the actual candle

As you can see, the calculation of today’s HA candle uses data from both today’s and yesterday’s candles. This way, HA candles smooth price action.

The result, applied to the same chart is:

S&P 500 chart with Heikin Ashi candles. Image by the author

As you can see, there are no gaps and the chart is easier to read.

How to use Heikin Ashi charts?

Using HA charts is very simple. First of all, we can see that before an important reversal we can detect some spinning top patterns, that are candles with very small real body and large shadows of almost the same size. This is an important way to detect a trend reversal.

Then, we can see that when the trend is strong, the opposite shadow is almost absent (i.e. in a strong bullish trend, lower shadows are invisible and in a strong bearish trend, upper shadows are invisible). This gives us a clear overview of the strength of a trend. Finally, a color change is very often used as a confirmation that the trend has changed direction and may be used as an operative signal.

These are all useful items for building a trading strategy and we don’t need to be able to catch several types of patterns like in candlestick charts, but we only need to spot spinning tops and color changes.

The drawback of Heikin Ashi candles is that, like any other kind of moving average, they catch the trend reversal with some delay. So, their signals are always a confirmation of something that has already happened. Thus, they are useful only then you have to work with long-term strategies because the delay in the signal will always make you enter and exit late. However, HA candles are a very useful tool, especially when you work with scalping and need to smooth very noisy price action. Just like any other indicator, it’s useful to use it with another signal, for example with moving averages.

Let’s now see how to calculate Heikin Ashi candles in Python.

#algorithmic-trading #trading #algorithms #investing #python

How to calculate Heikin Ashi candles in Python for trading
6.15 GEEK