Trading With the Heikin-Ashi Candlestick Oscillator

7
Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort Copyright (c) Technical Analysis Inc. INDICATORS Visual, Digital Candlesticks This visual tool complements candlesticks that will help you enter and exit trades, resulting in higher profits per trade. by Sylvain Vervoort nalyzing a candlestick chart gives a good idea of what is going on in the market. Candlestick patterns, resistance or support from price pivots, rising or falling windows, and the use of trendlines are all excellent technical trad- ing tools. But initiating a trade and deciding when to close it, candle after candle, remains a difficult task. It would be nice Trading With The Heikin-Ashi to have a complementary visual aid when looking at a candle chart. Figure 1, a daily chart for Ford Motor Co., uses an expert function for color-coding the candlesticks. On November 21, 2006, the price falls through the uptrend line after a number of green candles. This means it’s time to close any long position and open a new short position. As long as there are red candles, we will keep the short trade open. On December 20, 2006, there is a new green candle. Drawing a downtrend line up to this point, we see that it is broken to the upside. It’s time to close the short position and open a new long position. On February 13, 2007, we have a first red candle. Drawing the uptrend line, we see that the closing price remains above A A Candlestick Oscillator

Transcript of Trading With the Heikin-Ashi Candlestick Oscillator

Page 1: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

INDICATORS

Visual, Digital Candlesticks

This visual tool complements candlesticks that will help youenter and exit trades, resulting in higher profits per trade.

by Sylvain Vervoort

nalyzing a candlestick chart gives a good ideaof what is going on in the market. Candlestickpatterns, resistance or support from pricepivots, rising or falling windows, and the useof trendlines are all excellent technical trad-

ing tools. But initiating a trade and deciding when to close it,candle after candle, remains a difficult task. It would be nice

Trading With The Heikin-Ashi

to have a complementary visual aid when looking at a candlechart.

Figure 1, a daily chart for Ford Motor Co., uses an expertfunction for color-coding the candlesticks. On November 21,2006, the price falls through the uptrend line after a numberof green candles. This means it’s time to close any longposition and open a new short position. As long as there arered candles, we will keep the short trade open. On December20, 2006, there is a new green candle. Drawing a downtrendline up to this point, we see that it is broken to the upside. It’stime to close the short position and open a new long position.

On February 13, 2007, we have a first red candle. Drawingthe uptrend line, we see that the closing price remains above

AA

Candlestick Oscillator

Page 2: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

the uptrend line. As a rule, we will wait for the next day.The price continues above the trendline and the candlesare turning green again. On February 22, 2007, there isanother red candle. Now, the uptrend line is broken, sowe close the long position eventually, opening a newshort position. The color-coded candlesticks make dailyfollowup easy and relaxing. Want to know how this isdone? Of course you do.

THE STARTING IDEAA good starting point is the heikin-ashi† chart. In thedaily chart of Sysco Corp. in Figure 2, you can see thetraditional candlestick chart on the top and the heikin-ashi chart on the bottom. Visually, the heikin-ashicandles look very consistent. In a downtrend, we see

9.19.08.98.88.78.68.58.48.38.28.18.07.97.87.77.67.57.47.37.27.17.06.96.8

3 30 6 13 20 27 4 11 18 26 3 16 22 29 5 12 20 26February2007DecemberNovember

34

33

32

31

30

29

28

27

33

32

31

30

29

28

27

3110 17 24 21 5 11 18 25 2 928147AugustJuly September October

SYSCO Corp.normalcandles

SYSCO Corp.heikin-ashi

candles

34.033.533.032.532.031.531.030.530.029.529.028.528.027.527.0

33

32

31

30

29

28

27

3110 17 24 21 5 11 18 25 2 928147July September OctoberAugust

Heikin-ashicolor-coded

candles

mostly black candles with no or small upper shadows. In anuptrend, there are mostly white candles with no or smalllower shadows.

First, I am going to color-code the normal candle chart withthe information from the heikin-ashi chart. A white heikin-ashi candle will paint the normal candlestick green and ablack heikin-ashi candle will paint the normal candlestickred. The result can be seen in Figure 3. To do this inMetaStock, we create an expert function and link it to thechart. In the highlights tab of the expert editor, we firstintroduce the formula to create a green candle when theheikin-ashi closing price is greater than or equal to the heikin-ashi opening price and we link a green color to a positiveoutcome:

