Candlestick Patterns vs Baseline: Forward Returns, 95% CI

462
WHAT IT DOES
Candlestick Patterns vs Baseline detects six classic candlestick patterns and measures what price did over the next N bars after each one. It measures the same thing after every bar on the chart and compares the two. For each pattern the table shows the number of occurrences, the hit rate, the mean forward return, the difference against the baseline with a 95% confidence interval, and a plain verdict.

WHAT IS ORIGINAL HERE
Marking a pattern says nothing about how often it is followed by the move it suggests. This script adds the missing reference point: every confirmed bar contributes one forward return to a baseline. Each pattern's returns are signed by its direction, so a bearish pattern is scored on the short side, and are compared with the baseline signed the same way. The comparison is a difference of means whose standard error combines the variance of both samples (Welch style), shown as a 95% interval. The verdict calls a difference only when the whole interval sits on one side of zero.
Forward returns use no look-ahead: on each confirmed bar the script looks back N bars at the signal and measures to the current close. The entry can be the next bar's open or the signal bar's close.

PATTERN DEFINITIONS
Anatomy: body = |close - open|, range = high - low, upper wick = high - max(open, close), lower wick = min(open, close) - low.
Prior trend (optional): bullish patterns need the close before the pattern to be below the close "trend length" bars earlier, bearish ones above it. Three-bar patterns shift the test two bars back.
Bullish engulfing (long): previous bar down, current bar up, open at or below the previous close, close at or above the previous open, body larger than the previous body, after a decline.
Bearish engulfing (short): the mirror image, after a rise.
Hammer (long): non-zero body, lower wick at least 2 times the body, upper wick at most 25% of the range, after a decline.
Shooting star (short): the mirror image, after a rise.
Morning star (long): first bar down with a body of at least 50% of its range, middle bar with a body of at most 30% of its range, last bar up and closing above the midpoint of the first bar's body, after a decline.
Evening star (short): the mirror image, after a rise.
Patterns are evaluated on the closed bar. Thresholds are fixed, not tuned.

HOW TO USE IT
1. Add it to a chart with as much history as your plan loads. Sample size drives everything.
2. Set the horizon, the number of bars between the signal and the exit.
3. Choose the entry: the next bar's open or the signal bar's close.
4. Keep the prior trend filter on to score reversals, or turn it off to score the candle shape alone.
5. Set the minimum number of occurrences before a verdict is shown.
Every setting you try is another comparison, so count them.

HOW TO READ THE TABLE
n: signals that had a full forward window.
Hit rate (base): share of signals with a direction-signed return above zero; in brackets, the same share over all bars.
Mean fwd % (base): mean direction-signed forward return in percent, and in brackets the mean over all bars signed the same way. For a bearish pattern a positive number means price fell.
Diff vs base, 95% CI: pattern mean minus baseline mean, in percentage points, with the 95% interval (1.96 standard errors) in square brackets.
Verdict: "beats baseline" (green) or "worse than baseline" (red) when the interval excludes zero, "no evidence" when it includes zero, "too few" below the minimum number of occurrences (30 by default).

LIMITATIONS
Overlapping windows: above a horizon of 1, consecutive windows share bars and patterns cluster in time, so returns are not independent and the interval is too narrow.
The baseline is every bar, not only bars after the same prior trend. With the filter on, a difference may come from the trend context, not the candle shape.
Six patterns and many settings mean many comparisons; about 1 interval in 20 excludes zero by chance.
The interval is a normal approximation, weak with fat tails or small samples.
Only bars loaded on the chart count, so history depth, symbol and timeframe change n.
Returns include no fees, spreads or slippage. The next open is a chart price, not a guaranteed fill.
The script reports counts and differences, not a trading rule, and it is not financial advice.

The chart shows SPY on the daily timeframe with the default settings, over all the history the chart loads (a baseline of about 8,500 bars). The table is in the bottom right, and the triangles mark the pattern signals.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.