Home » Candlestick Patterns » Detecting Dragonfly Doji Candlestick Pattern in Pine Script

Detecting Dragonfly Doji Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Dragonfly Doji Candlestick Pattern

The Dragonfly Doji candlestick pattern is a significant formation in technical analysis, often indicating potential reversals in market trends. It’s part of the Doji family, where the opening and closing prices are virtually the same, reflecting indecision in the market. Here’s an overview of its characteristics and implications:

Dragonfly Doji Candlestick Pattern
  1. Appearance and Structure: The Dragonfly Doji is characterized by a long lower shadow (wick) and a very small or non-existent body at the top of the trading range. The candlestick has little to no upper shadow. Its distinctive T-shape forms when the open, high, and close prices are roughly the same, and the low is significantly lower.
  2. Market Implications: This pattern is most significant when it appears after a downtrend. It suggests that sellers were initially in control, pushing prices lower, but by the end of the trading period, buyers managed to push the prices back up to the opening level. This can be interpreted as a sign of a potential bullish reversal, especially when confirmed by the subsequent price action.
  3. Trading Considerations: Traders often look for additional confirmation before acting on a Dragonfly Doji. This confirmation might come from the following candle being bullish, or from other technical indicators aligning with the reversal signal. The longer the lower wick, the more significant the potential reversal.

Importance in Technical Analysis

In technical analysis, the Dragonfly Doji candlestick pattern holds significant importance due to its potential to signal key market reversals and sentiment shifts. Its relevance and importance can be understood through various aspects:

  1. Indication of Reversal: The Dragonfly Doji is primarily seen as a reversal pattern, particularly when it appears at the bottom of a downtrend. It signifies that the selling pressure during the session was overcome by buying pressure, suggesting a potential shift from a bearish to a bullish market sentiment.
  2. Reflecting Market Indecision: This pattern epitomizes market indecision, where the opening and closing prices are almost identical. It shows that neither buyers nor sellers could gain control during the trading session, leading to an equilibrium. Such indecision, particularly following a strong trend, can be a crucial indicator for traders.
  3. Sentiment Shift Indicator: The long lower shadow of the Dragonfly Doji indicates that sellers pushed the price down, but buyers were able to resist this selling pressure and push the price back up to near the opening level. This shift from bearish to bullish sentiment within a single session can be a powerful signal for traders.
  4. Enhancing Other Analysis: When combined with other technical analysis tools, such as trend lines, moving averages, or momentum indicators, the Dragonfly Doji can provide stronger validation for potential market moves. Its significance is heightened when it aligns with other signals or occurs at key support or resistance levels.
  5. Risk Management: For traders, recognizing a Dragonfly Doji can be a cue for potential entry or exit points, aiding in risk management. It can signal a stop to further selling and a chance for buyers to enter the market, or vice versa.

Example From Trading View

Example From Trading View

Defining the Dragonfly Doji Candlestick Pattern Criteria 

The Dragonfly Doji candlestick pattern is identified by the following key criteria:

  1. Open-Close Proximity: The opening and closing prices are very close to each other, creating a small or nonexistent body.
  2. Long Lower Shadow: A significant long lower shadow indicates that prices dropped during the session but recovered to near the opening level.
  3. No or Short Upper Shadow: There is typically no upper shadow, or it is very short.
  4. Trend Context: Most effective when appearing at the end of a downtrend, suggesting a potential bullish reversal.
  5. Shadow Length: The lower shadow is notably long compared to the overall candle size, often several times the length of the entire candle.

Code For Detecting Dragonfly Doji

//@version=5
indicator("Dragonfly Doji Detector v5", shorttitle="DD Detector v5", overlay=true)

// Parameters for Dragonfly Doji
dojiSize = input(0.1, title="Maximum Body Size as % of Range")
lowerWickRatio = input(0.7, title="Minimum Lower Wick Size as % of Range")

// Calculate the size of the candle body and the entire range
bodySize = math.abs(close - open)
fullRange = high - low

