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

Detecting Gravestone Doji Candlestick Pattern in Pine Script

Photo of author
Published on

Overview of Gravestone Doji Candlestick Pattern


The Gravestone Doji is a significant candlestick pattern in technical analysis, often seen as a potential indicator of a trend reversal, particularly in a bullish context. It is a unique pattern that conveys meaningful insights into market sentiment and future price movements.

  1. Appearance: The Gravestone Doji is characterized by a long upper shadow and virtually no lower shadow. The open, low, and close prices are typically at the same or nearly the same level.
  2. Formation: This pattern forms when the price opens at a low, rallies to a high, but then sellers push it back down to close near the open.
  3. Psychological Implication: It represents a scenario where buyers initially drive the price up, but ultimately, sellers gain control and push the price back down, reflecting a significant sell-off from the highs.

Importance in Technical Analysis


The Gravestone Doji, as a candlestick pattern in technical analysis, holds significant importance due to several reasons:

  1. Trend Reversal Signal: It is primarily viewed as a bearish reversal signal, especially when occurring after an uptrend. This makes it a crucial tool for traders and investors to anticipate potential trend reversals.
  2. Market Sentiment Indicator: The Gravestone Doji reflects a specific market sentiment where buyers initially push the price up, but by the close, sellers take control, driving the price back down. This shift from bullish to bearish sentiment within a single trading session can be a key indicator of changing market dynamics.
  3. Risk Management: The pattern helps in risk management by providing early signals of potential bearish reversals. Traders can use this information to adjust their positions, place stop-loss orders, or reconsider their investment strategies.
  4. Enhanced with Confirmation: While the Gravestone Doji is a significant pattern, its reliability increases when combined with other technical indicators or a subsequent bearish candlestick. This approach enhances the effectiveness of technical analysis by providing a more comprehensive view of the market.
  5. Volume Analysis Correlation: When a Gravestone Doji is accompanied by high trading volume, it may indicate a stronger bearish reversal signal, adding to its importance in market analysis.

Example From Trading View

Example From Trading View

Defining the Gravestone Doji Candlestick Pattern Criteria 

The Gravestone Doji is a specific type of candlestick pattern in technical analysis that is identified by its unique structure. Here are the defining criteria for a Gravestone Doji candlestick pattern:

  • Long Upper Shadow: The candlestick has a long upper shadow, which is created when the price rises significantly above the opening level but falls back near the opening level by the close.
  • No or Very Short Lower Shadow: There is little to no lower shadow, indicating that the low and open prices are very close to each other.
  • Open and Close Near the Same Level: The open and close prices should be at or very near the same level, making the body of the candlestick appear as a thin line.

Code For Detecting Gravestone Doji

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

// Parameters for Gravestone Doji
dojiSize = input(0.1, title="Maximum Body Size as % of Range")
upperWickRatio = input(0.7, title="Minimum Upper 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 Gravestone Doji
isBodySmall = bodySize <= fullRange * dojiSize
isUpperWickLong = (high > math.max(open, close)) and ((high - math.max(open, close)) >= fullRange * upperWickRatio)

// Detecting the Gravestone Doji
isGravestoneDoji = isBodySmall and isUpperWickLong

// Plotting using labels
if isGravestoneDoji
    label.new(bar_index, low, "Gravestone Doji", style=label.style_label_up, color=color.rgb(255, 0, 0), textcolor=color.white, yloc = yloc.belowbar)

Output

Overview of the script 

1. Indicator Declaration

//@version=5
indicator("Gravestone Doji Detector v5", shorttitle="GSD Detector v5", overlay=true)
  • @version=5: Specifies that this script uses version 5 of Pine Script.
  • indicator(...): Declares a new custom indicator.
    • "Gravestone Doji Detector v5": The full name of the indicator.
    • shorttitle="GSD Detector v5": A shorter title for the indicator.
    • overlay=true: This indicator will be plotted directly on the price chart.

2. Input Parameters

bodySize = math.abs(close - open)
fullRange = high - low

3. Calculations

bodySize = math.abs(close - open)
fullRange = high - low
  • bodySize: Calculates the absolute size of the candle’s body (distance between the open and close prices).
  • fullRange: Determines the full price range of the candle (distance between the high and low).

4. Doji Detection Criteria

isBodySmall = bodySize <= fullRange * dojiSize
isUpperWickLong = (high > math.max(open, close)) and ((high - math.max(open, close)) >= fullRange * upperWickRatio)
  • isBodySmall: A condition that checks if the candle’s body is small enough relative to the full range (according to dojiSize).
  • isUpperWickLong: A condition that checks if the upper wick is long enough (according to upperWickRatio).

5. Gravestone Doji Detection

isGravestoneDoji = isBodySmall and isUpperWickLong
  • isGravestoneDoji: Combines the above conditions to identify a Gravestone Doji. This is true when both isBodySmall and isUpperWickLong are true.

6. Plotting

if isGravestoneDoji
    label.new(bar_index, low, "Gravestone Doji", style=label.style_label_up, color=color.rgb(255, 0, 0), textcolor=color.white, yloc = yloc.belowbar)

This block creates a label on the chart wherever a Gravestone Doji is detected.

  • label.new(...): Creates a new label.
  • bar_index: The index of the current bar (used to position the label).
  • low: The label is positioned at the low price of the bar.
  • "Gravestone Doji": Text displayed in the label.
  • style=label.style_label_up: The label points upwards.
  • color=color.rgb(255, 0, 0): The label’s color (red).
  • textcolor=color.white: The color of the text (white).
  • yloc = yloc.belowbar: The label is positioned below the bar.

Frequently Asked Questions

What is this Pine Script designed for?

This script is designed to detect and highlight Gravestone Doji candlestick patterns on TradingView charts.

What version of Pine Script is this code written in?

It’s written in Pine Script version 5.

Can I change the parameters for detecting a Gravestone Doji?

Yes, you can adjust the parameters for body size (dojiSize) and upper wick size (upperWickRatio) to fit your analysis needs.

What does dojiSize represent in the script?

The upperWickRatio determines the minimum length of the upper wick as a percentage of the total candle range, crucial for identifying Gravestone Doji patterns.

Is this script suitable for all types of financial markets?

While it can be applied to various markets, its effectiveness may vary. It’s best to test it in the specific market you’re analyzing.

Conclusion

This Gravestone Doji Detector script is a practical addition to the toolkit of any trader utilizing technical analysis on TradingView. It provides an automated, customizable, and visually intuitive method for spotting potential trend reversals signaled by Gravestone Doji candlestick patterns. However, reliance on this script alone is not advisable; it should be used in conjunction with a broader analytical approach for optimal trading decisions.

Leave a Comment