{green candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;haC:=((O+H+L+C)/

4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;ClHa:=haC>=haOpen;ClHa

We do the same for creating a red candle with this secondformula when the heikin-ashi closing price is smaller thanthe opening price and we link red to it.

{red candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;ClHa:=haC<haOpen;ClHa

The execution priority is a green candle followed by a redcandle. That way, the red candle function is only executed ifthe green candle function has a negative outcome (not true).

FIGURE 1: COLOR-CODED CANDLESTICKS. A short trade can be opened when price fallsthrough the uptrend line. The short trade is open till the downtrend line is broken to the upside.

ME

TA

ST

OC

K

FIGURE 2: THE HEIKIN-ASHI CHART. Here you see a traditional candlestick charton the top and a heikin-ashi chart on the bottom. As you can see, the heikin-ashichart is very consistent.

FIGURE 3: COLOR-CODING USING INFORMATION FROM HEIKIN-ASHI. A whiteheikin-ashi candle will paint the normal candlestick green and a black heikin-ashicandle will paint the normal candlestick red.

Page 3: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

16.5

16.0

15.5

15.0

14.5

14.0

13.5

16.5

16.0

15.5

15.0

14.5

14.0

3 10 17 24 31 7 14 21 28 5 12 19 27March April May

NOT A PERFECT WORLDUnfortunately, results are not always go-ing to be as positive as what you see in theSysco chart. In this case, there is a nicerange of red candles in the downtrend anda longer series of green candles in theuptrend. Wouldn’t it be great if priceswere moving like that all the time?

But as we know all too well, the marketis not going to move perfectly all the time.Note in Figure 4 how the colors are lessconsistent and much less usable for enter-ing or exiting a trade. It is clear that in anyup- or downtrend, there must be room forsome price reaction.

Let’s try some techniques to keep thebars as green as possible during an uptrend,with little delay at turning points. First,we can eliminate all single-day reactionsby extending a previous green candle byat least one more bar. In the TWX ex-ample, this adds eight more green candlesin the uptrend (Figure 5). To do this, wechange the green candle and red candleformulas as follows:

{green candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min

(L,haOpen))/4;ClHa:=Alert(haC>=haOpen,2);ClHa

{red candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;

17.0

16.5

16.0

15.5

15.0

14.5

14.0

13.53 10 17 24 31 7 14 21 28 5 12 19 27 225191142822

February March April May June

FIGURE 4: NOT A PERFECT WORLD. Here, the colors are less consistent and cannot be used for entering orexiting a trade.

haC:=((O+H+L+C)/

4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;ClHa:=Alert(haC<haOpen,2);ClHa

But a number of red candles are still left that we would liketo eliminate in the uptrend. The second step is to see if the newcandle comes after a green candle, or if it is a white candle(close above open). If it is the latter, there is no need to changethe color because the bars still point in the direction of theuptrend. In Figure 6 you can see that another two red candlesare eliminated by this second step. The green candle and redcandle formulas have now been changed as follows:

{green candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;ClHa:=Alert(haC>=haOpen,2);ClHa OR (Ref(ClHa,-1) AND (C>=O OR C>=Ref(C,-

FIGURE 5: AS GREEN AS POSSIBLE. All single-day reactions can be eliminated by extending a previous greencandle by at least one more bar.

1)))

{red candle}haOpen:=(Ref((O+H+L+C)/4,-1)+PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;ClHa:=Alert(haC<haOpen,2);ClHa OR (Ref(ClHa,-1) AND (C<O OR C<Ref(C,-1)))

In the third step, we will use a fast crossover system to allowa minimum price reaction while still being very fast at theturning points. We will employ the zero-lag crossover systemthat I introduced in my article in the STOCKS & COMMODITIES

May 2008 issue. The code can be found here (upper left) in thesidebar, “MetaStock crossover formula.”

We consider an uptrend (green candle) when ZlDif is equalto or greater than zero. I am using a triple exponential movingaverage (TEMA) of 34 bars. You may want to make that valuesmaller or bigger if you want to allow less or more pricereaction.

At the price pivot point levels, often there are doji candlesor spinning tops or bottoms with a small body compared to

Page 4: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

Initiating a trade and decidingwhen to close it, candle aftercandle, remains a difficult task.

METASTOCK CROSSOVER FORMULA

avg:=34;haOpen:=(Ref((O+H+L+C)/4,-1) +PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;TMA1:= Tema(haC,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlHa:= TMA1 + Diff;TMA1:= Tema((H+L)/2,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlCl:= TMA1 + Diff;ZlDif:=ZlCl-ZlHa;ZlDif

16.5

16.0

15.5

15.0

14.5

14.0

16.5

16.0

15.5

15.0

14.5

14.0

17 24 31 7 14 21 28 5 12 19 27April May

FIGURE 6: DO THE BARS POINT IN THE RIGHT DIRECTION? We can take this one step further and eliminatemore red candles in an uptrend.

the high-low price. To eliminate them, Imust introduce a last step. That step is notchanging the green color when the previ-ous candle is green and the size of the realbody is smaller than 35% of the full high–low range. In addition, the high must behigher than the previous low to make surethere is no window in between. The finalresult can be seen in Figure 7.

There are now only green candles dur-ing the entire uptrend. We get a sell signal on the first redcandle. Drawing uptrend lines at this point shows a third,steeper trendline that has been broken downward. This tellsus it is time to sell. The complete expert formula“_Uptrend_HA” can be found in the sidebar “MetaStock andthe last step.”

The order of execution is first the formula (green candle)and then the red candle only when the green candle is false.With the green candle uptrend expert we have a useful tool tokeep us in an uptrend and detect a downward trend reversal.

What we need next is an equally effective expert for adowntrend. For this we can simply reverse the executionorder and put a red candle on top of a green candle in theexpert editor. Or you can create another expert and call it“_Downtrend_HA” with the same formulas to be introducedin the expert editor, but now with an inverse execution order— formula (red candle) first, followed by the (green candle)formula.

Figure 8, a graphic of KBH, shows a downtrend. In the lowerpart of the chart, we used the expert function “_Uptrend_HA.”The first red candle here is the reversal signal for going short. Theupper part is the expert function “_Downtrend_HA.” We willstay short as long as there are red candles. With the first greencandle, we would close the short position and eventually open along position.

Unfortunately, there is no perfect system. You may receivesignals to exit a trade when it is probably better to hold onto thetrade. The idea is not to trust this system blindly. When you arefaced with a reversal signal, you must use all available technicalanalysis techniques to make an intelligent decision, preferablysupported by more than one technique.

Figure 9 illustrates the use of combined techniques. From

the “_Downtrend_HA” expert, we receive a buy signal at(1). So we are now looking at the “_Uptrend_HA” candlechart. We are combining this chart with a fast indicator likemy SVAPO (see my article in the November 2007 issue ofSTOCKS & COMMODITIES) to find out if there is a greaterchance for a move up or down.

In early March, we had a red selling bar at (2). Here we wouldhold on to the long position at least for one more day because theclosing price remains well above the last support line, andSVAPO is below the lower reference line, suggesting the possi-bility of an up move for the following bars.

We have an uptrend line drawn from the beginning of theup move through the low at (2). We have drawn a parallel linethrough the previous top to form an uptrend channel. At the endof March, we have a second selling signal at (3). But there areenough reasons to hold onto the position. The price remainsabove the uptrend line within the uptrend channel and a closingprice above the last support while SVAPO is below the lowerreference line, suggesting a higher chance of an up move.

The next selling signal appears in the first half of April, butthe price remains above the uptrend line within the uptrendchannel and a closing price above the last support. Duringthis activity, SVAPO is moving up. The price continues tomove up and reaches the upper side of the trend channel,making a top above the upper SVAPO reference line. At (5)

Page 5: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

price drops through the last steeper uptrendline and we get another red selling bar.This is a good profit-taking moment.

Next, selling signals appear at (6) whenthe closing price drops through the lastsupport line, and at (7), when price dropsout of the trend channel. If you preferusing an oscillator instead of color-codedcandlesticks, you can use the heikin-ashicandlesticks oscillator (HACO), which Iwill explain next.

INTRODUCING HACOHACO is a digital oscillator version of thecolored candlesticks. It has either a valueof zero for a red candle or “1” for a greencandle. The basic formula is taken fromthe green candle and the red candle out ofthe “_Uptrend_HA” expert. TheMetaStock code for the HACO can befound in the sidebar “The heikin-ashi candle-stick oscillator (HACO).”

On the chart of General Electric (GE) inFigure 10, you’ll see the HACO on the topsubchart. I have colored the price chart soFIGURE 7: TWEAKING THE TREND EVEN FURTHER. We can go one more step further and eliminate any

dojis, spinning tops or bottoms, and other similar patterns.

{red candle}avg:=34;haOpen:=(Ref((O+H+L+C)/4,-1) + PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;TMA1:= Tema(haC,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlHa:= TMA1 + Diff;TMA1:= Tema((H+L)/2,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlCl:= TMA1 + Diff;ZlDif:=ZlCl-ZlHa;keep1:=Alert(haC>=haOpen,2);keep2:=ZlDif>=0;keeping:=(keep1 OR keep2);keepall:=keeping OR (Ref(keeping,-1) AND (C>=O) ORC>=Ref(C,-1));keep3:=(Abs(C-O)<(H-L)*.35 AND H>=Ref(L,-1));utr:=Keepall OR (Ref(keepall,-1) AND keep3);keep1:=Alert(haC<haOpen,2);keep2:=ZlDif<0;keep3:=Abs(C-O)<(H-L)*.35 AND L<=Ref(H,-1);keeping:=keep1 OR keep2;keepall:=keeping OR (Ref(keeping,-1) AND (C<O) ORC<Ref(C,-1));dtr:=If(Keepall OR (Ref(keepall,-1) AND keep3)=1,1,0);upw:=dtr=0 AND Ref(dtr,-1) AND utr;dnw:=utr=0 AND Ref(utr,-1) AND dtr;result:=If(upw,1,If(dnw,0,PREV));result=0

METASTOCK AND THE LAST STEP (Note: The MetaStock expert for an uptrend is “_Uptrend_HA”)

{green candle}avg:=34;haOpen:=(Ref((O+H+L+C)/4,-1) + PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;TMA1:= Tema(haC,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlHa:= TMA1 + Diff;TMA1:= Tema((H+L)/2,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlCl:= TMA1 + Diff;ZlDif:=ZlCl-ZlHa;keep1:=Alert(haC>=haOpen,2);keep2:=ZlDif>=0;keeping:=(keep1 OR keep2);keepall:=keeping OR (Ref(keeping,-1) AND (C>=O) ORC>=Ref(C,-1));keep3:=(Abs(C-O)<(H-L)*.35 AND H>=Ref(L,-1));utr:=Keepall OR (Ref(keepall,-1) AND keep3);keep1:=Alert(haC<haOpen,2);keep2:=ZlDif<0;keep3:=Abs(C-O)<(H-L)*.35 AND L<=Ref(H,-1);keeping:=keep1 OR keep2;keepall:=keeping OR (Ref(keeping,-1) AND (C<O) ORC<Ref(C,-1));dtr:=If(Keepall OR (Ref(keepall,-1) AND keep3)=1,1,0);upw:=dtr=0 AND Ref(dtr,-1) AND utr;dnw:=utr=0 AND Ref(utr,-1) AND dtr;result:=If(upw,1,If(dnw,0,PREV));result

16.5

16.0

15.5

15.0

14.5

14.0

16.5

16.0

15.5

15.0

14.5

14.0

13.5

3 10 17 24 31 7 14 21 28 5 12 19 27 2March April May June

Page 6: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

55

50

45

55

50

45

2 20 26 5 12 19 26 2 9 16March April

2008 March April May

SVAPO(1,3)

JuneFebruary

25.525.024.524.023.523.022.522.021.521.020.520.019.519.018.518.0

0

-5

1 2

34

56

7

FIGURE 8: DOWNTRENDS. Here you see red candle and green candle formulas. As long as there are redcandles, it’s best to stay short.

FIGURE 9: COMBINING TREND CHARTS WITH SVAPO. Using trend charts with a fast indicator like SVAPOadds confirmation to your buy/sell decisions.

you can easily see the periods with a longposition (green) and with a short position(red). HACO is not meant to be an auto-matic trading system, so when there is abuy or sell signal from HACO, make sureit is confirmed by other technical analysistechniques. HACO will certainly aid insignaling buy and sell opportunities andhelp you hold onto a trade, making it moreprofitable.

In early 2004, you can probably avoida short position in GE for just a couple ofdays, generating more net profit. You canchange the input value in the HACO for thezero-lag TEMA in the up and down moves.Basically, you would use the same valuefor both entries. If you use different val-ues, it will work fine most of the time, butthere may be some unexpected results.This is because using different up anddown TEMAs will mean no synchroniza-tion between the up and down compo-nents.

The behavior of HACO is closely re-lated to the level and speed of price change.It can be used on charts of any time frameranging from intraday to monthly.

Sylvain Vervoort lives in the Flemish part ofBelgium and is a retired electronics engi-neer, studying and using technical analysisfor more than 30 years. He is an indepen-dent trader, writer, publisher, and educatorin the area of technical analysis and op-tions. Sylvain Vervoort may be reached athis website at http://stocata.org/.

ADDITIONAL READINGMulloy, Patrick [1994]. “Smoothing Data

With Less Lag,” Technical Analysis ofSTOCKS & COMMODITIES, Volume 12:February.

Valcu, Dan [2004]. “Using The Heikin-Ashi Technique,” Technical Analysisof STOCKS & COMMODITIES, Volume22: February.

Vervoort, Sylvain [2008]. “The QuestFor Reliable Crossovers,” TechnicalAnalysis of STOCKS & COMMODITIES,Volume 26: May.

_____ [2007]. “Short-Term Volume AndPrice Oscillator,” Technical Analysisof STOCKS & COMMODITIES, Volume25: November.

Page 7: Trading With the Heikin-Ashi Candlestick Oscillator

Stocks & Commodities V. 26:12 (50-57): Trading With The Heikin-Ashi Candlestick Oscillator by Sylvain Vervoort

Copyright (c) Technical Analysis Inc.

THE HEIKIN-ASHI CANDLESTICK OSCILLATOR (HACO)

{HACO}avg:=Input(“Up TEMA average: “,1,100,34);avgdn:=Input(“Down TEMA Average: “,1,100,34);haOpen:=(Ref((O+H+L+C)/4,-1) + PREV)/2;haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;TMA1:= Tema(haC,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlHa:= TMA1 + Diff;TMA1:= Tema((H+L)/2,avg);TMA2:= Tema(TMA1,avg);Diff:= TMA1 - TMA2;ZlCl:= TMA1 + Diff;ZlDif:=ZlCl-ZlHa;keep1:=Alert(haC>=haOpen,2);keep2:=ZlDif>=0;keeping:=(keep1 OR keep2);keepall:=keeping OR (Ref(keeping,-1) AND (C>=O) ORC>=Ref(C,-1));keep3:=(Abs(C-O)<(H-L)*.35 AND H>=Ref(L,-1));utr:=Keepall OR (Ref(keepall,-1) AND keep3);

TMA1:= Tema(haC,avgdn);TMA2:= Tema(TMA1,avgdn);Diff:= TMA1 - TMA2;ZlHa:= TMA1 + Diff;TMA1:= Tema((H+L)/2,avgdn);TMA2:= Tema(TMA1,avgdn);Diff:= TMA1 - TMA2;ZlCl:= TMA1 + Diff;ZlDif:=ZlCl-ZlHa;keep1:=Alert(haC<haOpen,2);keep2:=ZlDif<0;keep3:=Abs(C-O)<(H-L)*.35 AND L<=Ref(H,-1);keeping:=keep1 OR keep2;keepall:=keeping OR (Ref(keeping,-1) AND (C<O) ORC<Ref(C,-1));dtr:=If(Keepall OR (Ref(keepall,-1) AND keep3)=1,1,0);upw:=dtr=0 AND Ref(dtr,-1) AND utr;dnw:=utr=0 AND Ref(utr,-1) AND dtr;result:=If(upw,1,If(dnw,0,PREV));result

—S.V.

0.5

35.034.534.033.533.032.532.031.5

30.530.029.529.028.528.027.527.0

FebruaryNovember 2004 March April May June

FIGURE 10: HACO. The long positions are displayed in green and short positions in red. S&C