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.
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.
//------
// 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);
}
//------
// 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.
//------
// 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:
//------
// 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);
}
}
}
//------
// 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);
}
}
}
//------
// 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);
}
}
}
//------
// 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);
}
}
}
//------
// 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);
}
}
}
// 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);
}
}
//------
// 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);
}
}
//------
// 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;
//------
// 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);
}
}
}
// 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);
}
}
}
//------
// 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);
}
}
}
//------
// 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);
}
}
//------
// 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);
}
}
}
//------
// 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);
}
}
//------
// 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
{
DrawSignal(prefix+"Three Outside Up the bull model"+string(objcount++),cand1,cand2,cand3,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+"Three Outside Up the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Three Outside Down the bear model
if(cand1.trend==UPPER && cand1.bull && cand2.trend==UPPER && !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 lower than the second
{
comment=_language?"Three Outside Down";
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+"Three Outside Down the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,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+"Three Outside Down the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
}
//------
// Three Inside Up 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) && //checking the "long" candlestick
cand1.bodysize>cand2.bodysize && // the body of the first candlestick is larger than that of the second one
cand3.close>cand1.open) // the third day is closed higher than the both first one
{
comment=_language?"Three Inside Up";
if(_forex)// if forex
{
if(cand1.close<=cand2.open && cand1.close<=cand2.close && cand1.open>cand2.close) // the body of the second candlestick is inside the body of the first one
{
DrawSignal(prefix+"Three Inside Up the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
else
{
if(cand1.close<cand2.open && cand1.close<cand2.close && cand1.open>cand2.close) // the body of the second candlestick is inside the body of the first one
{
DrawSignal(prefix+"Three Inside Up the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Three Inside Down 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) && // checking the "long" candlestick
cand1.bodysize>cand2.bodysize && // the body of the first candlestick is larger than that of the second one
cand3.close<cand1.open) // the third day closes lower than the both first one
{
comment=_language?"Three Inside Down";
if(_forex)// if forex
{
if(cand1.close>=cand2.open && cand1.close>=cand2.close && cand1.open<=cand2.close) // inside the body of the first candlestick
{
DrawSignal(prefix+"Three Inside Down the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
else
{
if(cand1.close>cand2.open && cand1.close>cand2.close && cand1.open<cand2.close) // inside the body of the first candlestick
{
DrawSignal(prefix+"Three Inside Down the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
}
//------
// Three Stars the bull model
if(cand1.trend==DOWN && // check the trend direction
cand1.type==CAND_DOJI && cand2.type==CAND_DOJI && cand3.type==CAND_DOJI) // check doji
{
comment=_language?"Bullish Three Stars";
if(_forex)// if forex
{
DrawSignal(prefix+"Three Stars the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
else
{
if(cand2.open!=cand1.close && cand2.close!=cand3.open) // the second candlestick is on a different level
{
DrawSignal(prefix+"Three Stars the bull model"+string(objcount++),cand1,cand2,cand3,InpColorBull,comment);
}
}
}
// Three Stars the bear model
if(cand1.trend==UPPER && // check the trend direction
cand1.type==CAND_DOJI && cand2.type==CAND_DOJI && cand3.type==CAND_DOJI) // check doji
{
comment=_language?"Bearish Three Stars";
if(_forex)// if forex
{
DrawSignal(prefix+"Three Stars the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
else
{
if(cand2.open!=cand1.close && cand2.close!=cand3.open) // the second candlestick is on a different level
{
DrawSignal(prefix+"Three Stars the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
}
}
// Identical Three 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 or marubozu
(cand3.type==CAND_LONG || cand3.type==CAND_MARIBOZU_LONG)) // checking the "long" candlestick or marubozu
{
comment=_language?"Identical Three Crows";
if(_forex)// if forex
{
DrawSignal(prefix+"Identical Three Crows the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}
else // a different market
{
if(cand1.close>=cand2.open && cand2.close>=cand3.open) // open is less or equal to close of the preceding candlestick
{
DrawSignal(prefix+"Identical Three Crows the bear model"+string(objcount++),cand1,cand2,cand3,InpColorBear,comment);
}