With some minor modifications for match the global definition.
About the "Period" parameter in this system: It is used to determine the Downtrend/Uptrend using a Moving Average (learn more here). If you want to skip the trend checking condition, please set the Period to 1. More information about the trend condition of each Pattern, please see Pattern definition here.
Plotting of candlestick charts and analysis of candlestick patterns is an amazing line of technical analysis. The advantage of candlesticks is that they represent data in a way that it is possible to see the momentum within the data.
Candlesticks give a vivid mental picture of trading. After reading and a little practice, candlesticks will be part of your analytical arsenal. Japanese candlestick charts can help you penetrate "inside" of financial markets, which is very difficult to do with other graphical methods. They are equally suitable for all markets.
One of the first analysts who started to predict the movement of prices in the future, based on past prices, was the legendary Japanese Munehisa Homma. Trading principles applied by Homma in trading on the rice market, initiated the technique of Japanese candlesticks, which is now widely used in Japan and abroad.
Figure 1. Structure of a candlestick
Consider the structure of a candlestick (Fig. 1). The rectangle representing the difference between the open and close prices, is called the body of the candlestick. The height of the body represents the range between the open and close prices of the trading period. When the close price is higher than the open price, the candlestick body is white (Fig. 1 a). If the body is black (Fig. 1 b), this means the close price was below the open price.
Candlesticks can have shadows - the upper and lower, the length of shadows depends on the distance between the open/close prices and the minimum/maximum prices.
Candlestick are plotted on the chart one by one, forming various patterns. According to the theory, some patterns can indicate with a certain probability that the trend is changing, or confirm the trend, or show that the market is indecisive.
Long bodies of candlesticks, as a rule, tell about pressure from buyers or sellers (depending on the color of the candlestick). Short bodies mean that the struggle between the bulls and bears was weak.
Candlesticks
Description
"Long Candlesticks". Link to long candlesticks is widespread in the literature on Japanese candlesticks.
The term "long" refers to a candlestick body length, the difference between the open price and the close price.
It is better to consider the most recent price movements to determine what is long, and what is not.
Five or ten previous days - that's quite an adequate period to arrive at a correct conclusion.
"Short Candlesticks". The determination of short candlesticks can be based on the same methodology as in the case of long candlesticks, with similar results.
In addition, there are a lot of candlesticks, which do not fall into any of these two categories.
"Marubozu" . In Japanese "Marubozu" means almost bold.
In any case, the meaning of the term reflects the fact that the body of the candlestick either does not have up and/or down shadows at all, or they are very small.
Black marubozu - a long black body without a shadow on one of the sides. It often becomes a part of the bearish continuation pattern or bull reversal pattern, especially it appears in a downtrend. A long black candlestick indicates a major victory of bears, so it often appears the first day of many reversal patterns of the bullish character.
White marubozu - a long white body without a shadow on one of the sides. This is a very strong candle. In contrast to the black marubozu it often turns out to be part of the bullish pattern of continuation or a bearish reversal pattern.
"Doji". If the body of the candlestick is so small that the open and close prices are the same, it is called Doji.
The requirement that the open and close prices should be exactly equal, imposes ti strict restrictions on the data, and Doji would appear very rarely.
If the price difference between the open and close prices does not exceed a few ticks (minimum price change), this is more than enough.
"Spinning Tops" are short candlesticks with an upper and/or lower shadow longer than the body.
Sometimes they are referred to as "white" and "black" Doji. Koma indicates indecision of bulls and bears.
The color of the Koma body, as well as the length of its shadow, is not important. The small body relative to the shadows is what makes the spinning top.
"Hanging man" and "Hammer". These are candlesticks with long lower shadows and short bodies. The bodies are at the top of the range of prices.
The surprising property of these candlesticks is that they can be bullish and bearish, depending on the phase of the trends, in which they appear.
The appearance of these candles in a downward trend is a signal that its dominance in the market is coming to an end, in this case the candlestick is called "the hammer".
If the candlestick appears during an uptrend, it indicates its possible end, and the candlestick has an ominous name - "hanging man".
"A start" appears each time when the small body appears whenever a small body opens up or down from the previous long body, body color is unimportant.
Ideally, the gap must catch also shadows, but it is not entirely necessary. The star indicates some uncertainty prevailing in the market.
Stars are included in many candlestick patterns, mostly reversal.
Table 1. Types of Candlesticks
Separate candlesticks are extremely important for the analysis of combinations of candlesticks. When an analyst uses them separately, and then in combination with other candlesticks, the psychological state of the market is revealed.
2.1. Necessary structures
Candlestick patterns can be a separate candlestick or consist of a few of them. For the candlestick patterns, there are certain rules of recognition.
Example:Evening star (bearish pattern). The trend upwards. The first and third candlesticks are "long". Shadows of the stars are short, the color does not matter. The classical pattern: separation of the star from the Close of the first candlestick, for forex and within the day: Close of the first candlestick and Open of the star are equal. The third candlestick is closed inside the body of the first one.
So first let's learn to recognize the types of candlesticks. For this purpose, we write a function RecognizeCandle, which will recognize the type of candlesticks and return the necessary information.
//+------------------------------------------------------------------+
//| Function of candlestick type recognition |
//+------------------------------------------------------------------+
bool RecognizeCandle(string symbol,ENUM_TIMEFRAMES period, datetime time,int aver_period,CANDLE_STRUCTURE &res)
where:
symbol - the name of the symbol
period β chart period,
time β open time of the candlestick,
aver_period - period of averaging
res - a structure, in which the result is returned.
Let's define what results we need, based on the rules of recognition of candlestick patterns:
open, close, high and low;
open time of the candlestick;
trend direction;
bullish or bearish candlestick;
size of the candlestick body β an absolute value;
//+------------------------------------------------------------------+
//| Function of recognition of candlestick type |
//+------------------------------------------------------------------+
bool RecognizeCandle(string symbol,ENUM_TIMEFRAMES period, datetime time,int aver_period,CANDLE_STRUCTURE &res)
{
MqlRates rt[];
//--- Get data of previous candlesticks
if(CopyRates(symbol,period,time,aver_period+1,rt)<aver_period)
{
return(false);
}
First, using the CopyRates function obtain data from previous aver_period +1 candlesticks. Note the order, in which data is stored in the array we obtain.
If data were received without errors, start filling out our return structure CANDLE_STRUCTURE with data.
Defining trend. What is a trend? If this question had a fairly complete answer, the secrets of the market would have been disclosed. In this article we will use the method for determining the trend using a moving average.
MA=(C1+C2+β¦+Cn)/N,
where C β close prices, N β number of bars.
//--- Define the trend direction
double aver=0;
for(int i=0;i<aver_period;i++)
{
aver+=rt[i].close;
}
aver=aver/aver_period;
if(aver<res.close) res.trend=UPPER;
if(aver>res.close) res.trend=DOWN;
if(aver==res.close) res.trend=LATERAL;
Next we define if our candle is bullish or bearish, we calculate the absolute value of the candlestick body, the size of shadows, the average body size of the candlestick during aver_period and other necessary intermediate data.
//--- Define of it bullish or bearish
res.bull=res.open<res.close;
//--- Get the absolute value of the candlestick body size
res.bodysize=MathAbs(res.open-res.close);
//--- Get the size of shadows
double shade_low=res.close-res.low;
double shade_high=res.high-res.open;
if(res.bull)
{
shade_low=res.open-res.low;
shade_high=res.high-res.close;
}
double HL=res.high-res.low;
//--- Calculate the average body size of previous candlesticks
double sum=0;
for(int i=1; i<=aver_period; i++)
sum=sum+MathAbs(rt[i].open-rt[i].close);
sum=sum/aver_period;
Now let's deal with the identification of the types of candlesticks.
2.3. Rules of identification of candlestick types
"Long" candlesticks. To define "long" candlesticks, check the value of the current candlestick relative to the average value of aver_period previous candles.
Note: incase aver_period=1 (skip trend checking mode) we will use the simple Long/Short candle definition:
- long: body >= 0.65 * (High - Low)
- short: body <= 0.35 * (High - Low)
(Body) > (average body of the last aver_period) *1.3
//--- long
if(res.bodysize>sum*1.3) res.type=CAND_LONG;
//--- simple long
if(aver_period==1 && res.bodysize>=HL*0.65) res.type=CAND_LONG;
"Short" candlesticks. To define "short" candlesticks, use the same principle as for the "long" ones, but with a changed condition.
(Body) > (average body of the last X days) *0.5
//--- short
if(res.bodysize<sum*0.5) res.type=CAND_SHORT;
//--- simple short
if(aver_period==1 && res.bodysize<=HL*0.35) res.type=CAND_SHORT;
Doji. Doji occurs when open and close prices are equal. This is a very strict rule. In the case of most types of data, we can tolerate some deviations in finding patterns. The formula allows finding the percentage difference between the two prices within acceptable limits.
(Dodji body) < (range from the highest to the lowest prices) * 0.03
When writing an indicator for this article, it was necessary to separate the "long" "Maribozu", for which I had to add the condition for checking "long" candlesticks.
"Hammer" and "Hanging Man". The body is located in the upper part of the daily range and the lower shadow is much longer than the body. It is also necessary to consider the length of the upper shadow, if there is any. The ratio between the body and the lower shadow is defined as the ratio of the body length to the length of the lower shadow:
(lower shadow)>(body)*2 and (upper shadow)< (body)*0.1
"Spinning Tops". These are "short" candlesticks" with shadows longer than the body:
Short candle and (lower shadow) > (body) and (upper shadow) > (body)
//--- spinning top
if(res.type==CAND_SHORT && shade_low>res.bodysize && shade_high>res.bodysize) res.type=CAND_SPIN_TOP;
The source text of the function and structure descriptions are in the attached file CandlestickType.mqh.
A;so to the article, the Candlestick Type Color.mq5 indicator is attached, which paints candlesticks on the chart depending on their type.
Figure 2. Example of Candlestick Type Color.mq5
So we have created a function that returns all the necessary data.
Now we cane proceed creating an indicator that will recognize candlestick patterns.
3. Candlestick Patterns and Algorithms for Their Identification
A candlestick pattern can be either a single candlestick, or consist of several candlesticks, seldom more than five or six. In Japanese literature, they sometimes refer to the patterns consisting of a larger number of candlesticks. The order in which we will consider the patterns, does not reflect their importance or predictive capabilities.
Candlestick patterns are divided into two types - reversal patterns and continuation patterns.
We will consider simple patterns (one candlestick) first, and then complex (several candlesticks). The figure containing the pattern will start with two small vertical lines. These lines simply indicate the direction of the previous trend of the market, and should not be used as a direct indication of the relations between patterns.
The patterns will be presented in a table, in the first line - bull pattern, in the second - the opposite bearish pattern, if there is such.
3.1. REVERSAL PATTERNS OF CANDLESTICKS
3.1.1. Patterns consisting of a single candlestick
Obtain data for a single candlestick:
//--- calculation of candlestick patterns
for(int i=limit;i<rates_total-1;i++)
{
CANDLE_STRUCTURE cand1;
if(!RecognizeCandle(_Symbol,_Period,time[i],InpPeriodSMA,cand1))
continue;
/* Checking patterns with one candlestick */
and recognize patterns.
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Invertedhammer(bullish)
Buy
Downward trend.
The upper shadow is not less than 2 and no more than 3 times larger than the body.
There is no lower shadow, or it is very short (no more than 10% of the candlestick range).
The color of the body in the long game is not important, with the short - white hammer is much stronger than the black one.
Confirmation is suggested.
Hanging Man(bearish)
Sell
Uptrend.
The lower shadow is not less than 2 and no more than 3 times larger than the body.
There is no upper shadow, or it is very short (no more than 10% of the candlestick range).
The color of the body in the long game is not important, with the short - the black hanging man is much stronger than the white one.
Confirmation is suggested.
//------
// Inverted Hammer the bull model
if(cand1.trend==DOWN && // check the trend direction
cand1.type==CAND_INVERT_HAMMER) // check the "inverted hammer"
{
comment=_language?"Inverted hammer";
DrawSignal(prefix+"Inverted Hammer the bull model"+string(objcount++),cand1,InpColorBull,comment);
}
// Handing Man the bear model
if(cand1.trend==UPPER && // check the trend direction
cand1.type==CAND_HAMMER) // check "hammer"
{
comment=_language?"Hanging Man";
DrawSignal(prefix+"Hanging Man the bear model"+string(objcount++),cand1,InpColorBear,comment);
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Hammer(bullish)
Buy
Downward trend.
The lower shadow is not less than 2 and no more than 3 times larger than the body.
There is no upper shadow, or it is very short (no more than 10% of the candlestick range).
The color of the body in the long game is not important, with the short - white hammer is much stronger than the black one.
Confirmation is suggested.
Shooting Star(bearish)
Sell
Uptrend.
The upper shadow is not less than 3 times is larger than the body.
There is no lower shadow, or it is very short (no more than 10% of the candlestick range).
The price gap between the star and the previous candlestick.
Forex: the Close price of the previous candlestick and Open of the Star are equal.
The body color does not matter.
Confirmation is suggested.
//------
// Hammer the bull model
if(cand1.trend==DOWN && //check the trend direction
cand1.type==CAND_HAMMER) // check the hammer
{
comment=_language?"Hammer";
DrawSignal(prefix+"Hammer the bull model"+string(objcount++),cand1,InpColorBull,comment);
}
//------
// Shooting Star the bear model
if(cand1.trend==UPPER && cand2.trend==UPPER && //check the trend direction
cand2.type==CAND_INVERT_HAMMER) // check the inverted hammer
{
comment=_language?"Shooting Star";
if(_forex)// if forex
{
if(cand1.close<=cand2.open) // close 1 less equal open 1
{
DrawSignal(prefix+"Shooting Star the bear model"+string(objcount++),cand2,InpColorBear,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.close<cand2.close) // 2 candlestick detached from 1
{
DrawSignal(prefix+"Shooting Star the bear model"+string(objcount++),cand2,InpColorBear,comment);
}
}
}
I would like to draw your attention to the fact that in the case of "Shooting Star" we actually need two candlesticks, because under the terms of recognizing the body of the previous day is taken into account.
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Belt Hold(bullish)
Buy
The pattern
is not
implemented
Downward trend.
Opening of a candlestick with a large gap in the direction of the trend.
White candlestick β Β«marubozuΒ» Β«longΒ».
The body of the white candlestick is much larger than the body of the previous candlestick.
Confirmation is suggested.
Belt Hold(bearish)
Sell
The pattern
is not
implemented
Uptrend.
Opening of a candlestick with a large gap in the direction of the trend.
Black candlestick β Β«marubozuΒ» Β«longΒ».
The body of the black candlestick is much larger than the body of the previous candlestick.
Confirmation is suggested.
//------
// Belt Hold the bull model
if(cand2.trend==DOWN && cand2.bull && !cand1.bull &&// check the trend direction and direction of the candlestick
cand2.type==CAND_MARIBOZU_LONG && // check the "long" marubozu
cand1.bodysize<cand2.bodysize && cand2.close<=cand1.close) // the body of the first candlestick is smaller than the body of the second one, close of the second one is below the close of the first
{
comment=_language?"Belt Hold";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Belt Hold the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
// Belt Hold the bear model
if(cand2.trend==UPPER && !cand2.bull && cand1.bull && // check the trend direction and direction of the candlestick
cand2.type==CAND_MARIBOZU_LONG && // check the "long" marubozu
cand1.bodysize<cand2.bodysize && cand2.close>=cand1.close) // the body of the first candlestick is smaller than the body of the second one, close of the second one is above the close of the first
{
comment=_language?"Belt Hold";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Belt Hold the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
Like in the case with the "Shooting Star", two candlesticks are used, because the body of the previous day is taken into account for pattern recognition.
3.1.2. Patterns consisting of two candlesticks
Add another candle:
/* Checking patterns with two candlesticks */
CANDLE_STRUCTURE cand2;
cand2=cand1;
if(!RecognizeCandle(_Symbol,_Period,time[i-1],InpPeriodSMA,cand1))
continue;
and recognize patterns:
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Engulfing(bullish)
Buy
Downward trend.
The body of the second candlestick completely covers the body of the first one.
Forex: Close of the black candlestick and Open of the white one match.
Shadows do not matter.
Confirmation is suggested.
Engulfing(bearish)
Sell
Uptrend.
The body of the second candlestick completely covers the body of the first one.
Forex: Close of the white candlestick and Open of the black one match.
Shadows do not matter.
Confirmation is suggested.
//------
// Engulfing the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && // check the trend direction and direction of the candlestick
cand1.bodysize<cand2.bodysize) // the body of the second candlestick is larger than that of the first
{
comment=_language?"Engulfing";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand1.open<cand2.close) // the body of the first candlestick is inside the body of the second
{
DrawSignal(prefix+"Engulfing the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
else
{
if(cand1.close>cand2.open && cand1.open<cand2.close) // the body of the first candlestick is inside the body of the second
{
DrawSignal(prefix+"Engulfing the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
}
// Engulfing the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && // check the trend direction and direction of the candlestick
cand1.bodysize<cand2.bodysize) // the body of the second candlestick is larger than that of the first
{
comment=_language?"Engulfing";
if(_forex)// if forex
{
if(cand1.close<=cand2.open && cand1.open>cand2.close) //the body of the first candlestick is inside the body of the second
{
DrawSignal(prefix+"Engulfing the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.open>cand2.close) // close 1 less equal to open 2 or open 1 larger equal to close 2
{
DrawSignal(prefix+"Engulfing the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Harami Cross (Bull)
Buy
Downward trend.
The first candlestick of the pattern is long black.
Doji is within the range of the first candlestick, including the shades.
Forex: doji is on the level of Close of the first candlestick. If Doji shadows are short, the pattern should be considered a Doji Star for forex.
Confirmation is suggested.
Harami Cross(bearish)
Sell
Uptrend.
The first candlestick of the pattern is long white.
Doji is within the range of the first candlestick, including the shades.
Forex: doji is on the level of Close of the first candlestick. If Doji shadows are short, the pattern should be considered a Doji Star for forex.
Confirmation is suggested.
//------
// Harami Cross the bull model
if(cand1.trend==DOWN && !cand1.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // checking the "long" first candlestick and doji
{
comment=_language?""Harami Cross";
if(_forex)// if forex
{
if(cand1.close<=cand2.open && cand1.close<=cand2.close && cand1.open>cand2.close) // doji inside the body of the first candlestick
{
DrawSignal(prefix+"Harami Cross the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.close<cand2.close && cand1.open>cand2.close) // doji inside the body of the first candlestick
{
DrawSignal(prefix+"Harami Cross the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
}
// Harami Cross the bear model
if(cand1.trend==UPPER && cand1.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // checking the "long" candlestick and doji
{
comment=_language?"Harami Cross";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand1.close>=cand2.close && cand1.close>=cand2.close) // doji inside the body of the first candlestick
{
DrawSignal(prefix+"Harami Cross the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
else
{
if(cand1.close>cand2.open && cand1.close>cand2.close && cand1.open<cand2.close) // doji inside the body of the first candlestick
{
DrawSignal(prefix+"Harami Cross the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Harami(bullish)
Buy
Downward trend.
The body of the first "long" candlestick" completely engulfs the body of the second one.
Shadows do not matter.
Forex: Close of the black candlestick and Open of white match.
Confirmation is suggested.
Harami(bearish)
Sell
Uptrend.
The body of the first "long" candlestick" completely engulfs the body of the second one.
Shadows do not matter.
Forex: Close of the white candlestick and Open of black match.
Confirmation is suggested.
//------
// Harami the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.bull &&// check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && // checking the "long"first candlestick
cand2.type!=CAND_DOJI && cand1.bodysize>cand2.bodysize) // the second candlestick is not doji and the body of the first is larger than the body of the second
{
comment=_language?"Harami";
if(_forex)// if forex
{
if(cand1.close<=cand2.open && cand1.close<=cand2.close && cand1.open>cand2.close) // body of the second candlestick is inside the body of the first
{
DrawSignal(prefix+"Harami the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.close<cand2.close && cand1.open>cand2.close) // body of the second candlestick is inside the body of the first
{
DrawSignal(prefix+"Harami the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
}
// Harami the bear model
if(cand1.trend==UPPER && cand1.bull && !cand2.bull &&// check the trend direction and direction of candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && // checking the "long" first candlestick
cand2.type!=CAND_DOJI && cand1.bodysize>cand2.bodysize) // the second candlestick is not doji and body of the first candlestick is larger than that of the second
{
comment=_language?"Harami";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand1.close>=cand2.close && cand1.close>=cand2.close) // doji is inside the body of the first candlestick
{
DrawSignal(prefix+"Harami the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
else
{
if(cand1.close>cand2.open && cand1.close>cand2.close && cand1.open<cand2.close) //doji is inside the body of the first candlestick
{
DrawSignal(prefix+"Harami the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Doji Star(bullish)
Buy
Downward trend.
The first candlestick of the pattern is long black.
The second session - doji with a break in the trend direction.
Forex: no break.
Shadows of doji are short.
Confirmation is suggested.
Doji Star(bearish)
Sell
Uptrend.
The first candlestick of the pattern is long white.
The second session - doji with a break in the trend direction.
Forex: no break.
Shadows of doji are short.
Confirmation is suggested.
//------
// Doji Star the bull model
if(cand1.trend==DOWN && !cand1.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // checking 1 "long" candlestick and 2 doji
{
comment=_language?"Doji Star";
if(_forex)// if forex
{
if(cand1.close>=cand2.open) // open of doji is below or equal to close of the first candlestick
{
DrawSignal(prefix+"Doji Star the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
else
{
if(cand1.close>cand2.open && cand1.close>cand2.close) // the body of doji is alienated from the body of the first candlestick
{
DrawSignal(prefix+"Doji Star the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
}
// Doji Star the bear model
if(cand1.trend==UPPER && cand1.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && cand2.type==CAND_DOJI) // checking 1 "long" candlestick and 2 doji
{
comment=_language?"Doji Star";
if(_forex)// if forex
{
if(cand1.close<=cand2.open) // // open of doji is above or equal to close of the first candlestick
{
DrawSignal(prefix+"Doji Star the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.close<cand2.close) // // the body of doji is alienated from the body of the first candlestick
{
DrawSignal(prefix+"Doji Star the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Piercing Pattern(bullish)
Buy
Downward trend.
Both candlesticks are long.
Open of the white candlestick is below Low of the black.
Forex: Close of the black candlestick and Open of white are equal.
The white candlestick is closed inside the black one and covers more than 50% of the body. (For stock markets: unlike Dark-cloud cover, this requirement has no exceptions.)
Confirmation is not required for the classical model, is required for Forex.
Dark Cloud Cover (Bear)
Sell
Uptrend.
Both candlesticks are long.
Open of the black candlestick is above High of the white candlestick.
Forex: Close of the white candlestick and Open of black are equal.
The black candle closes inside white and covers more than 50% of the body.
Confirmation is not required for the classical model, is required for Forex.
//------
// Piercing line the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.close>(cand1.close+cand1.open)/2)// close of the second is above the middle of the first
{
comment=_language?"Piercing Line";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand2.close<=cand1.open)
{
DrawSignal(prefix+"Gleam in clouds"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
else
{
if(cand2.open<cand1.low && cand2.close<=cand1.open) // open of the second candlestick is below LOW of the first,
{
DrawSignal(prefix+"Piercing Line"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
}
// Dark Cloud Cover the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.close<(cand1.close+cand1.open)/2)// close 2 is below the middle of the body of 1
{
comment=_language?"Dark Cloud Cover";
if(_forex)// if forex
{
if(cand1.close<=cand2.open && cand2.close>=cand1.open)
{
DrawSignal(prefix+"Dark Cloud Cover"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
else
{
if(cand1.high<cand2.open && cand2.close>=cand1.open)
{
DrawSignal(prefix+"Dark Cloud Cover"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Meeting Lines(bullish)
Buy
The pattern
is not
implemented
Downward trend.
The first candlestick of the pattern is long black.
Open of the white candlestick is with a large gap and is below the Low of the black candlestick.
Close prices of both candlesticks are the same.
Confirmation is suggested.
Meeting Lines(bearish)
Sell
The pattern
is not
implemented
Uptrend.
The first candlestick of the pattern is long white.
Open of the black candlestick is with a large gap and is above the High of the white candlestick.
Close prices of both candlesticks are the same.
Confirmation is suggested.
// Meeting Lines the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && // check the trend direction and the candlestick direction
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand1.close==cand2.close && cand1.low>cand2.open) // close prices are equal, size of the first one is less than of the second one, open of the second is below Low of the first
{
comment=_language?"Meeting Lines";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Meeting Lines the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
// Meeting Lines the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && // check the trend direction and the candlestick direction
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand1.close==cand2.close && cand1.high<cand2.open) // // close prices are equal, size of first is less than of second, open of the second is above High of the first
{
comment=_language?"Meeting Lines";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Meeting Lines the bear model"+string(objcount++),cand1,cand2,InpColorBear,comment);
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Matching Low(bullish)
The pattern
is not
implemented
Downward trend.
The first candlestick of the pattern is long black and the second is black.
Open of the second candlestick is inside the body of the first one.
Close prices of both prices are the same.
there are no lower shadows or they are very short.
Confirmation is suggested.
//------
// Matching Low the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && !cand2.bull && // check the trend direction and the candlestick direction
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) &&
cand1.close==cand2.close && cand1.bodysize>cand2.bodysize) // close prices are equal, size of the first one is larger than of the second
{
comment=_language?"Matching Low";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Matching Low the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Homing Pigeon<br1(bullish)
Bullish Homing Pigeon
The pattern
is not
implemented
Downward trend.
The first candlestick of the pattern is long black and the second is black.
The body of second candlestick is inside the body of the first one.
there are no lower shadows or they are very short.
Confirmation is suggested.
//------
// Homing Pigeon the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && !cand2.bull && // check the trend direction and the candlestick direction
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand1.close<cand2.close && cand1.open>cand2.open) // body of the second is inside that of the first candlestick
{
comment=_language?"Homing Pigeon";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Homing Pigeon the bull model"+string(objcount++),cand1,cand2,InpColorBull,comment);
}
}
3.1.3. Patterns consisting of three candlesticks
/* Checking patterns with three candlesticks */
CANDLE_STRUCTURE cand3;
cand3=cand2;
cand2=cand1;
if(!RecognizeCandle(_Symbol,_Period,time[i-2],InpPeriodSMA,cand1))
continue;
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Abandoned Baby(bullish)
The pattern
is not
implemented
This is a rare but important reversal pattern.
Downward trend.
The first candlestick of the pattern is long black.
The second candlestick is doji with a gap, and the gap is not only between the candlestick bodies, but also between shadows.
The third candlestick is "long" white candlestick with the same gap between the shadows and Close inside the body of the first candlestick.
Abandoned Baby(bearish)
The pattern
is not
implemented
This is a rare but important reversal pattern.
Uptrend.
The first candlestick of the pattern is long white.
The second candlestick is doji with a gap, and the gap is not only between the candlestick bodies, but also between shadows.
The third candlestick is "long" black candlestick with the same gap between the shadows and Close inside the body of the first candlestick.
//------
// The Abandoned Baby, the bullish model
if(cand1.trend==DOWN && !cand1.bull && cand3.trend==DOWN && cand3.bull && // check direction of trend and direction of candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // check of "long" candlestick
cand2.type==CAND_DOJI && // check if the second candlestick is Doji
cand3.close<cand1.open && cand3.close>cand1.close) // the third one is closed inside of body of the first one
{
comment=_language?"Abandoned Baby (Bull)":"Abandoned Baby";
if(!_forex)// if it's not forex
{
if(cand1.low>cand2.high && cand3.low>cand2.high) // gap between candlesticks
{
DrawSignal(prefix+"Abandoned Baby the bull model"+string(objcount++),cand1,cand1,cand3,InpColorBull,comment);
}
}
}
// The Abandoned Baby, the bearish model
if(cand1.trend==UPPER && cand1.bull && cand3.trend==UPPER && !cand3.bull && // check direction of trend and direction of candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // check of "long" candlestick
cand2.type==CAND_DOJI && // check if the second candlestick is Doji
cand3.close>cand1.open && cand3.close<cand1.close) // // the third one is closed inside of body of the second one
{
comment=_language?"Abandoned Baby (Bear)":"Abandoned Baby";
if(!_forex)// if it's not forex
{
if(cand1.high<cand2.low && cand3.high<cand2.low) // gap between candlesticks
{
DrawSignal(prefix+"Abandoned Baby the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Morning Star(bullish)
Buy
Downward trend.
The first and the third sessions are "long" candlesticks.
Shadows of the stars are short, the color does not matter.
Separation of the star from the Close of the first candlestick.
Forex: Close of the first candlestick and Open of the star are equal.
The third candlestick is closed inside the body of the first one.
Evening Star(bearish)
Uptrend.
The first and the third sessions are "long" candlesticks.
Shadows of the stars are short, the color does not matter.
Separation of the star from the Close of the first candlestick.
Forex: Close of the first candlestick and Open of the star are equal.
The third candlestick is closed inside the body of the first one.
// Morning star the bull model
if(cand1.trend==DOWN && !cand1.bull && cand3.trend==DOWN && cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.type==CAND_SHORT && // checking "short"
cand3.close>cand1.close && cand3.close<cand1.open) // the third candlestick is closed inside the body of the first one
{
comment=_language?"Morning star";
if(_forex)// if forex
{
if(cand2.open<=cand1.close) // open of the second candlestick is below or equal to close of the first one
{
DrawSignal(prefix+"Morning star the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
else // another market
{
if(cand2.open<cand1.close && cand2.close<cand1.close) // separation of the second candlestick from the first one
{
DrawSignal(prefix+"Morning star the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Evening star the bear model
if(cand1.trend==UPPER && cand1.bull && cand3.trend==UPPER && !cand3.bull && //check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.type==CAND_SHORT && // checking "short"
cand3.close<cand1.close && cand3.close>cand1.open) // the third candlestick is closed inside the body of the first one
{
comment=_language?"Evening star";
if(_forex)// if forex
{
if(cand2.open>=cand1.close) // open of the second is above or equal to close of the first one
{
DrawSignal(prefix+"Evening star the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
else // another market
{
if(cand2.open>cand1.close && cand2.close>cand1.close) // separation of the second candlestick from the first one
{
DrawSignal(prefix+"Evening star the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Morning Doji Star(bullish)
Buy
Downward trend.
The first candlestick of the pattern is long black.
The second session - doji with a break in the trend direction.
Forex: no break.
Shadows of doji are short.
The third candlestick is closed inside the body of the first one.
Evening Doji Star(bearish)
Uptrend.
The first candlestick of the pattern is long white.
The second session - doji with a break in the trend direction.
Forex: no break.
Shadows of doji are short.
Confirmation is suggested.
//------
// Morning Doji Star the bull model
if(cand1.trend==DOWN && !cand1.bull && cand3.trend==DOWN && cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.type==CAND_DOJI && // checking "doji"
cand3.close>cand1.close && cand3.close<cand1.open) // third cand. is closed inside body of first
{
comment=_language?"Morning Doji Star";
if(_forex)// if forex
{
if(cand2.open<=cand1.close) // open of doji is below or equal to close of the first
{
DrawSignal(prefix+"Morning Doji Star the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
else // another market
{
if(cand2.open<cand1.close) // separation of doji from the first
{
DrawSignal(prefix+"Morning Doji Star the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Evening Doji Star the bear model
if(cand1.trend==UPPER && cand1.bull && cand3.trend==UPPER && !cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand2.type==CAND_DOJI && // checking "doji"
cand3.close<cand1.close && cand3.close>cand1.open) // third cand. is closed inside body of first
{
comment=_language?"Evening Doji Star";
if(_forex)// if forex
{
if(cand2.open>=cand1.close) // open of doji is above or equal to close of the first
{
DrawSignal(prefix+"Evening Doji Star the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
else // another market
{
if(cand2.open>cand1.close) // separation of doji from the first
// check close 2 and open 3
{
DrawSignal(prefix+"Evening Doji Star the bear model"+string(objcount++),cand1,cand3,cand3,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Bearish Upside Gap Two Crows
Sell
The pattern
is not
implemented
Uptrend.
The first candlestick is "long" white.
A gap between white and black candlesticks.
The third candlestick opens higher than the second and engulfs it.
Confirmation is suggested.
The meaning of the pattern: if prices could not go up during the 4th session, we should expect prices to fall.
Two Crows(bearish)
Sell
The pattern
is not
implemented
Uptrend.
The first candlestick of the pattern is long white.
The gap between white and the first black candlestick.
The third candlestick is black and necessarily "long"; opens inside or above the second and closes within or below the white candlestick, covering the gap.
Confirmation is suggested.
If the second crow (the third candle) engulfs a white candle, the confirmation is not required.
//------
// Upside Gap Two Crows the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && cand3.trend==UPPER && !cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand1.close<cand2.close && cand1.close<cand3.close && // separation of the second and third from the first one
cand2.open<cand3.open && cand2.close>cand3.close) // the third candlestick engulfs second
{
comment=_language?"Upside Gap Two Crows";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Upside Gap Two Crows the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
//------
// Two Crows the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !cand2.bull && cand3.trend==UPPER && !cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG|| cand1.type==CAND_MARIBOZU_LONG) &&(cand3.type==CAND_LONG|| cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
cand1.close<cand2.close && // separation of the second from the first one
cand3.open>cand2.close && // third one opens higher than close of the second
cand3.close<cand1.close) // third one closes than close of the first
{
comment=_language?"Two Crows";
if(!_forex)// if not forex
{
DrawSignal(prefix+"Two Crows the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Three Star in the South(bullish)
Buy
Downward trend.
The first candlestick is a long black day with a long lower shadow.
The second candlestick is shorter than the first, its Low is above the Low of the first candlestick.
The third candlestick is a small black marubozu or a star, an internal day in relation to the second session.
Confirmation is suggested.
Deliberation(bearish)
Uptrend.
Three white candlesticks with higher close prices. The first two candlesticks are long days.
Open price of each candlestick is inside the body of the preceding one.
Forex: open/close prices of white candlesticks are the same.
The third candlestick opens at about the close level of the second candlestick.
the third candlestick is a star or a spinning top.
Confirmation is suggested.
//------
// Three Star in the South the bull model
if(cand1.trend==DOWN && !cand1.bull && !cand2.bull && !cand3.bull && //check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand3.type==CAND_MARIBOZU || cand3.type==CAND_SHORT) && // checking the "long" candlestick and marubozu
cand1.bodysize>cand2.bodysize && cand1.low<cand2.low && cand3.low>cand2.low && cand3.high<cand2.high)
{
comment=_language?"Three Star in the South";
if(_forex)// if forex
{
DrawSignal(prefix+"Three Star in the South the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
else // another market
{
if(cand1.close<cand2.open && cand2.close<cand3.open) // open is inside the previous candlestick
{
DrawSignal(prefix+"Three Star in the South the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Deliberation the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.bull && cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick
(cand3.type==CAND_SPIN_TOP || cand3.type==CAND_SHORT)) // the third candlestick is a star or spinning top
{
comment=_language?"Deliberation";
if(_forex)// if forex
{
DrawSignal(prefix+"Deliberation the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
else // another market
{
if(cand1.close>cand2.open && cand2.close<=cand3.open) // open is inside the previous candlestick
// check close 2 and open 3
{
DrawSignal(prefix+"Deliberation the bear model"+string(objcount++),cand1,cand3,cand3,InpColorBear,comment);
}
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Three White Soldiers(bullish)
Buy
Downward trend.
Three long white candlesticks appear one after another, close prices of each of them is higher than that of the previous.
Open price of each soldier is inside the body of the previous candlestick.
Forex: Close/Open of solders are the same.
Upper shadows of the soldiers are short.
Confirmation is not required.
Three Black Crows(bearish)
The pattern
is not
implemented
Uptrend.
Three long black candlesticks appear one after another, close prices of each of them is lower than that of the previous.
Open price of each crow is inside the body of the previous candlestick.
Forex: corresponds to pattern Identical three crows.
The lower shadows of the crows are short.
Confirmation is not required.
//------
// Three White Soldiers the bull model
if(cand1.trend==DOWN && cand1.bull && cand2.bull && cand3.bull && // check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick and marubozu
(cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG)) // checking the "long" candlestick and marubozu
{
comment=_language?"Three White Soldiers";
if(_forex)// if forex
{
DrawSignal(prefix+"Three White Soldiers the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
else // another market
{
if(cand1.close>cand2.open && cand2.close>cand3.open) // open inside the previous candlestick
{
DrawSignal(prefix+"Three White Soldiers the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Three Black Crows the bear model
if(cand1.trend==UPPER && !cand1.bull && !cand2.bull && !cand3.bull && //check the trend direction and direction of the candlestick
(cand1.type==CAND_LONG || cand1.type==CAND_MARIBOZU_LONG) && (cand2.type==CAND_LONG || cand2.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick and marubozu
(cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG) && // checking the "long" candlestick and marubozu
cand1.close<cand2.open && cand2.close<cand3.open)
{
comment=_language?"Three Black Crows";
if(!_forex) // non-forex
{
DrawSignal(prefix+"Three Black Crows the bear model"+string(objcount++),cand1,cand3,cand3,InpColorBear,comment);
}
}
Name of the Pattern
Order
Classical pattern
Forex
Pattern recognition
Three Outside Up(bullish)
Buy
Downward trend.
First the pattern of Engulfing (bull) is formed: the body of the second candlestick completely covers the body of the first one.
Forex: Close of a black candlestick and Open of the white one are equal.
Shadows do not matter.
Then, on the third day there is a higher close.
Confirmation is not required: the pattern itself is a confirmation to the bull Engulfing
Three Outside Down(bearish)
Uptrend.
First the pattern of Engulfing (bear) is formed: the body of the second candlestick completely covers the body of the first one.
Forex: Close of the white candlestick and Open of the first black one match.
Shadows do not matter.
Then, on the third day there is a lower close.
Confirmation is not required: the pattern itself is a confirmation to the bear Engulfing
//------
// Three Outside Up the bull model
if(cand1.trend==DOWN && !cand1.bull && cand2.trend==DOWN && cand2.bull && cand3.bull && // check the trend direction and direction of the candlestick
cand2.bodysize>cand1.bodysize && // the body of the second candlestick is larger than that of the first
cand3.close>cand2.close) // the third day is closed higher than the second
{
comment=_language?"Three Outside Up";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand1.open<cand2.close) // the body of the first candlestick is inside the body of the second