CODING CANDLESTICKS

The Quantitative Approach in Candlestick Charts Analysis

Victor Likhovidov
There are several ways to use this coding scheme for the purposes of technical analysis. At first it represents a very suitable instrument for psychological interpretations of market sentiment visualized by chart patterns. Secondly we may use candle codes to create different filtering rules in mechanical trading systems. But most interesting is an attempt of direct construction of technical indicators over candle codes. Everything what we need here is appropriate smoothing. Indeed if some candles in a row have large values of codes than application of moving average to the chart of codes will give a rising line. V.v. if bearish candles meet frequently in current window the moving average will tend to lower values. It is very convenient here that maximal possible code of candle is 128, hence the smoothed indicator obtains its values nearly between 0 and 100 as it takes place for many ordinary technical indicators. Application of different standard technical analysis functions (e.g. MA, RSI, MACD, Osc) to the CandleCode chart or its smoothed variants may generate a variety of new technical analysis functions, that surely will be effective tools for analysis of charts and construction of trade systems. So we may see that technical indicators derived from the Candle Code represent a very interesting tools of market charts analysis. While many other indicators use in their construction only one of the candle's elements (e.g. the closing price), the suggested candle code considers the candlestick as a whole object taking into account all price movements fixed in its body and shadows. And as the selection of the thresholds is based on the market statistics, even the code of single candle includes a lot of information about the whole market. Some experience that was obtained in practical use of ICS has shown its ability to generate clear trade signals, in many relations better than signals of usual technical indicators. In particular the ICS signals often show turning points of the market without delay imminent to other indicators. It is reasonable also to expect the most valuable results from using the ICS indicators in computer mechanical trade systems.
back to top

The digital code attributed to the candlestick is defined as the sequence of seven binary digits (Fig. 1).

The first position of this code (binary digit) represents

Color= 1 for white candlestick
Color = 0 for black candlestick

The second position (two binary digits) denotes the body size:

 

Body =

The sequence of binary digits constructed in such a way is considered then as the binary representation of ordinary decimal number. And this number is the code of the particular candlestick. The doji candlestick may seem to have indeterminate code because the color of its body is undefined. But this uncertainty may be easily eliminated by appropriate rule; for example we may assign to doji the color that is inverse relatively to that of previous candle or consider the doji as white if its upper shadow is longer than its lower shadow. Some examples below illustrate the approach. The Fig. 2 shows some approximate relations in geometric sizes of candlesticks elements that were used in the examples.
For the candlesticks represented here we have the following values of codes:
V

The candlesticks 118, 115 (white marubozu), 111 (white opening bozu), 104, 97 (white closing bozu) have directly expressed bullish sense; the candlestick 24 is considered in the literature as bullish,102 - from sideways to bullish.

  1. 111110 = 26 + 25 + 24+ 23 + 22 + 2 = 64+32+16+8+4+2 = 126
  2. 0011000= 24 + 23 = 16 + 8 = 24
  3. 1011011 = 26 + 24 + 23 + 21 + 20 = 64+16+8+2+1 = 91
  4. 1000101 = 26 + 22 + 20 = 69 or 0110101 = 25 + 24 + 22 + 20 = 51

    The sense of the suggested coding scheme consists in assigning the highest values to the most bullish candles. And v.v. the more bearish is the reading of the candle the less is its code. Of course the vital question for the method is what sizes of candles (or of their components) are to be considered as small, middle or large. The adequate answer should be based on statistical analysis of candle sizes. Here are some examples showing that generated in such a manner candle codes are in agreement with common understanding of candle signals adopted in technical analysis.
The candlesticks 3 (black marubozu) and 6 are strong bearish signals, 22 - from sideways to bearish; 108 is oftenly considered as bearish which is in contradiction with the big value of its code. The candlesticks 111 and 8 (with big enough body size) have the names bullish belt-hold and bearish belt-hold respectively; 111 in the bottom of the chart may give a strong bullish signal while 8 at the top of the chart may predict the bearish reversal.
The candlestick 96 is karakasa (umbrella), at the top of the market its name is hanging man, in the bottom of the chart it is hammer; independently of its color arriving of karakasa at the top is sell signal and respectively it is a buy signal in the bottom. The candlestick 32 is an example of shooting star and 63, 57, 53, 51, 48 - doji candlesticks (63 - doji gravestone, 48 - doji dragonfly, 51 - four price doji); different doji variants generate reliable signals about possible changes of trend. Practical realization of suggested idea demands some rules that would allow to decide what size of candle's element (body or shadow) should be considered as small, middle or large. Let us denote the candle components as usual by open, high, low, close and write the following rule

small        if        abs(open - close) < b1
middle      if        b1 <= abs(open - close) < b2
large        if        abs(open - close) >= b2

small        if        (high - max (open, close))< u1
middle      if        u1 <= (high - max (open, close)) < u2
large        if        (high - max (open, close)) = u2

small        if        (low - min (open, close)) < l1
middle      if        l1 <= (low - min (open, close)) < l2
large        if        (low - min (open, close)) < l2

