Overview of Doji Candlestick Pattern
The Doji candlestick is a unique pattern in financial chart analysis, notable for its distinct lack of a significant body. It is characterized by having nearly the same opening and closing prices, which gives it a cross-like or plus-shaped appearance. This pattern reflects a state of equilibrium or indecision in the market, where neither buyers nor sellers gain significant ground during the session.
Importance in Technical Analysis
The Doji candlestick pattern is highly valued in technical analysis for several reasons:
- Market Indecision Signal: It indicates a balance between buyers and sellers, suggesting potential trend reversals or pauses.
- Predictive Nature: Often predicts future market movements, especially when following a strong trend, aiding in timely trading decisions.
- Applicability Across Timeframes: Useful in various time frames, making it versatile for different trading strategies.
- Complements Other Analysis Tools: Works well with other indicators, strengthening overall market analysis.
- Risk Management: Helps in adjusting risk strategies, particularly in anticipating and reacting to potential market reversals.
Different Types of Doji Patterns and Their Significance
Long-Legged Doji
Features long upper and lower shadows, indicating a larger distance between the high and low of the session but a close near the open. This pattern suggests a turning point in the market.
Dragonfly Doji
Has a long lower shadow and no upper shadow, indicating that sellers drove prices down, but buyers were able to push it back to the opening level. This is often seen as a bullish reversal signal.
Gravestone Doji
The opposite of a Dragonfly, with a long upper shadow and no lower shadow. It suggests that buyers initially pushed the price up, but sellers managed to drive it back down, hinting at a bearish reversal.
Example From Trading View
Code For Detecting Doji
//@version=5 indicator("Dojis", overlay=true) // Get user input maxWickSize = input.float(title="Max Wick Size", defval=2.0) maxBodySize = input.float(title="Max Body Size", defval=0.05) // Get candle data topWickSize = high - (close > open ? close : open) bottomWickSize = (close < open ? close : open) - low bodyPercent = math.abs(open - close) / (high - low) // Get our filters swingHigh = high == ta.highest(high, 10) swingLow = low == ta.lowest(low, 10) // Determine if the current bar is a valid doji candle doji = topWickSize <= bottomWickSize * maxWickSize and bottomWickSize <= topWickSize * maxWickSize and bodyPercent <= maxBodySize dojiBull = doji and swingLow dojiBear = doji and swingHigh // Draw dojis onto the chart plotshape(dojiBull, style=shape.triangleup, location=location.belowbar, color=color.green) plotshape(dojiBear, style=shape.triangledown, location=location.abovebar, color=color.red)
Output
Overview of the script
This script is written in Pine Script, which is used for creating custom indicators and strategies on the TradingView platform. It’s designed to detect doji candles, a type of candlestick pattern in financial charts. Let’s break down the code step by step:
1.Defining the Indicator and User Inputs:
indicator("Dojis", overlay=true)
This line sets up a new indicator named “Dojis”. The overlay=true parameter ensures that this indicator is overlaid on the main price chart.
maxWickSize = input.float(title="Max Wick Size", defval=2.0) maxBodySize = input.float(title="Max Body Size", defval=0.05)
Here, two user inputs are defined. maxWickSize is the maximum allowed ratio of the wick sizes, and maxBodySize is the maximum size of the candle body as a proportion of the entire candle range. These parameters can be adjusted by the user.
2.Getting Candle Data:
topWickSize = high - (close > open ? close : open) bottomWickSize = (close < open ? close : open) - low bodyPercent = math.abs(open - close) / (high - low)
These lines calculate the sizes of the candle components. topWickSize is the size of the upper wick, bottomWickSize is the size of the lower wick, and bodyPercent is the size of the candle body relative to the total candle range.
3.Identifying Swing Highs and Lows:
swingHigh = high == ta.highest(high, 10) swingLow = low == ta.lowest(low, 10)
This part identifies if the current candle is at a swing high or low by comparing the current high/low to the highest/lowest value over the last 10 bars.
4.Defining Doji Candles:
doji = topWickSize <= bottomWickSize * maxWickSize and bottomWickSize <= topWickSize * maxWickSize and bodyPercent <= maxBodySize dojiBull = doji and swingLow dojiBear = doji and swingHigh
A doji candle is defined here based on the calculated sizes. A candle is considered a doji if both wicks are within the specified max wick size, and the body is within the specified max body size. dojiBull and dojiBear are specific types of doji candles appearing at swing lows and highs, respectively.
5.Plotting the Doji Candles:
plotshape(dojiBull, style=shape.triangleup, location=location.belowbar, color=color.green) plotshape(dojiBear, style=shape.triangledown, location=location.abovebar, color=color.red)
Finally, the script plots shapes on the chart where doji candles are found. Bullish doji candles are marked with green triangles below the bars, and bearish doji candles are marked with red triangles above the bars.
Frequently Asked Questions
A Doji candlestick pattern is a type of pattern found in financial charts, representing a period where the opening and closing prices are almost the same, indicating indecision in the market.
The Pine Script code identifies Doji patterns on TradingView charts by calculating the size of candle wicks and bodies, and then comparing these to predefined thresholds for what constitutes a Doji.
The key parameters are maxWickSize, which defines the maximum allowed ratio of wick sizes, and maxBodySize, which specifies the maximum relative size of the candle body.
Yes, you can adjust the sensitivity by changing the values of maxWickSize and maxBodySize in the input settings.
dojiBull and dojiBear are specific types of Doji candles. dojiBull appears at swing lows, indicating potential bullish reversals, while dojiBear appears at swing highs, indicating potential bearish reversals.
Conclusion
The Pine Script provided is an effective tool for detecting Doji candlestick patterns on the TradingView platform, essential for traders practicing technical analysis. It offers customization through parameters like maxWickSize and maxBodySize, allowing for adaptability to different trading strategies. The script aids in identifying potential trend reversals by highlighting dojiBull and dojiBear patterns at swing highs and lows, visually represented on charts for easy recognition.