// Criteria for a Dragonfly Doji
isBodySmall = bodySize <= fullRange * dojiSize
isLowerWickLong = (low < math.min(open, close)) and ((math.min(open, close) - low) >= fullRange * lowerWickRatio)

// Detecting the Dragonfly Doji
isDragonflyDoji = isBodySmall and isLowerWickLong

// Plotting using labels
if isDragonflyDoji
    label.new(bar_index, high, "Dragonfly Doji", style=label.style_label_down, color=color.rgb(255, 0, 0), textcolor=color.white,yloc = yloc.abovebar)

Output

Output

Overview of the script 

1. Script Declaration

//@version=5
indicator("Dragonfly Doji Detector v5", shorttitle="DD Detector v5", overlay=true)
  • //@version=5: Specifies that the script uses Pine Script version 5.
  • indicator(...): Declares the script as a custom indicator.
    • "Dragonfly Doji Detector v5": The full name of the indicator.
    • shorttitle="DD Detector v5": A shorter name for display purposes.
    • overlay=true: Indicates that the indicator will be drawn over the price chart.

2. Input Parameters

dojiSize = input(0.1, title="Maximum Body Size as % of Range")
lowerWickRatio = input(0.7, title="Minimum Lower Wick Size as % of Range")

input(...): This function allows users to input custom values.

  • dojiSize: Represents the maximum size of the candle body as a percentage of the total price range.
  • lowerWickRatio: Specifies the minimum size of the lower wick relative to the candle’s total range.

3. Candlestick Size Calculations:

bodySize = math.abs(close - open)
fullRange = high - low
  • bodySize: Calculates the absolute size of the candle body (difference between the close and open prices).
  • fullRange: Computes the total range of the candle (difference between the high and low prices).

4. Criteria for Dragonfly Doji:

isBodySmall = bodySize <= fullRange * dojiSize
isLowerWickLong = (low < math.min(open, close)) and ((math.min(open, close) - low) >= fullRange * lowerWickRatio)
  • isBodySmall: Checks if the candle body is small enough to be considered a Doji.
  • isLowerWickLong: Ensures that the lower wick is sufficiently long relative to the full range.

5. Detecting the Dragonfly Doji:

isDragonflyDoji = isBodySmall and isLowerWickLong
  • isDragonflyDoji: A boolean variable that is true if both the small body and long lower wick criteria are met.

6. Plotting Labels:

if isDragonflyDoji
    label.new(bar_index, high, "Dragonfly Doji", style=label.style_label_down, color=color.rgb(255, 0, 0), textcolor=color.white, yloc=yloc.abovebar)
  • This block of code executes if isDragonflyDoji is true.
  • label.new(...): Creates a new label on the chart.
    • bar_index, high: Position of the label at the high price of the current bar.
    • "Dragonfly Doji": Text displayed in the label.
    • style=label.style_label_down: The style of the label, pointing downwards.
    • color=color.rgb(255, 0, 0): The color of the label (red).
    • textcolor=color.white: The text color (white).
    • yloc=yloc.abovebar: The label’s location is set above the bar.

Frequently Asked Questions

What does this script detect?

It identifies the Dragonfly Doji pattern, a candlestick with a long lower shadow and a small body, indicating a potential market reversal.

Can I adjust the detection sensitivity?

Yes, modify the dojiSize and lowerWickRatio values in the script to adjust sensitivity.

Why does the script use labels?

Labels provide clear and direct identification of the pattern, especially useful on complex charts.

Is this script effective for all markets?

It can be used across various markets but effectiveness varies with market conditions. Use it alongside other analysis tools for better results.

How should I interpret a Dragonfly Doji signal?

It suggests a potential bullish reversal, especially after a downtrend. Look for additional confirmation before making trades.

Conclusion

The provided Pine Script for detecting Dragonfly Doji patterns automates the identification of a key candlestick pattern that signals potential bullish reversals, especially after a downtrend. By customizing sensitivity parameters like dojiSize and lowerWickRatio, users can adapt the script to different markets and trading styles.

Leave a Comment