Compare the bullish and bearish gap rules
TradingView describes a long first candle, a smaller second candle of the same color and an opposing third close inside the gap. Number the candles 1, 2 and 3, oldest first; O, H, L and C mean ordinary open, high, low and close. Under the stated candle colors, the body-gap boundaries reduce to C1 and O2.
- The third-open containment test is explicit in TA-Lib. Its Tasuki implementation also compares bodies 2 and 3 for similar size using a configurable Near setting. TradingView documentation and TA-Lib are not interchangeable detector specifications.
- A body gap permits overlapping shadows. A separate full-range test would require L2 > H1 for upside or H2 < L1 for downside. TradingView's Gaps indicator uses full high-low separation, so its gap boxes need not match a body-based Tasuki detector.
- A wick that crosses the far edge is an intrabar fill even when the close stays inside. This page classifies the close-based shape and records wick fills separately; it does not claim the gap remained untouched throughout candle 3.
| Condition | Upside Tasuki | Downside Tasuki |
|---|
| Background | Prior advance | Prior decline |
| First two candles | C1 > O1 and C2 > O2 | C1 < O1 and C2 < O2 |
| Body gap G | O2 - C1 > 0 | C1 - O2 > 0 |
| Third candle | C3 < O3 | C3 > O3 |
| Third open inside body 2 | O2 < O3 < C2 | C2 < O3 < O2 |
| Third close inside gap | C1 < C3 < O2 | O2 < C3 < C1 |
| Close-based fill fraction F | (O2 - C3) / G | (C3 - O2) / G |
| Partial fill | 0 < F < 1 | 0 < F < 1 |
Fix the thresholds before scanning a chart
For a reproducible research variant, require three strictly rising closes immediately before candle 1 for upside, or three strictly falling closes for downside. Define B = abs(C - O). Require B1 >= 1.5 times the mean body of the preceding 20 completed bars, and 0 < B2 < B1. Apply every directional, opening and closing test in the table above.
- These trend and body thresholds are chosen examples, not optimized values or TradingView defaults. This variant has no extra body-2/body-3 similarity filter and does not reproduce TA-Lib exactly. Save that distinction with your results.
- Use a positive instrument tick t and tick-aligned prices. Strict inside means at least one tick away from each boundary: upside C1 + t <= C3 <= O2 - t; downside O2 + t <= C3 <= C1 - t. A one-tick gap cannot contain a tick-aligned close strictly inside it; a two-tick gap can.
- Apply the same one-tick-inside logic to O3 within body 2. Do not widen the gap or round a boundary touch into a valid partial fill. Reject missing history, a nonpositive mean body, H < max(O, C), L > min(O, C), or H < L.
- Evaluate the candidate only after candle 3 closes. TradingView offers SMA50, SMA50 with SMA200, and no trend detection for its built-in pattern studies. Record that selection when comparing built-in labels with a custom detector.
Recalculate a Tasuki gap in both directions
The following hypothetical examples use tick t = 0.01 and prior mean body = 2, making the long-body threshold 3. Assume preceding closes 97, 98, 99 for upside and 113, 112, 111 for downside. Tuples are (open, high, low, close). These are arithmetic examples, not observed trades.
- Both pass the stated body-based research variant. Their overlapping shadows deliberately show why a separate full-range gap indicator can report no gap.
- Upside: change only C3 to 104.50 and the closing fill becomes 75%. Downside: change only C3 to 105.50 and the closing fill also becomes 75%. Both remain partial fills with valid OHLC.
- Upside: setting L3 = 103.50 while keeping C3 = 105 preserves the close-based candidate but creates an intrabar full fill. A stricter no-wick-fill variant would reject it. The downside mirror changes H3 to 106.50.
| Measurement | Upside example | Downside example |
|---|
| Candle 1 | (100, 105, 99, 104) | (110, 111, 105, 106) |
| Candle 2 | (106, 109.50, 103.50, 109) | (104, 106.50, 100.50, 101) |
| Candle 3 | (108, 109, 104.50, 105) | (102, 105.50, 101, 105) |
| Bodies 1, 2 and 3 | 4, 3, 3 | 4, 3, 3 |
| Body gap | 106 - 104 = 2 | 106 - 104 = 2 |
| Third open | 106 < 108 < 109 | 101 < 102 < 104 |
| Third close | 104 < 105 < 106 | 104 < 105 < 106 |
| Closing fill | (106 - 105) / 2 = 50% | (105 - 104) / 2 = 50% |
| Gap remaining at close | 105 - 104 = 1 | 106 - 105 = 1 |
| Full-range gap? | No: L2 = 103.50 is below H1 = 105 | No: H2 = 106.50 is above L1 = 105 |
Reject boundary touches and distinguish full-gap patterns
A close at either gap endpoint fails the strict inside rule. The near edge means no closing penetration; the far edge means complete closing fill. The following boundary tests use the same gap from 104 to 106 and tick 0.01. When changing a close, extend its high or low if necessary so the OHLC remains valid.
- Passing this table proves only the gap-close condition. Trend, colors, body size and the third open must still pass. An O3 exactly at an endpoint of body 2 fails the opening test.
- Gap three methods requires the third close to travel through the gap and finish inside body 1 in TA-Lib. Merely touching the far gap edge fails Tasuki but does not automatically complete gap three methods.
- Piercing is a two-candle bullish reversal candidate after a decline. TradingView requires the second candle to open below the first low and close above the first body midpoint. Tasuki uses three candles, two same-direction bodies and a remaining gap; it has no piercing midpoint-recovery requirement.
| Third close | Upside gap test | Downside gap test |
|---|
| 104.00 | Reject: 100% filled | Reject: 0% filled |
| 104.01 | Pass gap test: 99.5% filled | Pass gap test: 0.5% filled |
| 105.99 | Pass gap test: 0.5% filled | Pass gap test: 99.5% filled |
| 106.00 | Reject: 0% filled | Reject: 100% filled |
| G = 0 | Reject before dividing by G | Reject before dividing by G |
Record confirmation and gap failure separately
One possible follow-up rule watches the next three completed candles. Confirm upside on a close above H2, or downside on a close below L2. Invalidate the pending gap hypothesis on an upside close at or below C1, or a downside close at or above C1. If neither event occurs, expire the candidate after three bars. This is a research rule, not part of the pattern name.
- Freeze the original levels and end the pending state at the first qualifying close. A wick beyond H2 or L2 does not meet this closing confirmation rule.
- Keep the original three-candle match if its later outcome fails. If confirmation occurs first and the gap fills later, record a confirmed candidate followed by failure, with both timestamps. Do not relabel the original candle history.
- An unfinished observation window is incomplete, not expired. None of these labels specifies an entry fill, stop order, position size or expected return.
| Event using the examples | Upside | Downside |
|---|
| First confirming close on the tick grid | 109.51 | 100.49 |
| Threshold touch, still pending | 109.50 | 100.50 |
| Gap invalidation boundary, inclusive | 104.00 or below | 106.00 or above |
| Three bars without either event | Expired | Expired |
Know when an intraday chart cannot form the gap
If each new bar opens exactly at the preceding close, then O2 = C1 and the same-direction body gap is zero. That pair cannot form Tasuki under these rules. Frequent trading or a continuous session can leave few qualifying openings; the pattern name is not a reason to accept a no-gap substitute.
- Check the actual OHLC rather than declaring an entire asset class ineligible. Session breaks, price jumps and sparse trading can produce discontinuities; a 24-hour label alone does not prove every adjacent open equals the prior close.
- Keep symbol, exchange, timeframe, regular or extended session, and adjustment settings fixed. Missing bars or data-feed interruptions need investigation before a visual gap is treated as a market event.
- Use ordinary candles for this price specification. TradingView documents Heikin-Ashi OHLC as synthetic. A gap between synthetic bodies does not establish the same gap in traded prices.
Build a detector from the rule sheet, then review the hits
Give Pine Script AI Coding Agent the body-gap definition, tick boundaries, chosen trend filter and follow-up window to draft a detector. Request separate candidate, confirmed, invalidated and expired markers. Compare the generated source and its output with the accepted and rejected numerical cases before adding strategy orders.
- Ask explicitly for syntax checking, then verify detection behavior against OHLC. Compilation cannot prove that the intended pattern or its timing was implemented correctly.
- Use AI Chart Analysis to review screenshots of matches and failures for visible candle structure and trend context. Keep numerical OHLC beside each image: screenshots cannot reliably resolve a one-tick boundary or supply off-screen reference history.
- Save the rule version, candle timestamps, gap width, fill fraction and later outcome. Only then define entry, exit, fees and slippage for a separate strategy test. This page does not report a completed detector backtest.