Automatic Classification of Japanese Candlestick Patterns

Indicators

Automatic Classification of Japanese Candlestick Patterns


asimon 09-10-2006, 8:05 AM

Japanese candlesticks display price action during a specified period of time and are formed by plotting four important prices of the time period represented. Those prices are: the opening price, highest price, lowest price and closing price, or O H L C in short. Popular periods are 1 minute, 5 and 15 minutes for short term analysis. For medium term 30 minutes, 1 hour and  4 hrs are used. Long term trading uses 1 day and 1 week candles. These are popular values but any interval like 3 min. can be used to build and plot candles.  

The opening and closing price indicate trends, and the highest and lowest values are used to gauge the strength of the trend. The distance between the open and close and the high and low can also be used to gauge the strength of the trend.

The space between the opening and closing price is called the real body of the candle and is represented as a rectangle whose top and bottom indicate opening and closing values. It is painted white or green if the closing value is higher than the opening value, the black or red color is used for the opposite condition. The space between the high and low values and the real body of the candle is represented as a vertical line and is called the wick.

This price charting technique is said to have originated in Japan in the 17 century and used by the rice trader Munehisa Homma. Steve Nison first wrote in the West about this technique and continues to publish books on this topic.

Candlesticks can be used to gauge traders sentiment and detect when a reversal of the trend is inminent. When they are used as trend reversal indicators, the signals generated by these patterns should be confirmed with other indicators such as the ADX to determine the strength of the current trend, and overbought / oversold oscillators such as stochastics or RSI.

The file CandlePatterns.cs contains a framework that implements automated recognition of three popular japanese candlestick patterns: doji, harami, hammer / hanging man. The oCandlePatterns class implements an extensible mechanism for automatically recognizing candle stick patterns.

Create a free account and login to the forums to download the Source Code for the 4XLab.NET software

The doji is one of the simplest patterns to recognize, it features open and close prices that are close together. This is referred to as not having a real body. The body of a candle is the space between the opening and closing price. If the high and low value do not extend far from the open and close values, it is a simple doji and it resembles a plus (+) sign.

This pattern indicates indecision, or struggle between buyers and sellers, bulls and bears. The period opened and closed virtually at the same value, the attempt for prices to move higher or lower failed and instead closed near the opening. This is a significant reversal pattern when it occurs at the top of bottom of a trend. As with any other candlestick pattern, it should be confirmed either with trend strength and overbought / oversold indicators or with the next candle (the rule of twos).

There are several variations of the doji pattern involving the length of the high and low portions of the candle. These variations are called: Long Legged Doji, Dragonfly Doji, and Gravestone Doji.

A harami, or pregnant candle, is a pattern where a previous candle completely engulfes the next candle. The open and close values of the next candle (the child) are contained within the open and close values of the previous candle (the mother). The high and low values are not used to detect this pattern. It is not agreed if the next candle should be of the opposite direction, but if so, the strength of this pattern increases.

The hammer pattern consists of a small body with a long lower wick and a very small or no upper wick. The wick should be twice as big as the real body. This is another reversal pattern. If it occurs at the end of a downtrend, it is called a hammer. It is called a hanging man if it occurs at the end of an uptrend.

Read more about it:

http://en.wikipedia.org/wiki/Candlestick_chart

http://stockcharts.com/help/doku.php?id=chart_school:chart_analysis:candlestick_pattern_dictionary

Automatic Classification of Japanese Candlestick Patterns


asimon 09-10-2006, 8:30 AM

//
// 4X Lab.NET © Copyright 2005-2006 ASCSE LLC
// http://www.4xlab.net
// email: 4xlab@4xlab.net
//

// This method from the file CandlePatterns.cs shows how a Doji candlestick pattern is detected.

        private bool isDoji(ref double pStrength, ref string pComments)
        {
            bool v = false;
            pStrength = -1;
            pComments = "";

            double O=Candles[CandleIndex(0,tickcount)].O;
            double H=Candles[CandleIndex(0,tickcount)].H;
            double L=Candles[CandleIndex(0,tickcount)].L;
            double C=Candles[CandleIndex(0,tickcount)].C;

            if (
                (Math.Abs(O-C)<0.0002)    &&                // open and close near each other
                (Math.Abs(H-Math.Max(O,C)) > 0.0001) &&     // has upper body
                (Math.Abs(L-Math.Min(O,C)) > 0.0001)        // has lower body
                ) 
            {
                v = true;
            }

            if (v)
            {
                if (
                    (Math.Abs(H-Math.Max(O,C)) > 0.0004) &&
                    (Math.Abs(L-Math.Min(O,C)) > 0.0004) &&
                    (Math.Abs(Math.Abs(H-Math.Max(O,C)) / Math.Abs(L-Math.Min(O,C))) > 0.8)
                    )
                {
                    pComments += " Long Legged";
                }

                if (
                    (( Math.Abs(H-Math.Max(O,C)) / Math.Abs(L-Math.Min(O,C)) ) < 0.1)
                    )
                {
                    pComments += " Dragonfly";
                }

                if (
                    ((Math.Abs(L-Math.Min(O,C)) / Math.Abs(H-Math.Max(O,C))) < 0.1)
                    )
                {
                    pComments += " Gravestone";
                }

            }

            return v;
        }

Forex Lab .NET | 4X Lab .NET © Copyright 2005-2006 ASCSE LLC | Disclaimer

Powered by Community Server, by Telligent Systems