Doji candlestick: rules, types and context
A doji candlestick has an open and close at the same or nearly the same price. Its small body records little net change during that bar, even when price traveled far between its high and low. Traders often call this indecision. The shape alone does not tell you whether the next move will reverse or continue the trend.
Key Takeaways
- A doji describes a small open-to-close change; it does not establish a reversal.
- State the body denominator, tolerance, zero-range policy and minimum range before comparing detections.
- Doji subtypes describe shadow geometry. Trend context and later confirmation answer separate questions.
- Use completed ordinary candles for the example rules, and record later confirmation when it actually becomes available.
Define the body tolerance before counting doji candles
TradingView describes a doji as having essentially equal open and close prices, without prescribing a universal percentage in its definition. For a reproducible detector, state what "nearly equal" means. Let body be the absolute difference between close and open, and range be high minus low. When range is positive, body percentage is 100 × body ÷ range. An illustrative rule is body percentage at or below 5%. A candle with open 100, close 100.20, high 103 and low 99 has a body of 0.20 and range of 4, so it sits at the 5% boundary. A close of 100.21 fails that rule. These are hypothetical prices and a chosen threshold, not a TradingView default or a tested trading edge.
| Measurement | Illustrative rule | Boundary to preserve |
|---|---|---|
| Body relative to range | Body percentage at or below 5% | Expose the percentage as an input; changing it changes the sample. |
| Zero range | Exclude before dividing | If high equals low, the percentage is undefined. Do not turn 0 ÷ 0 into a valid signal. |
| Very small range | Optionally require at least 4 minimum price ticks | A separate adjustable filter avoids counting every flat or nearly flat bar. |
| Upper shadow | High minus the higher of open and close | Measure in price units before comparing its share of the range. |
| Lower shadow | The lower of open and close minus low | Do not divide a shadow by a zero body to classify the subtype. |
- At a tick size of 0.01 and a range of 0.10, one tick is 10% of the range. A 5% rule therefore accepts only an exactly equal open and close on that bar.
- Some implementations use a different denominator. Schwab thinkorswim defines its LongLeggedDoji body limit relative to average body height, so it need not label the same candles as this range-based example.
- A zero-range candle is sometimes called a four-price doji. Keep that descriptive label separate from an active-range detection rule and investigate the data before interpreting it.
Types of doji candlestick: compare the shadows
The main doji candlestick patterns differ in where the small body sits and how far the shadows extend. These shape labels describe a completed bar; bullish and bearish interpretations also depend on what preceded it and what happens afterward. A long-legged doji needs a stated benchmark for "long," such as recent average shadow length, if you want a script to identify it consistently.
| Type | Shape | What the shape does not establish |
|---|---|---|
| Standard doji | Near-equal open and close with shadows on both sides | No direction is implied by the small body alone. |
| Dragonfly doji | Body near the high, long lower shadow, little upper shadow | A recovery from the low is not proof that a decline has ended. |
| Gravestone doji | Body near the low, long upper shadow, little lower shadow | A retreat from the high is not proof that an advance has ended. |
| Long-legged doji | Long upper and lower shadows with a near-zero body | Large movement in both directions does not select the next breakout direction. |
| Bar | Open | High | Low | Close |
|---|---|---|---|---|
| Standard | 100 | 102 | 98 | 100.1 |
| Dragonfly | 102 | 102.1 | 98 | 102 |
| Gravestone | 98 | 102 | 97.9 | 98 |
| Long-legged | 100 | 106 | 94 | 100 |
Hollow bodies close at or above the open. Filled bodies close below the open.
Illustrative independent candles, not a price sequence or historical market data. The longer final shadows show the geometry only; a detector needs a separate lookback and threshold for the long-legged label.
A doji after a trend means something different from one in a range
After an advance, a doji can be a reason to test for weakening continuation. After a decline, it can be a reason to test for a recovery. Neither observation lets you call the candle a trend top or bottom at the time it closes. Those labels require later prices. In a sideways market, the same small net change may fit the existing range behavior. A doji at the range midpoint supplies little new directional information; one at a previously defined boundary gives you a specific level to watch. Define the range before seeing the candle, rather than drawing a convenient boundary afterward.
| Context | Question to test | Evidence against it |
|---|---|---|
| After an advance | Will later price break below the doji range? | Price continues above its high or never meets the bearish confirmation rule. |
| After a decline | Will later price break above the doji range? | Price continues below its low or never meets the bullish confirmation rule. |
| Inside a sideways range | Does price leave the established range, not just the doji? | A small candle breakout stays inside the wider range or quickly returns. |
Keep shape detection, confirmation and failure separate
A testable example could first require the three closes preceding the doji to decline successively. After a qualifying doji closes, require the next bar to close above its high without trading below its low. If either condition is absent, this one-bar setup expires. This is one illustrative confirmation rule, not a universal requirement for trading doji candles. Suppose the prior closes are 106, 104 and 102, followed by the hypothetical doji with open 100, high 103, low 99 and close 100.20. A next bar with high 104, low 99.50 and close 103.50 confirms the stated setup. A high of 104 followed by a close of 102 does not: an intrabar breach is different from a close above 103. Even after confirmation, a subsequent trade below 99 breaks the low-holding premise. Confirmation arrives one bar later and can leave less room between entry and a planned exit. Entry price, stop buffer, position size, commissions and slippage still need separate rules. A gap through a stop can produce a worse fill than the chosen level.
- An optional volume condition can require the doji volume to exceed the mean of the preceding 20 completed bars. Treat the filter as a hypothesis to test, not evidence of institutional participation.
- If volume is unavailable or represents a different measure for the chosen instrument, explicitly disable the filter or reject the setup. Do not silently treat missing data as confirmation.
- Compare results across a reserved test period after selecting the rules. The candle shape and these hypothetical examples provide no success-rate estimate.
When a TradingView doji marker can change
An open candle can move into and out of the doji tolerance as close, high and low change. For chart-timeframe detection, evaluate the final shape at bar close. TradingView documents barstate.isconfirmed as true on the closing update of a realtime bar. A later confirmation candle has its own closing time; its signal should not be backdated to the doji. Use ordinary candles when the intended rule is about traded OHLC prices. Heikin-Ashi candles use synthetic OHLC values, so a doji on that chart is a property of transformed data. Closing-bar logic also does not resolve every repainting issue: higher-timeframe requests, future-looking data access and historical marker placement require separate review.
Pineify next step
Turn your doji definition into adjustable inputs
Give Pineify AI Coding Agent the body-to-range tolerance, minimum range in ticks, trend lookback, optional volume condition and confirmation deadline. Ask for separate shape and confirmation markers, then check the output against the boundary and failure examples above.
Sources and verification
Last verified:
Educational information, not investment advice. Thresholds and chart prices are illustrative, not optimized parameters or backtest results. Trading involves risk of loss; a confirmed pattern does not guarantee a profitable trade.