Choose which stick sandwich definition you are testing
The thinkorswim reference requires a bearish first candle in a downtrend, a bullish second candle opening above the first close, and a bearish third candle closing at the first close. TA-Lib uses a stricter middle-candle location: its low must exceed the first close. TA-Lib permits a configurable equality tolerance and does not test the preceding downtrend.
- A middle candle can open above the first close and still dip below it. That passes the stated opening comparison but fails the stricter low comparison.
- The specification below uses the stricter location, an explicit prior-decline filter and a tick-based equality rule. It is a custom research definition, not a claim to reproduce TradingView, thinkorswim or TA-Lib defaults.
- Candle color is determined by close versus open. A hollow or green chart display alone is insufficient if the chart uses a different color convention.
Define the OHLC and close-tolerance rules
Number the three completed ordinary candles 1, 2 and 3, oldest first. O, H, L and C mean open, high, low and close. Let q be the symbol minimum tick and N be a nonnegative integer tolerance in ticks. This example sets N = 2; the allowed price difference is T = N × q.
- TradingView exposes the chart dataset minimum tick as syminfo.mintick. It is a price increment, not a pip or the cash value of a futures tick. Read it for the actual exchange-qualified symbol.
- For tick-aligned OHLC, compare the integer tick coordinates of the two closes. This prevents decimal floating-point noise from rejecting an exact boundary. Verify alignment first; do not silently round malformed or differently adjusted data into a match.
- Reject missing history, a nonpositive tick, invalid OHLC ranges or open/close values outside their high-low range. This definition adds no body-length ratio, shadow-length limit or third-candle opening gap.
- A two-tick rule has no universal market significance. On a coarse-price grid it may be wide relative to the candle body. Record the tolerance and inspect that scale before testing; changing it changes the population of candidates.
| Test | Rule |
|---|
| Prior decline | The three closes immediately before candle 1 decrease strictly |
| Outer bodies | C1 < O1 and C3 < O3 |
| Middle body | C2 > O2; a doji is excluded |
| Middle location | L2 > C1; equality fails |
| Close match | abs(C3 - C1) <= N × q; equality at the boundary passes |
| Strict mode | N = 0 requires C3 = C1 |
Two ticks mean different price distances
These hypothetical examples isolate the close-match test. Assume valid tick-aligned prices and that every other pattern rule passes. Price units are arbitrary; these rows are not quotes for particular instruments.
- The tolerance is symmetric. With q = 0.25, closes from 99.50 through 100.50 qualify in quarter-point steps; 99.25 fails. With N = 0, only 100.00 qualifies.
- Using a fixed 0.02 allowance on all three grids changes the rule: it is two ticks on the first, less than one tick on the second, and 200 ticks on the third. Decimal places alone do not define comparable tolerance.
| Minimum tick q | First close C1 | T at N = 2 | At the included upper edge | One tick beyond |
|---|
| 0.01 | 100.00 | 0.02 | C3 = 100.02: pass | C3 = 100.03: fail |
| 0.25 | 100.00 | 0.50 | C3 = 100.50: pass | C3 = 100.75: fail |
| 0.0001 | 1.1000 | 0.0002 | C3 = 1.1002: pass | C3 = 1.1003: fail |
Walk through a candidate and rejected near matches
Assume q = 0.25, N = 2 and prior closes of 105, 104.50 and 104 in chronological order. The hypothetical candles below form a candidate at candle 3 close. The matching distance is abs(100.25 - 100) = 0.25, or one tick, within the two-tick limit of 0.50.
- The middle candle has a positive 2.00 body and L2 = 100.25 > C1 = 100. Changing only L2 to 100 makes the strict location test fail, even though its open remains above C1.
- Changing only C3 to 100.50 still passes; 100.75 fails. Changing only C2 to 100.50 creates a doji and fails the middle-body rule.
- Changing the preceding closes to 104, 104 and 103.50 fails the strict decline filter. The three-candle shape can still exist without qualifying as this reversal candidate.
- The first and third lows differ, and both are below their closes. The close match therefore says nothing about an exact match of the lower extremes.
| Candle | Open | High | Low | Close |
|---|
| 1: bearish | 103.00 | 103.25 | 99.75 | 100.00 |
| 2: bullish | 100.50 | 102.75 | 100.25 | 102.50 |
| 3: bearish | 103.00 | 103.50 | 99.50 | 100.25 |
Separate confirmation, expiry and failed support
For a declared follow-through test, freeze U = max(H1, H2, H3) and D = min(L1, L2, L3). Watch the next three completed bars. The first close above U confirms the upward hypothesis; the first close below D invalidates it. If neither occurs, expire the pending candidate after the third close. These thresholds and the three-bar window are example research choices.
- Keep the original candidate time separate from the confirmation time. Later information cannot justify placing a confirmed historical signal on candle 1 or candle 3.
- This is a close-based event test, not an intrabar stop system. A bar may trade below D and recover before closing; that excursion does not invalidate this particular rule. A different rule using lows will produce different results.
- A confirmation does not establish a profitable trade. Entry timing, position size, costs, stop execution and exit rules remain separate; a gap can prevent a fill at the intended price.
| Independent path after the example: U = 103.50, D = 99.50 | Outcome |
|---|
| A later high is 103.75, but its close is 103.25 | Pending: a wick above U is insufficient |
| A later close equals 103.50 or 99.50 | Pending: the boundary tests are strict |
| The next close is 103.75 | Confirmed at that close |
| The next close is 99.25 | Invalidated; the matched closes did not hold |
| The next three closes are 101.00, 102.00 and 103.50 | Expired without confirmation |
| A close of 103.75 confirms, then price later closes at 99.25 | Record later failure without deleting the earlier confirmation |
Stick sandwich versus tweezer bottom
TradingView describes a tweezer bottom as two candles with nearly identical lows, with bearish then bullish bodies after a decline. Stick sandwich uses three candles and matches the first and third closes. Substituting lows for closes changes which pattern is being measured.
| Feature | Stick sandwich | Tweezer bottom |
|---|
| Number of candles | Three | Two |
| Body sequence | Bearish, bullish, bearish | Bearish, bullish |
| Matched price | First and third close | First and second low |
| What the match establishes | A measured close-level relationship | A measured low-level relationship |
Review the detector before testing a strategy
Give Pine Script AI Coding Agent the OHLC rules, tick tolerance, prior-close filter and follow-through window to draft a detector. Request separate candidate, confirmed, invalidated and expired events, evaluated on completed bars. Review the generated source, request syntax checking and compile it in TradingView before comparing its output with these cases.
- Record the symbol, timeframe, session, adjustment settings, timestamps and raw OHLC values for both matches and rejected near matches. Keep ordinary candles and the price feed consistent across the review.
- Use AI Chart Analysis to review a screenshot of the visible trend and candle sequence. Compare a hit with a failure sample. Retain the numeric OHLC alongside the image: pixels cannot certify a one-tick difference or recover off-screen history.
- Only after the detector matches the declared rules should you specify strategy orders and test outcomes. Compilation, image agreement and pattern counts do not establish a trading advantage.