Home » Candlestick Patterns » Detecting Bullish Harami Candlestick Pattern in Pine Script

Detecting Bullish Harami Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Bullish Harami Candlestick Pattern

The Bullish Harami is a candlestick pattern recognized in technical analysis as a potential indicator of a trend reversal, particularly in bearish markets. This pattern, consisting of two candlesticks, is known for signaling a decrease in bearish momentum and the possible onset of a bullish trend.

Bullish Harami Candlestick Pattern
  • Potential Trend Reversal: The Bullish Harami suggests a weakening of bearish momentum, indicating that a bullish reversal might be on the horizon.
  • Shift in Market Sentiment: This pattern is often interpreted as a sign that the bears are losing control and the bulls are starting to gain strength.

Importance in Technical Analysis

The Bullish Harami candlestick pattern holds significant importance in technical analysis for several reasons:

  1. Potential Trend Reversal Indicator: As a precursor to a potential shift from a bearish to a bullish trend, the Bullish Harami is crucial for identifying early signs of market reversal.
  2. Sentiment Shift Representation: It represents a change in market sentiment, indicating that the bearish momentum might be losing strength and a bullish sentiment is starting to emerge.
  3. Risk Management Tool: The pattern can aid in risk management, allowing traders to adjust their strategies, whether it’s tightening stop-loss orders or preparing to enter long positions.
  4. Enhances Trading Strategy: When combined with other technical indicators, such as moving averages, RSI, or MACD, the Bullish Harami can enhance the robustness of a trading strategy.
  5. Useful in Multiple Timeframes: It can be applied across various timeframes, making it a versatile tool for day traders, swing traders, and long-term investors alike.

Example From Trading View

This image has an empty alt attribute; its file name is EURUSD_2024-01-06_20-27-16_1d1a2-1024x690.png

Defining the Bullish Harami Candlestick Pattern Criteria 

The Bullish Harami is a two-candlestick pattern that is often considered a sign of a potential reversal in a downtrend. Here are the defining criteria for the Bullish Harami candlestick pattern:

  1. Prevailing Trend:
    • The pattern should occur within a downtrend. Its presence in a bearish context is crucial for its potential as a reversal signal.
  2. First Candlestick:
    • Large Bearish Candle: The first candlestick is a large bearish one, indicating strong selling pressure. It should have a significantly larger body compared to recent candles.
  3. Second Candlestick:
    • Small Bullish Candle: The second candlestick is a small bullish one. The key aspect is that its body is completely contained within the vertical range of the body of the first candle.
    • Positioning: This candle opens and closes within the range of the body of the previous day’s candlestick.
  4. Contrast in Size and Color:
    • The stark contrast between the first large bearish candle and the second smaller bullish candle is essential for this pattern.

Code For Detecting Bullish Harami

//@version=5
indicator("Bullish Harami Detector ", overlay=true)

// Detecting Bullish Harami pattern
isBullishHarami() =>
    bearishCandle = close[1] < open[1] and open[1]>close
    bullishCandle = close > open 
    sizeWithin = high < high[1] and low > low[1]
    bearishCandle and bullishCandle and sizeWithin

// Plotting the pattern using labels
if isBullishHarami()
    label.new(bar_index, high, "Bullish Harami", style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)

Output

Output

Overview of the script 

1. Indicator Declaration

//@version=5
indicator("Bullish Harami Detector ", overlay=true)
  • @version=5: Specifies that the script uses version 5 of Pine Script.
  • indicator(...): This function declares a new custom indicator.
    • "Bullish Harami Detector": The name of the indicator.
    • overlay=true: Indicates that the indicator will be plotted directly on the price chart.

2. Bullish Harami Detection Function

isBullishHarami() =>
    bearishCandle = close[1] < open[1] and open[1]>close
    bullishCandle = close > open 
    sizeWithin = high < high[1] and low > low[1]
    bearishCandle and bullishCandle and sizeWithin

isBullishHarami(): A user-defined function to check for a Bullish Harami pattern.

  • bearishCandle: Checks if the previous candle is bearish (closing price lower than opening price).
  • bullishCandle: Checks if the current candle is bullish (closing price higher than opening price).
  • sizeWithin: Ensures the current candle is within the high and low range of the previous candle.
  • The function returns true if all conditions are met, indicating a Bullish Harami pattern.

3. Plotting the Pattern

if isBullishHarami()
    label.new(bar_index, high, "Bullish Harami", style=label.style_label_down, color=color.green, textcolor=color.white, yloc=yloc.abovebar)

This block creates a label on the chart wherever a Bullish Harami pattern is detected.

  • if isBullishHarami(): Checks if the Bullish Harami pattern is present on the current bar.
  • label.new(...): Creates a new label.
    • bar_index: The index of the current bar (used for positioning the label).
    • high: Places the label at the high price of the bar.
    • "Bullish Harami": The text displayed in the label.
    • style=label.style_label_down: The label points downwards.
    • color=color.green: The label’s color (green).
    • textcolor=color.white: The color of the text (white).
    • yloc=yloc.abovebar: The label is positioned above the bar.

Frequently Asked Questions

What is the purpose of this Pine Script?

This script is designed to detect and visually indicate Bullish Harami candlestick patterns on TradingView charts, a potential sign of bullish reversals.

Which version of Pine Script is this code written for?

The code is written for Pine Script version 5, the latest version available on TradingView.

Can I modify the parameters of the Bullish Harami pattern in this script?

The script doesn’t have user-defined inputs for parameters, but you can manually adjust the conditions within the code if necessary.

How does the script indicate a Bullish Harami pattern on the chart?

It uses a green label, marked “Bullish Harami” and is placed above the bar where the pattern is detected.

Conclusion

The Bullish Harami Detector script is designed to identify the Bullish Harami candlestick pattern automatically. This script aids in quickly spotting potential bullish reversal signals, marked by clear green labels for easy recognition. While it enhances technical analysis, it’s important to use this script as part of a wider trading strategy, complemented by other technical indicators for more reliable decision-making.

Leave a Comment