TradingView quirks— Heikin Ashi candles

We’ve been doing trading strategy testing and using the TradingView strategy tools over recent months to quickly look at different indicators. TradingView is a fantastic tool for this. The Pine script doesn’t take more than a few days to learn and you can work very quickly to eyeball and backtest different ideas.

Check out the various overviews and reference to get a sense for what you can do with TradingView and Pine script.

Heikin Ashi candles look to be great, but …

Some strategies call for the use of Heikin Ashi candles which you can select instead of normal candles in the TradingView chart. See end of this post for more on what Heikin Ashi candles are.

Here is an example of a simple indicator that looks to perform OK on Heikin Ashi candles. We can do better than this, but this will illustrate well enough.

Image for post
Image for post

Eyeballing this chart shows that it generally buys low and sells high which is good. Using the TradingView strategy tester to backtest it, also gives good results and profits.

So this is a great indicator that we should be trading, right?

Well … no …

A bug to note

Coding this up into another bot to confirm the strategy, we saw that the profits turned into losses. We couldn’t replicate the TradingView profitable results. So what’s going on?

We need to look at how Heikin Ashi candles work and how TradingView strategy tools work, to understand this.

Heikin Ashi candles

The following picture compares normal and Heikin Ashi candles (source: Investopedia):

Image for post
Image for post

Heikin Ashi are great for identifying momentum more clearly using the red / green than the normal candles.

However they also introduce a small time lag as a consequence.

The close and the open end up being determined by averages from the current and the previous ‘normal’ candle. And this means that Heikin Ashi candles are a bit delayed compared to the real prices in the market.

In particular the close price of the Heikin Ashi candles is a blended average of values from the current and the previous bar.

The key point is that the Heikin Ashi close is not the current close price of the market.

TradingView strategy tester

When running the TradingView strategy tester using Pine script, it will work out the profit and loss assuming you buy and sell at the candle close in line with the strategy you put in.

When running scripts on normal candles, this is fine as the candle close is the real market price at close of candle and the strategy results are reasonable.

But when using Heikin Ashi candles for the triggers, TradingView assumes you can actually buy and sell at the close price of the Heikin Ashi candle. But we already know that this is not the real current price.

As you would expect, when the strategy triggers a buy, usually the actual close price is significantly higher than the Heikin Ashi close, and vice versa on the sells. So any profit is more than wiped out in the cases we looked at.

So that’s a shame. The profit was actually an illusion.

Unfortunately TradingView doesn’t warn you of this when using non-standard candles and the strategy tester. It is worth being aware of this to save yourself a lot of wasted time and disappointment.

Written by

Insurance meets tech meets music. #insurtech

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store