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.

Explicit measurement choices for a custom doji detector
MeasurementIllustrative ruleBoundary to preserve
Body relative to rangeBody percentage at or below 5%Expose the percentage as an input; changing it changes the sample.
Zero rangeExclude before dividingIf high equals low, the percentage is undefined. Do not turn 0 ÷ 0 into a valid signal.
Very small rangeOptionally require at least 4 minimum price ticksA separate adjustable filter avoids counting every flat or nearly flat bar.
Upper shadowHigh minus the higher of open and closeMeasure in price units before comparing its share of the range.
Lower shadowThe lower of open and close minus lowDo 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.

Common doji shapes and what each one actually shows
TypeShapeWhat the shape does not establish
Standard dojiNear-equal open and close with shadows on both sidesNo direction is implied by the small body alone.
Dragonfly dojiBody near the high, long lower shadow, little upper shadowA recovery from the low is not proof that a decline has ended.
Gravestone dojiBody near the low, long upper shadow, little lower shadowA retreat from the high is not proof that an advance has ended.
Long-legged dojiLong upper and lower shadows with a near-zero bodyLarge movement in both directions does not select the next breakout direction.
Four hypothetical doji shapes on one price scale
94100106Standard: open 100, high 102, low 98, close 100.1StandardDragonfly: open 102, high 102.1, low 98, close 102DragonflyGravestone: open 98, high 102, low 97.9, close 98GravestoneLong-legged: open 100, high 106, low 94, close 100Long-legged
OHLC values for Four hypothetical doji shapes on one price scale
BarOpenHighLowClose
Standard10010298100.1
Dragonfly102102.198102
Gravestone9810297.998
Long-legged10010694100

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 changes the hypothesis, not the measured shape
ContextQuestion to testEvidence against it
After an advanceWill later price break below the doji range?Price continues above its high or never meets the bearish confirmation rule.
After a declineWill later price break above the doji range?Price continues below its low or never meets the bullish confirmation rule.
Inside a sideways rangeDoes 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.

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.

Frequently Asked Questions