Define how close the body must be to the low
TradingView describes a doji near the low with a long upper shadow, but its support article does not specify a universal percentage cutoff. The following is a custom, illustrative definition for ordinary OHLC candles. Let O, H, L and C mean open, high, low and close, and let R = H - L. Reject a zero-range candle before dividing by R.
- All conditions must pass. The endpoint rule already implies an upper shadow of at least 90%; the 80% rule is retained as an independent input if the endpoint tolerance is later widened.
- Example: O = 100.10, H = 104.00, L = 100.00 and C = 100.05. R is 4.00; the body is 1.25%, the highest body endpoint is 2.5% above the low, the upper shadow is 97.5%, and the lower shadow is 1.25%.
- These percentages are assumptions, not TradingView defaults or tested optimal settings. A candle with a 7% body fails this example even if it looks like a doji on a compressed chart.
- For instruments with coarse ticks, a one-tick change can cross a percentage boundary. Record the tick size and avoid silently rounding a failed candle into a match.
| Measurement | Calculation | Illustrative requirement |
|---|
| Small body | Absolute difference between C and O, divided by R | At most 5% |
| Both endpoints near the low | (max(O, C) - L) / R | At most 10% |
| Long upper shadow | (H - max(O, C)) / R | At least 80% |
| Lower shadow | (min(O, C) - L) / R | At most 5% |
Gravestone doji versus shooting star
Both shapes place the body near the bottom of a long upper shadow. The gravestone adds the doji requirement: the open and close are nearly the same. A shooting star can have a small but visible body. TradingView describes the shooting star in an uptrend; neither name establishes that a reversal has happened.
- A green gravestone can still satisfy the geometry. In the numerical example, swapping O and C changes body color but leaves all four ratios unchanged.
- A long upper wick without a sufficiently small, low-positioned body is not enough. Keep rejected candles in a review sample so the boundary remains visible.
| Feature | Gravestone doji | Shooting star |
|---|
| Body | Near-zero body under a declared doji tolerance | Small body that need not meet the doji tolerance |
| Upper shadow | Dominates the candle range | Long relative to the small body |
| Context | Bearish reversal hypothesis after a rise | Bearish reversal hypothesis after a rise |
| Classification boundary | The example accepts body / range up to 5% | A larger body may fit a separate shooting-star rule; it is not automatically one |
Define the prior rise and the next-bar decision
For this illustrative reversal test, require the close immediately before the candidate to be above its own 20-bar simple moving average, with that average higher than five bars earlier. Skip candidates without enough history. This is a reproducible trend filter, not proof that the market is at a top.
- At the candidate close, save its high and low. Geometry and the prior-rise filter create a candidate, not a confirmed short signal.
- With confirmation enabled, inspect only the immediately following completed bar. Require its close below the saved low and its high at or below the saved high.
- If the next bar trades above the saved high, invalidate the candidate even if it later closes below the saved low. This stated precedence avoids guessing the intrabar price path.
- Otherwise, a next-bar close at or above the saved low expires the candidate without confirmation. Do not extend the window after seeing later prices.
- With confirmation disabled, label the event as a shape candidate at its own close. Keep that sample separate from next-bar-confirmed events when comparing results.
Follow an unconfirmed candle and a false reversal
Use the hypothetical candidate above, with a saved low of 100 and high of 104, after a prior rise that passes the filter. Each row below is an alternative path, not a sequence of historical trades. All prices use the same arbitrary price units.
- If the same candle appears in a sideways range and fails the prior-rise filter, it remains a shape match outside this reversal setup.
- A confirmation adds information and costs time. Price may already have moved away from the candidate low when the condition becomes knowable.
- The later 104.50 close does not erase the earlier signal. A failure label is an evaluation rule, not a stop order or an assumption that a trade can exit at that close.
- A detector is not a complete strategy. Entry timing, stop execution, position size, exit horizon, commissions and slippage still need separate rules. No win rate follows from these examples.
| Following price action | Classification | Reason |
|---|
| Next bar: high 103.00, low 99.60, close 100.30 | Expired without confirmation | A wick below 100 does not meet the closing condition |
| Next bar: high 103.00, low 99.40, close 99.70 | Confirmed at the next bar close | Close is below 100 and high does not exceed 104 |
| Next bar: high 104.20, low 99.40, close 99.70 | Invalidated before confirmation | The high breach takes precedence over the bearish close |
| After the valid 99.70 confirmation, a later bar closes at 104.50 | Confirmed signal followed by failure | For this review, a later close above 104 invalidates the reversal hypothesis |
Check the chart before turning the rules into a script
In TradingView, open Indicators, metrics, and strategies, then Technicals → Patterns to find the built-in candlestick indicators. Compare their labels with your written rules; different tolerances and trend filters can legitimately produce different matches. The custom thresholds on this page do not reproduce the built-in detector.
- Wait for the candidate candle to close before evaluating its final shape. An open candle can gain a larger body or a new low and stop qualifying.
- Next-bar confirmation becomes knowable one completed bar later. A marker placed on the original candle must not imply that the later information was available then.
- Use ordinary candles for this OHLC definition. TradingView documents Heikin-Ashi prices as synthetic; a gravestone-like shape there describes transformed values.
- To draft a custom detector, give Pineify the four tolerances, the prior-rise filter, and independent switches for trend and next-bar confirmation. Request separate markers for shape candidates, confirmations and invalidations.
- Review the generated conditions, run syntax validation, compile in TradingView, and check the hypothetical cases bar by bar. Closing-bar logic addresses changing intrabar values; it is not a blanket guarantee against every source of repainting.