Trading Dev AcademyFree quant education

Free lesson · Charts & patterns

Doji, hammer, shooting star and long-body bars

Open interactive lessonPractice calculationsExplore labs

Start with the idea

Separate two questions: “what shape occurred?” and “what tends to happen after that shape under a stated context?” Only the second can address a trading edge.

Symbols, units & horizon
  • B,D,U,A: body, lower wick, upper wick and full range in price units
  • b,d,u: corresponding fractions of range
  • τ_b: maximum body fraction for doji
  • τ_h: maximum body fraction for a wick candidate
  • τ_u: maximum opposite-wick fraction
  • k: minimum wick-to-body multiple
  • ≤,≥: less/greater than or equal to
  • 0

When and why to use this

Use numeric thresholds to make discretionary observations reproducible across researchers and instruments. Test nearby thresholds to see whether the result is stable or merely tuned.

A doji has a small open-to-close body relative to its range. A long-legged doji also has substantial wicks; a dragonfly-like form has most of its wick below the body, and a gravestone-like form above. A long-body or marubozu-like bar closes far from its open with relatively small wicks. These descriptions need numerical tolerances; perfect textbook shapes are uncommon.

doji: b≤τb,lower wick shape: 0<b≤τh, d≥kb, u≤τu
Algebra and arithmetic

Turn a visual label into inequalities

  1. For a doji, B/A≤τ_b. Multiplying by A>0 gives B≤τ_b A. With A=10 and τ_b=.10, body must be at most 1 price unit.
  2. For a lower wick at least k bodies long, D≥kB. Divide by A>0 to obtain d≥kb. With B=1.5,D=6,U=.5,A=8: b=.1875,d=.75,u=.0625, so d≥2b and the example thresholds pass.
Work it by hand

The same candidate fails if the maximum upper-wick fraction is tightened below .0625. This is a change of definition, not a change in the market.

For this course’s teaching rule, use a doji body fraction of at most 0.10. A lower-wick candidate has a nonzero body no larger than 0.35 of its range, lower wick at least twice its body and upper wick at most 0.20 of its range. These are configurable examples, not academically established optimal settings. Minimum range and liquidity filters may be necessary before studying any rule.

GeometryTraditional context/nameResearch question
Long lower wick, small upper bodyAfter decline: hammer. After advance: hanging man.Does prior trend change conditional net returns?
Long upper wick, small lower bodyAfter advance: shooting star. After decline: inverted hammer.Does confirmation add information after accounting for delayed entry?
Small body, substantial rangeDoji / indecision labelDoes this improve a volatility or execution forecast?
Large body, tiny wicksMarubozu-like directional barDoes continuation survive spread, gaps and crowded entry?

Context can reverse the traditional name without changing geometry. A hammer label normally refers to a lower-wick shape after a decline; identifying the same shape during an uptrend does not justify calling it a bullish reversal. Decide whether trend means a trailing slope, moving-average relationship or confirmed swing sequence. Record that definition before inspecting outcomes.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

def single_bar_shapes(o,h,l,c,doji_max=.10,body_max=.35,wick_multiple=2,opposite_max=.20):
    if not l <= min(o,c) <= max(o,c) <= h:
        raise ValueError("Invalid OHLC")
    span=h-l
    if span==0: return []
    b,u,d=abs(c-o)/span,(h-max(o,c))/span,(min(o,c)-l)/span
    labels=[]
    if b<=doji_max: labels.append("doji geometry")
    if 0<b<=body_max and d>=wick_multiple*b and u<=opposite_max:
        labels.append("lower-wick geometry")
    if 0<b<=body_max and u>=wick_multiple*b and d<=opposite_max:
        labels.append("upper-wick geometry")
    if b>=.8 and u<=.1 and d<=.1: labels.append("long-body geometry")
    return labels  # prior trend is a separate input

print(single_bar_shapes(100,102,94,101.5))

Continue learning

Candles, Structures & Pattern Research — all lessons
  1. First principles: what a candle actually records
  2. Doji, hammer, shooting star and long-body bars
  3. Engulfing, inside bars and multi-candle sequences
  4. Trends, ranges, breakouts and chart structures
  5. Indicators as arithmetic: ATR, moving averages, RSI and bands
  6. Known strategy families: from chart idea to complete rules
  7. Pattern recognition: rules, features, shapelets and image models
  8. Quantitative recognition I: build a causal candle feature table
  9. Quantitative recognition II: shapelets and constrained dynamic time warping
  10. Quantitative recognition III: causal encoders and contrastive learning
  11. Quantitative recognition IV: GAF images, CNNs, transformers and visual-model audits
  12. Quantitative recognition V: calibrate, abstain and test the complete strategy
  13. Research review: what the evidence does and does not establish

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations