feat: TA-Lib candlestick patterns — matching-low/lines/three-methods (part 7 of 9) (#139)

Adds five TA-Lib candlestick patterns, all `Input = Candle`, `Output = f64`
(`+1.0` bullish / `-1.0` bearish / `0.0` no pattern), wired across core,
Python/Node/WASM bindings, fuzz, and tests.

- **Matching Low** (`CDLMATCHINGLOW`) — 2-bar bullish reversal: two black candles in a decline share the same close, signalling selling pressure is exhausting; bullish +1.
- **Long Line** (`CDLLONGLINE`) — a candle whose range beats a rolling average of recent ranges with a body-dominated range; bullish +1 (white) / bearish -1 (black).
- **Short Line** (`CDLSHORTLINE`) — a compact candle whose range falls below the rolling average with a body-dominated range; bullish +1 (white) / bearish -1 (black).
- **Rising Three Methods** (`CDLRISEFALL3METHODS`) — 5-bar bullish continuation: a long white candle, three small bars holding within its range, then a white breakout to new highs; bullish +1.
- **Falling Three Methods** (`CDLRISEFALL3METHODS`) — the bearish mirror: a long black candle, three small bars within its range, then a black breakdown to new lows; bearish -1.

Counter 274 → 279 (mod-count == lib counted block; FAMILIES total 269 → 274).

Stacked on #138 (part 6 of 9); base retargets to `main` as the chain merges.
This commit is contained in:
kingchenc
2026-06-02 17:16:15 +02:00
committed by GitHub
parent 04ae145126
commit c2c85c7ecf
19 changed files with 1285 additions and 41 deletions
+10
View File
@@ -270,6 +270,11 @@ from ._wickra import (
KickingByLength,
LadderBottom,
MatHold,
MatchingLow,
LongLine,
ShortLine,
RisingThreeMethods,
FallingThreeMethods,
# Microstructure: order book
OrderBookImbalanceTop1,
OrderBookImbalanceTopN,
@@ -567,6 +572,11 @@ __all__ = [
"KickingByLength",
"LadderBottom",
"MatHold",
"MatchingLow",
"LongLine",
"ShortLine",
"RisingThreeMethods",
"FallingThreeMethods",
# Microstructure: order book
"OrderBookImbalanceTop1",
"OrderBookImbalanceTopN",
+18
View File
@@ -11662,6 +11662,19 @@ candle_pattern_no_param!(PyKicking, wc::Kicking, "Kicking");
candle_pattern_no_param!(PyKickingByLength, wc::KickingByLength, "KickingByLength");
candle_pattern_no_param!(PyLadderBottom, wc::LadderBottom, "LadderBottom");
candle_pattern_no_param!(PyMatHold, wc::MatHold, "MatHold");
candle_pattern_no_param!(PyMatchingLow, wc::MatchingLow, "MatchingLow");
candle_pattern_no_param!(PyLongLine, wc::LongLine, "LongLine");
candle_pattern_no_param!(PyShortLine, wc::ShortLine, "ShortLine");
candle_pattern_no_param!(
PyRisingThreeMethods,
wc::RisingThreeMethods,
"RisingThreeMethods"
);
candle_pattern_no_param!(
PyFallingThreeMethods,
wc::FallingThreeMethods,
"FallingThreeMethods"
);
// ============================== Microstructure: Order Book ==============================
//
// Order-book indicators consume a depth snapshot rather than OHLCV. Streaming
@@ -14188,6 +14201,11 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<PyKickingByLength>()?;
m.add_class::<PyLadderBottom>()?;
m.add_class::<PyMatHold>()?;
m.add_class::<PyMatchingLow>()?;
m.add_class::<PyLongLine>()?;
m.add_class::<PyShortLine>()?;
m.add_class::<PyRisingThreeMethods>()?;
m.add_class::<PyFallingThreeMethods>()?;
// Microstructure: order book.
m.add_class::<PyOrderBookImbalanceTop1>()?;
m.add_class::<PyOrderBookImbalanceTopN>()?;
@@ -643,6 +643,26 @@ CANDLE_SCALAR = {
lambda: ta.MatHold(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"MatchingLow": (
lambda: ta.MatchingLow(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"LongLine": (
lambda: ta.LongLine(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"ShortLine": (
lambda: ta.ShortLine(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"RisingThreeMethods": (
lambda: ta.RisingThreeMethods(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
"FallingThreeMethods": (
lambda: ta.FallingThreeMethods(),
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
),
}
@@ -1891,6 +1911,46 @@ def test_mat_hold_reference():
assert t.update((15.0, 15.1, 14.4, 14.5, 1.0, 3)) == pytest.approx(0.0)
assert t.update((14.5, 17.1, 14.4, 17.0, 1.0, 4)) == pytest.approx(1.0)
def test_matching_low_reference():
t = ta.MatchingLow()
assert t.update((15.0, 15.1, 9.9, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((13.0, 13.1, 9.9, 10.0, 1.0, 1)) == pytest.approx(1.0)
def test_long_line_reference():
t = ta.LongLine()
# Five quiet bars fill the rolling range average, then a wide solid white bar.
for ts in range(5):
assert t.update((10.0, 10.5, 9.5, 10.2, 1.0, ts)) == pytest.approx(0.0)
assert t.update((10.0, 13.0, 9.9, 12.9, 1.0, 5)) == pytest.approx(1.0)
def test_short_line_reference():
t = ta.ShortLine()
# Five wide bars fill the rolling range average, then a compact solid white bar.
for ts in range(5):
assert t.update((10.0, 13.0, 9.5, 12.9, 1.0, ts)) == pytest.approx(0.0)
assert t.update((10.0, 11.0, 9.9, 10.9, 1.0, 5)) == pytest.approx(1.0)
def test_rising_three_methods_reference():
t = ta.RisingThreeMethods()
assert t.update((10.0, 15.1, 9.9, 15.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((14.0, 14.1, 12.9, 13.0, 1.0, 1)) == pytest.approx(0.0)
assert t.update((13.5, 13.6, 12.4, 12.5, 1.0, 2)) == pytest.approx(0.0)
assert t.update((13.0, 13.1, 11.9, 12.0, 1.0, 3)) == pytest.approx(0.0)
assert t.update((12.5, 16.1, 12.4, 16.0, 1.0, 4)) == pytest.approx(1.0)
def test_falling_three_methods_reference():
t = ta.FallingThreeMethods()
assert t.update((15.0, 15.1, 9.9, 10.0, 1.0, 0)) == pytest.approx(0.0)
assert t.update((11.0, 12.1, 10.9, 12.0, 1.0, 1)) == pytest.approx(0.0)
assert t.update((11.5, 12.6, 11.4, 12.5, 1.0, 2)) == pytest.approx(0.0)
assert t.update((12.0, 13.1, 11.9, 13.0, 1.0, 3)) == pytest.approx(0.0)
assert t.update((12.5, 12.6, 8.9, 9.0, 1.0, 4)) == pytest.approx(-1.0)
# --- Lifecycle ------------------------------------------------------------