Candlestick Patterns with their MQL4 Codes
There are many candlestick patterns, but here is a list of some of the most commonly recognized ones:
- Hammer
- Hanging man
- Doji
- Engulfing pattern
- Piercing pattern
- Dark cloud cover
- Harami
- Morning star
- Evening star
- Shooting star
- Inverted hammer
- Three white soldiers
- Three black crows
- Tweezer tops and bottoms
- Rising three method
- Falling three method
- Abandoned baby
- Belt hold
- Marubozu
- Gravestone doji
Please note that there are many variations and interpretations of these candlestick patterns, and traders often use them in combination with other technical indicators to make trading decisions.
Hammer
This pattern forms when the open, low, and close are near the high of the candle, and there is a long lower shadow. It suggests that bulls are gaining control of the market after a period of selling pressure.
MT4 Code
bool isHammer(double Open[], double Close[], double High[], double Low[]) {
double body = MathAbs(Open[0] - Close[0]);
double upperShadow = High[0] - MathMax(Open[0], Close[0]);
double lowerShadow = MathMin(Open[0], Close[0]) - Low[0];
if (body < upperShadow && body < lowerShadow) {
if (lowerShadow > body * 2) {
return true; // Bullish Hammer
}
}
return false;
}
// Buy scenario
if (isHammer(Open, Close, High, Low)) {
// Enter long position
// Set stop loss below the low of the Hammer candle
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
// No specific sell scenario for the Hammer pattern, as it is a bullish reversal pattern
Hanging man
This pattern is the opposite of the hammer, with a long lower shadow and a small body at the top of the candle. It can indicate that the market may be due for a correction after an uptrend.
MT4 Code
bool isHangingMan(double Open[], double Close[], double High[], double Low[]) {
double body = MathAbs(Open[0] - Close[0]);
double upperShadow = High[0] - MathMax(Open[0], Close[0]);
double lowerShadow = MathMin(Open[0], Close[0]) - Low[0];
if (body < upperShadow && body < lowerShadow) {
if (upperShadow > body * 2 && lowerShadow < body * 0.1) {
return true; // Bearish Hanging Man
}
}
return false;
}
// Buy scenario
// No specific buy scenario for the Hanging Man pattern, as it is a bearish reversal pattern
// Sell scenario
if (isHangingMan(Open, Close, High, Low)) {
// Enter short position
// Set stop loss above the high of the Hanging Man candle
// Set take profit at a predefined target or using a trailing stop
}
Doji
This pattern occurs when the open and close are at the same level, resulting in a small body and long upper and lower shadows. It suggests indecision in the market and can signal a potential reversal.
MT4 Code
bool isDoji(double Open[], double Close[], double High[], double Low[]) {
double body = MathAbs(Open[0] - Close[0]);
double upperShadow = High[0] - MathMax(Open[0], Close[0]);
double lowerShadow = MathMin(Open[0], Close[0]) - Low[0];
if (body < 0.1 * (High[0] - Low[0])) {
return true; // Doji
}
return false;
}
// Buy scenario
// No specific buy scenario for the Doji pattern, as it is a neutral pattern
// Sell scenario
if (isDoji(Open, Close, High, Low)) {
// Enter short position if preceded by a long uptrend
// Set stop loss above the high of the Doji candle
// Set take profit at a predefined target or using a trailing stop
}
Engulfing pattern
This pattern involves two candles, with the second candle completely engulfing the first one. A bullish engulfing pattern occurs when a small bearish candle is followed by a large bullish candle, while a bearish engulfing pattern is the opposite. It can signal a potential reversal.
MT4 Code
bool isEngulfing(double Open[], double Close[], double High[], double Low[]) {
double body1 = MathAbs(Open[1] - Close[1]);
double body2 = MathAbs(Open[0] - Close[0]);
if (Open[0] < Close[0] && Open[1] > Close[1]) {
if (body1 > body2 && Close[0] < Open[1] && Open[0] > Close[1]) {
return true; // Bullish Engulfing
}
} else if (Open[0] > Close[0] && Open[1] < Close[1]) {
if (body1 > body2 && Close[0] > Open[1] && Open[0] < Close[1]) {
return true; // Bearish Engulfing
}
}
return false;
}
Piercing pattern
This pattern also involves two candles, with the second candle opening below the low of the first candle and closing above the midpoint of the first candle. It can indicate that bulls are gaining control after a period of selling pressure.
MT4 Code
bool isPiercingPattern(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[1] - Open[1];
double body2 = Close[0] - Open[0];
double midPoint = (Close[1] + Open[1]) / 2;
if (body1 < 0 && body2 > 0) {
if (Close[0] > Open[1] && Close[0] < midPoint && Open[0] < Close[1]) {
return true; // Bullish Piercing Pattern
}
}
return false;
}
// Buy scenario
if (isPiercingPattern(Open, Close, High, Low)) {
// Enter long position if Bullish Piercing Pattern
// Set stop loss below the low of the Piercing Pattern candle
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
// No specific sell scenario for the Piercing Pattern, as it is a bullish reversal pattern
Dark cloud cover
This pattern is the opposite of the piercing pattern, with the second candle opening above the high of the first candle and closing below the midpoint of the first candle. It can indicate that bears are gaining control after an uptrend.MT4 Code
bool isDarkCloudCover(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[1] - Open[1];
double body2 = Close[0] - Open[0];
double midPoint = (Close[1] + Open[1]) / 2;
if (body1 > 0 && body2 < 0) {
if (Close[0] < Open[1] && Close[0] > midPoint && Open[0] > Close[1]) {
return true; // Bearish Dark Cloud Cover
}
}
return false;
}
// Buy scenario
// No specific buy scenario for the Dark Cloud Cover, as it is a bearish reversal pattern
// Sell scenario
if (isDarkCloudCover(Open, Close, High, Low)) {
// Enter short position if Bearish Dark Cloud Cover
// Set stop loss above the high of the Dark Cloud Cover candle
// Set take profit at a predefined target or using a trailing stop
}
Harami
This pattern involves two candles, with the second candle having a smaller body than the first one and being completely contained within the range of the first candle. It can indicate a potential reversal.
MT4 Code
bool isHarami(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[1] - Open[1];
double body2 = Close[0] - Open[0];
if (body1 > 0 && body2 < 0) {
if (Close[0] > Open[1] && Close[0] < Close[1] && Open[0] > Low[1] && Open[0] < High[1]) {
return true; // Bullish Harami
}
} else if (body1 < 0 && body2 > 0) {
if (Close[0] < Open[1] && Close[0] > Low[1] && Open[0] < Close[1] && Open[0] > High[1]) {
return true; // Bearish Harami
}
}
return false;
}
Morning star
This pattern involves three candles, with the first one being a long bearish candle, the second one being a small-bodied candle with a long upper and lower shadow, and the third one being a long bullish candle. It can indicate a potential reversal.
MT4 Code
bool isMorningStar(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[1] - Open[1];
double body2 = Close[0] - Open[0];
double body3 = Close[2] - Open[2];
if (body1 < 0 && body2 > 0 && body3 < 0) {
if (Close[2] < Open[1] && Close[0] > Open[1] && Close[0] < Close[1]) {
return true; // Bullish Morning Star
}
}
return false;
}
Evening star
This pattern is the opposite of the morning star, with the first candle being a long bullish candle, the second one being a small-bodied candle with a long upper and lower shadow, and the third one being a long bearish candle. It can indicate a potential reversal.
MT4 Code
bool isEveningStar(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[1] - Open[1];
double body2 = Close[0] - Open[0];
double body3 = Close[2] - Open[2];
if (body1 > 0 && body2 < 0 && body3 > 0) {
if (Close[2] > Open[1] && Close[0] < Open[1] && Close[0] > Close[1]) {
return true; // Bearish Evening Star
}
}
return false;
}
// Buy scenario
// No specific buy scenario for the Evening Star, as it is a bearish reversal pattern
// Sell scenario
if (isEveningStar(Open, Close, High, Low)) {
// Enter short position if Bearish Evening Star
// Set stop loss above the high of the Evening Star pattern
// Set take profit at a predefined target or using a trailing stop
}
Shooting star
This pattern is similar to the hanging man, with a long upper shadow and a small body at the bottom of the candle. It can indicate that the market may be due for a correction after an uptrend.
MT4 Code
bool isShootingStar(double Open[], double Close[], double High[], double Low[]) {
double body = Close[0] - Open[0];
double upperWick = High[0] - Close[0];
double lowerWick = Open[0] - Low[0];
if (body < 0 && lowerWick > 2 * upperWick && upperWick <= 0.2 * body) {
return true; // Bearish Shooting Star
}
return false;
}
// Buy scenario
// No specific buy scenario for the Shooting Star, as it is a bearish reversal pattern
// Sell scenario
if (isShootingStar(Open, Close, High, Low)) {
// Enter short position if Bearish Shooting Star
// Set stop loss above the high of the Shooting Star candle
// Set take profit at a predefined target or using a trailing stop
}
Inverted hammer
This pattern is similar to the hammer, with a long upper shadow and a small body at the bottom of the candle. It can indicate that bulls are gaining control of the market after a period of selling pressure.
MT4 Code
bool isInvertedHammer(double Open[], double Close[], double High[], double Low[]) {
double body = Close[0] - Open[0];
double upperWick = High[0] - Close[0];
double lowerWick = Open[0] - Low[0];
if (body < 0 && lowerWick >= 2 * upperWick && upperWick <= 0.2 * body) {
return true; // Bullish Inverted Hammer
}
return false;
}
// Buy scenario
if (isInvertedHammer(Open, Close, High, Low)) {
// Enter long position if Bullish Inverted Hammer
// Set stop loss below the low of the Inverted Hammer candle
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
// No specific sell scenario for the Inverted Hammer, as it is a bullish reversal pattern
Three white soldiers
This pattern involves three consecutive long bullish candles, and it can indicate a strong uptrend.MT4 Code
bool isThreeWhiteSoldiers(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[2] - Open[2];
double body2 = Close[1] - Open[1];
double body3 = Close[0] - Open[0];
if (body1 > 0 && body2 > 0 && body3 > 0) {
if (Close[2] < Close[1] && Close[1] < Close[0]) {
return true; // Bullish Three White Soldiers
}
}
return false;
}
// Buy scenario
if (isThreeWhiteSoldiers(Open, Close, High, Low)) {
// Enter long position if Bullish Three White Soldiers
// Set stop loss below the low of the third candle in the pattern
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
// No specific sell scenario for the Three White Soldiers, as it is a bullish reversal pattern
Three black crows
This pattern is the opposite of the three white soldiers, with three consecutive long bearish candles. It can indicate a strong downtrend.
MT4 Code
bool isThreeBlackCrows(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[2] - Open[2];
double body2 = Close[1] - Open[1];
double body3 = Close[0] - Open[0];
if (body1 < 0 && body2 < 0 && body3 < 0) {
if (Close[2] > Close[1] && Close[1] > Close[0]) {
return true; // Bearish Three Black Crows
}
}
return false;
}
// Buy scenario
// No specific buy scenario for the Three Black Crows, as it is a bearish reversal pattern
// Sell scenario
if (isThreeBlackCrows(Open, Close, High, Low)) {
// Enter short position if Bearish Three Black Crows
// Set stop loss above the high of the third candle in the pattern
// Set take profit at a predefined target or using a trailing stop
}
Tweezer tops and bottoms
This pattern involves two candles with the same high or low, and it can indicate potential resistance or support levels.
MT4 Code
bool isTweezerTops(double Open[], double Close[], double High[], double Low[], int start, int end) {
int topCount = 0;
int bottomCount = 0;
double topLevel = High[start];
double bottomLevel = Low[start];
for (int i = start+1; i <= end; i++) {
if (High[i] == topLevel) {
topCount++;
} else if (Low[i] == bottomLevel) {
bottomCount++;
} else {
break;
}
}
return (topCount >= 2 && bottomCount >= 2 && Close[start] > Open[start] && Close[end] < Open[end]);
}
Rising three method
This pattern involves a long bullish candle followed by three small-bodied bearish candles and another long bullish candle. It can indicate a continuation of an uptrend.MT4 Code
bool isRisingThreeMethod(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[3] - Open[3];
double body2 = Close[2] - Open[2];
double body3 = Close[1] - Open[1];
double body4 = Close[0] - Open[0];
if (body1 > 0 && body4 > 0 && Close[3] > Close[2] && Close[2] > Close[1] &&
Close[1] > Open[1] && Close[0] > Open[0] && body2 < body1 && body3 < body1 && body4 < body1) {
return true; // Bullish Rising Three Method
}
return false;
}
// Buy scenario
if (isRisingThreeMethod(Open, Close, High, Low)) {
// Enter long position if Bullish Rising Three Method
// Set stop loss below the low of the fourth candle in the pattern
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
// No specific sell scenario for the Rising Three Method, as it is a bullish continuation pattern
Falling three method
This pattern is the opposite of the rising three method, with a long bearish candle followed by three small-bodied bullish candles and another long bearish candle. It can indicate a continuation of a downtrend.
MT4 Code
bool isFallingThreeMethod(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[3] - Open[3];
double body2 = Close[2] - Open[2];
double body3 = Close[1] - Open[1];
double body4 = Close[0] - Open[0];
if (body1 < 0 && body4 < 0 && Close[3] < Close[2] && Close[2] < Close[1] &&
Close[1] < Open[1] && Close[0] < Open[0] && body2 > body1 && body3 > body1 && body4 > body1) {
return true; // Bearish Falling Three Method
}
return false;
}
// Buy scenario
// No specific buy scenario for the Falling Three Method, as it is a bearish continuation pattern
// Sell scenario
if (isFallingThreeMethod(Open, Close, High, Low)) {
// Enter short position if Bearish Falling Three Method
// Set stop loss above the high of the fourth candle in the pattern
// Set take profit at a predefined target or using a trailing stop
}
The Abandoned Baby
This pattern is a rare three-candlestick reversal pattern that can indicate a potential trend reversal. It usually occurs after an uptrend or downtrend and is characterized by a doji candle sandwiched between a long bullish candle and a long bearish candle. The doji candle has a gap on either side, which represents a period of indecision in the market.The Abandoned Baby pattern suggests that the bulls or bears have lost control of the market, and a reversal may be imminent. The doji candle represents a period of uncertainty or consolidation, while the long bullish and bearish candles on either indicate a shift in momentum. The pattern is more significant if it occurs after a prolonged uptrend or downtrend, and it is confirmed by further price action in the opposite direction.
Traders who spot the Abandoned Baby pattern may use it as a signal to enter a trade in the opposite direction of the previous trend. They may set stop-loss orders below the low of the doji candle to limit their risk. However, as with any trading strategy, it is important to use other technical indicators and perform proper risk management before making any trading decisions.
MT4 Code
bool isAbandonedBaby(double Open[], double Close[], double High[], double Low[]) {
double body1 = Close[2] - Open[2];
double body2 = Close[1] - Open[1];
double body3 = Close[0] - Open[0];
if (body1 > 0 && body3 < 0 && Open[2] > Close[1] && Close[2] < Open[1] &&
Close[0] < Open[0] && Low[0] > High[1] && body1 > 2 * (High[2] - Low[2])) {
return true; // Bearish Abandoned Baby
} else if (body1 < 0 && body3 > 0 && Open[2] < Close[1] && Close[2] > Open[1] &&
Close[0] > Open[0] && Low[0]<High[1] && body1<2*(High[2]+Low[2])){
return true;}
Belt hold
The Belt hold pattern is a single candlestick pattern that occurs when the opening price is equal to the low price of the day (in the case of a bullish belt hold) or the high price of the day (in the case of a bearish belt hold). The candlestick has a long real body with little to no shadow, indicating strong buying or selling pressure from the open to the close. The Belt hold pattern suggests that the bullish or bearish momentum is likely to continue in the near future.
MT4 Code
bool isBeltHold(double Open[], double Close[], double High[], double Low[]) {
double body = Close[0] - Open[0];
if (body > 0 && Open[0] == Low[0] && Close[0] == High[0]) {
return true; // Bullish Belt Hold
} else if (body < 0 && Open[0] == High[0] && Close[0] == Low[0]) {
return true; // Bearish Belt Hold
}
return false;
}
// Buy scenario
if (isBeltHold(Open, Close, High, Low)) {
// Enter long position if Bullish Belt Hold or exit short position if Bearish Belt Hold
// Set stop loss below the low of the Belt Hold pattern for long positions or above the high for short positions
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
if (isBeltHold(Open, Close, High, Low)) {
// Enter short position if Bearish Belt Hold or exit long position if Bullish Belt Hold
// Set stop loss above the high of the Belt Hold pattern for short positions or below the low for long positions
// Set take profit at a predefined target or using a trailing stop
}
Marubozu
The Marubozu pattern is a single candlestick pattern that has no upper or lower shadow, indicating a strong trend in one direction. There are two types of Marubozu patterns: the bullish Marubozu, which has a long real body and no lower shadow, and the bearish Marubozu, which has a long real body and no upper shadow. The Marubozu pattern indicates that there is strong buying or selling pressure in the market and that the trend is likely to continue in the near future.
MT4 Code
bool isMarubozu(double Open[], double Close[], double High[], double Low[]) {
double body = Close[0] - Open[0];
double upperShadow = High[0] - Close[0];
double lowerShadow = Open[0] - Low[0];
if (body > 0 && upperShadow == 0 && lowerShadow == 0) {
return true; // Bullish Marubozu
} else if (body < 0 && upperShadow == 0 && lowerShadow == 0) {
return true; // Bearish Marubozu
}
return false;
}
// Buy scenario
if (isMarubozu(Open, Close, High, Low)) {
// Enter long position if Bullish Marubozu or exit short position if Bearish Marubozu
// Set stop loss below the low of the Marubozu pattern for long positions or above the high for short positions
// Set take profit at a predefined target or using a trailing stop
}
// Sell scenario
if (isMarubozu(Open, Close, High, Low)) {
// Enter short position if Bearish Marubozu or exit long position if Bullish Marubozu
// Set stop loss above the high of the Marubozu pattern for short positions or below the low for long positions
// Set take profit at a predefined target or using a trailing stop
}
Gravestone doji
The Gravestone doji pattern is a single candlestick pattern that has a long upper shadow and a small real body at the bottom of the candle, indicating that there was a significant amount of selling pressure during the trading session. The pattern suggests that the bulls tried to push the price up, but failed to maintain the momentum, resulting in a doji candlestick with a long upper shadow. The Gravestone doji pattern is a bearish reversal pattern that can indicate a potential trend reversal if it occurs after a prolonged uptrend.It is important to note that while candlestick patterns can be useful in identifying potential trend reversals or continuations, they should not be used in isolation. Traders should use other technical indicators and perform proper risk management before making any trading decisions.
MT4 Code
bool isGravestoneDoji(double Open[], double Close[], double High[], double Low[]) {
double body = Close[0] - Open[0];
double upperShadow = High[0] - Close[0];
double lowerShadow = Open[0] - Low[0];
if (body < 0 && upperShadow == 0 && lowerShadow > body * 2) {
return true; // Gravestone Doji
}
return false;
}
// Buy scenario
// No specific buy scenario for the Gravestone Doji, as it is a bearish reversal pattern
Comments
Post a Comment