body =
Upper Shadow =
Lower Shadow =
With the fixed choice of thresholds b1, b2, u1, u2, l1, l2 the code assigned to the candlestick is uniquely determined. But the values of those thresholds should vary for different markets as they highly depend on the market's volatility: the candle that looks to be big from the point of view of one market may be small for another. Also the change in time span of the same market (e.g. from hourly to daily charts) will lead to certain shift of thresholds. So there is a need in adaptive methods for selection of thresholds in different markets. One possible approach is based on the analysis of mean-square scattering of candle sizes through Bollinger Bands. The Bollinger Band technical indicator is applied to the sizes of upper shadow (ushd), body (body) and lower shadow (lshd). Due to the definition of Bollinger Band as the measure of mean-square scattering it represents appropriate estimate for the volatility of sizes of candle's elements. BBandTop function gives upper threshold while BBandBot is used as lower threshold. "Deviations" parameter in Bollinger Band was set 0.5 and it means according to the standard normal distribution that three ranges have nearly equal probabilities: 0.38 for middle size and 0.31 for both small and large elements. Time period everywhere is 55.
I have introduced here two threshold values (lower and upper) for each candle's element: b1 < b2 for the body, u1 < u2 for upper shadow and l1< l2 for lower shadow, having the sense - if the size of candle element is less than lower threshold, then it is considered as small; if the size of this element lies between lower and upper thresholds than it is considered as middle; everything to the right of the upper threshold is large (Fig. 6).

The sizes of candle's body, lower shadow and upper shadow :

Body

Abs(OPEN-CLOSE)

lshd

If(CLOSE>=OPEN,OPEN-LOW,CLOSE-LOW)

ushd

If(CLOSE>=OPEN,HIGH-CLOSE,HIGH-OPEN) For each component of the candle the two thresholds (bottom threshold and top threshold) are calculated through the Bollinger Bands.

ThBot_b

BBandBot( Fml( "body" ) ,55,E,0.5)

ThTop_b B

BandTop( Fml( "body" ) ,55,E,0.5)

ThBot_l

BBandBot( Fml( "lshd" ) ,55,E,0.5)

ThTop_l

BBandTop( Fml( "lshd" ) ,55,E,0.5)

ThBot_u

BBandBot( Fml( "ushd" ) ,55,E,0.5)

ThTop_u

BBandTop( Fml( "ushd" ) ,55,E,0.5)

Calculation of the candle code is divided into three steps for convenience:

CandleCode-b

If(CLOSE=OPEN,1,0)* If(Fml("ushd")>=Fml("lshd"),64,48) + If(CLOSE=OPEN,0,1) * ( If(CLOSE>OPEN,1,0) * (If(Fml("body")<= Fml("ThBot_b" ) ,80,0) +If(Fml("body")> Fml("ThBot_b" ) AND Fml("body") <= Fml("ThTop_b" ) ,96,0)+If(Fml("body")> Fml("ThTop_b" ),112,0)) + If(CLOSE= Fml("ThBot_b" ) ,32,0)+If(Fml("body")> Fml("ThBot_b" ) AND Fml("body") <= Fml("ThTop_b" ),16,0) ) )

CandleCode-l

If(Fml("lshd") = 0,3,0)+If(Fml("lshd") < Fml("ThBot_l" ) AND Fml("lshd")>0,2,0)+ If(Fml("lshd")> Fml("ThBot_l" ) AND Fml("lshd")<= Fml("ThTop_l" ) AND Fml("lshd")>0,1,0)

CandleCode-u

If(Fml("ushd")>0 AND Fml("ushd")<= Fml("ThBot_u" ) ,4,0)+If( Fml("ushd")> Fml("ThBot_u" ) AND Fml( "ushd")<= Fml("ThTop_u" ) ,8,0)+If(Fml( "ushd" )> Fml("ThTop_u" ),12,0) The resulting candle code is the sum of the three above:

CandlCode

Fml( "CandleCode-b" ) + Fml( "CandleCode-l" ) + Fml( "CandleCode-u" ) The smoothed indicator:

ICS

Periods:=Input("Enter Periods",2,13,2); Mov( Mov( Mov( Fml( "CandlCode" ) , Periods, S), Periods, S), Periods, S)

CandleWeight

If(CLOSE=OPEN,1,0)* If(Fml("ushd")>=Fml("lshd"),64,-64) +
If(CLOSE=OPEN,0,1) * If(CLOSE>OPEN,1,-1) *
(If(Fml("body")<= Fml("ThBot_b" ) ,80,0) +
If(Fml("body")> Fml("ThBot_b" ) AND Fml("body") <=
Fml("ThTop_b" ) ,96,0)+If(Fml("body")> Fml("ThTop_b" ),112,0)) +
+ If(CLOSE>=OPEN,-4,4)*( If(Fml("lshd") = 0,3,0)+
If(Fml("lshd") < Fml("ThBot_l" ) AND Fml("lshd")>0,2,0)+
If(Fml("lshd")> Fml("ThBot_l" ) AND Fml("lshd")<=
Fml("ThTop_l" ) AND Fml("lshd")>0,1,0) )+
If(CLOSE>=OPEN,1,-1)*( If(Fml("ushd")>0 AND
Fml("ushd")<= Fml("ThBot_u" ) ,4,0)+
If( Fml("ushd")> Fml("ThBot_u" ) AND
Fml( "ushd")<= Fml("ThTop_u" ) ,8,0)+
If(Fml( "ushd" )> Fml("ThTop_u" ),12,0) )

00 zero size body (doji)
01 small body for white candlestick
10 middle size body
11 large size body
11 zero size body (doji)
10 small body for black candlestick
01 middle size body
00 large size body
Here is the text for CandleCode constructions in terms of the MetaStok Indicator Builder.