feat: add DeMark deepening (B12, 7 indicators) (#204)
B12 of the family-deepening roadmap — seven Tom DeMark indicators (467 -> 474).
**Candle -> +1/0 qualifier patterns (candlestick macro bindings):**
- **TD Camouflage** — hidden intrabar strength/weakness against the prior close.
- **TD Clop** — two-bar open/close engulfing reversal.
- **TD Clopwin** — the inside-body cousin of TD Clop (compression bar).
- **TD Propulsion** — continuation thrust closing beyond the prior extreme.
- **TD Trap** — inside ("trap") bar followed by a range breakout.
**Hand-bound:**
- **TD D-Wave** — streaming Elliott-style 1-5 / A-C swing-wave counter (candle -> f64, `strength` param).
- **TD Moving Averages** — ST1/ST2 median-price trend ribbon (candle -> struct {st1, st2}).
All seven join the existing **DeMark** family. Patterns follow the house-style
+1/0 candle-pattern convention (neutral 0.0 during warmup). Public binding names
use the family-consistent `TD...` casing.
Wiring complete across core, Python, Node, WASM, fuzz, tests, README + docs
counter (474) and CHANGELOG. Verified: core 3874 + doc 427, clippy clean,
node 549, python 903.
This commit is contained in:
@@ -378,6 +378,12 @@ const candleScalar = {
|
||||
BetterVolume: { make: () => new wickra.BetterVolume(14), step: (ind, i) => ind.update(high[i], low[i], close[i], volume[i]), batch: (ind) => ind.batch(high, low, close, volume) },
|
||||
ADAPTIVECCI: { make: () => new wickra.ADAPTIVECCI(20), step: (ind, i) => ind.update(high[i], low[i], close[i]), batch: (ind) => ind.batch(high, low, close) },
|
||||
PivotReversal: { make: () => new wickra.PivotReversal(1, 1), step: (ind, i) => ind.update(high[i], low[i], close[i]), batch: (ind) => ind.batch(high, low, close) },
|
||||
TDCamouflage: { make: () => new wickra.TDCamouflage(), step: (ind, i) => ind.update(open[i], high[i], low[i], close[i]), batch: (ind) => ind.batch(open, high, low, close) },
|
||||
TDClop: { make: () => new wickra.TDClop(), step: (ind, i) => ind.update(open[i], high[i], low[i], close[i]), batch: (ind) => ind.batch(open, high, low, close) },
|
||||
TDClopwin: { make: () => new wickra.TDClopwin(), step: (ind, i) => ind.update(open[i], high[i], low[i], close[i]), batch: (ind) => ind.batch(open, high, low, close) },
|
||||
TDPropulsion: { make: () => new wickra.TDPropulsion(), step: (ind, i) => ind.update(open[i], high[i], low[i], close[i]), batch: (ind) => ind.batch(open, high, low, close) },
|
||||
TDTrap: { make: () => new wickra.TDTrap(), step: (ind, i) => ind.update(open[i], high[i], low[i], close[i]), batch: (ind) => ind.batch(open, high, low, close) },
|
||||
TDDWave: { make: () => new wickra.TDDWave(2), step: (ind, i) => ind.update(high[i], low[i], close[i]), batch: (ind) => ind.batch(high, low, close) },
|
||||
};
|
||||
|
||||
for (const [name, d] of Object.entries(candleScalar)) {
|
||||
@@ -479,6 +485,7 @@ const multi = {
|
||||
MurreyMathLines: { make: () => new wickra.MurreyMathLines(4), fields: ['mm8_8', 'mm7_8', 'mm6_8', 'mm5_8', 'mm4_8', 'mm3_8', 'mm2_8', 'mm1_8', 'mm0_8'], step: (ind, i) => ind.update(high[i], low[i]), batch: (ind) => ind.batch(high, low) },
|
||||
AndrewsPitchfork: { make: () => new wickra.AndrewsPitchfork(2), fields: ['median', 'upper', 'lower'], step: (ind, i) => ind.update(high[i], low[i]), batch: (ind) => ind.batch(high, low) },
|
||||
VolumeWeightedSr: { make: () => new wickra.VolumeWeightedSr(3), fields: ['support', 'resistance'], step: (ind, i) => ind.update(high[i], low[i], volume[i]), batch: (ind) => ind.batch(high, low, volume) },
|
||||
TDMovingAverage: { make: () => new wickra.TDMovingAverage(5, 13), fields: ['st1', 'st2'], step: (ind, i) => ind.update(high[i], low[i]), batch: (ind) => ind.batch(high, low) },
|
||||
};
|
||||
|
||||
for (const [name, d] of Object.entries(multi)) {
|
||||
|
||||
Vendored
+67
@@ -342,6 +342,10 @@ export interface TdSequentialValue {
|
||||
countdown: number
|
||||
direction: number
|
||||
}
|
||||
export interface TdMovingAverageValue {
|
||||
st1: number
|
||||
st2: number
|
||||
}
|
||||
/** TD Lines output pair: latest TDST resistance / support (NaN if unset). */
|
||||
export interface TdLinesValue {
|
||||
resistance: number
|
||||
@@ -3159,6 +3163,24 @@ export declare class TDCombo {
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdDWaveNode = TDDWave
|
||||
export declare class TDDWave {
|
||||
constructor(strength: number)
|
||||
update(high: number, low: number, close: number): number | null
|
||||
batch(high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdMovingAverageNode = TDMovingAverage
|
||||
export declare class TDMovingAverage {
|
||||
constructor(periodSt1: number, periodSt2: number)
|
||||
update(high: number, low: number): TdMovingAverageValue | null
|
||||
batch(high: Array<number>, low: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdCountdownNode = TDCountdown
|
||||
export declare class TDCountdown {
|
||||
constructor(setupLookback: number, setupTarget: number, countdownLookback: number, countdownTarget: number)
|
||||
@@ -4072,6 +4094,51 @@ export declare class ThreeDrives {
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdCamouflageNode = TDCamouflage
|
||||
export declare class TDCamouflage {
|
||||
constructor()
|
||||
update(open: number, high: number, low: number, close: number): number | null
|
||||
batch(open: Array<number>, high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdClopNode = TDClop
|
||||
export declare class TDClop {
|
||||
constructor()
|
||||
update(open: number, high: number, low: number, close: number): number | null
|
||||
batch(open: Array<number>, high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdClopwinNode = TDClopwin
|
||||
export declare class TDClopwin {
|
||||
constructor()
|
||||
update(open: number, high: number, low: number, close: number): number | null
|
||||
batch(open: Array<number>, high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdPropulsionNode = TDPropulsion
|
||||
export declare class TDPropulsion {
|
||||
constructor()
|
||||
update(open: number, high: number, low: number, close: number): number | null
|
||||
batch(open: Array<number>, high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type TdTrapNode = TDTrap
|
||||
export declare class TDTrap {
|
||||
constructor()
|
||||
update(open: number, high: number, low: number, close: number): number | null
|
||||
batch(open: Array<number>, high: Array<number>, low: Array<number>, close: Array<number>): Array<number>
|
||||
reset(): void
|
||||
isReady(): boolean
|
||||
warmupPeriod(): number
|
||||
}
|
||||
export type OrderBookImbalanceTop1Node = OrderBookImbalanceTop1
|
||||
export declare class OrderBookImbalanceTop1 {
|
||||
constructor()
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -11100,6 +11100,124 @@ impl TdComboNode {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD D-Wave ==============================
|
||||
|
||||
#[napi(js_name = "TDDWave")]
|
||||
pub struct TdDWaveNode {
|
||||
inner: wc::TdDWave,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
impl TdDWaveNode {
|
||||
#[napi(constructor)]
|
||||
pub fn new(strength: u32) -> napi::Result<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::TdDWave::new(strength as usize).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
#[napi]
|
||||
pub fn update(&mut self, high: f64, low: f64, close: f64) -> napi::Result<Option<f64>> {
|
||||
Ok(self.inner.update(cnd(high, low, close, 0.0)?))
|
||||
}
|
||||
#[napi]
|
||||
pub fn batch(
|
||||
&mut self,
|
||||
high: Vec<f64>,
|
||||
low: Vec<f64>,
|
||||
close: Vec<f64>,
|
||||
) -> napi::Result<Vec<f64>> {
|
||||
if high.len() != low.len() || low.len() != close.len() {
|
||||
return Err(NapiError::from_reason(
|
||||
"high, low, close must be equal length".to_string(),
|
||||
));
|
||||
}
|
||||
let mut out = Vec::with_capacity(high.len());
|
||||
for i in 0..high.len() {
|
||||
out.push(
|
||||
self.inner
|
||||
.update(cnd(high[i], low[i], close[i], 0.0)?)
|
||||
.unwrap_or(f64::NAN),
|
||||
);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
#[napi]
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[napi(js_name = "isReady")]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[napi(js_name = "warmupPeriod")]
|
||||
pub fn warmup_period(&self) -> u32 {
|
||||
self.inner.warmup_period() as u32
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD Moving Averages ==============================
|
||||
|
||||
#[napi(object)]
|
||||
pub struct TdMovingAverageValue {
|
||||
pub st1: f64,
|
||||
pub st2: f64,
|
||||
}
|
||||
|
||||
#[napi(js_name = "TDMovingAverage")]
|
||||
pub struct TdMovingAverageNode {
|
||||
inner: wc::TdMovingAverage,
|
||||
}
|
||||
|
||||
#[napi]
|
||||
impl TdMovingAverageNode {
|
||||
#[napi(constructor)]
|
||||
pub fn new(period_st1: u32, period_st2: u32) -> napi::Result<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::TdMovingAverage::new(period_st1 as usize, period_st2 as usize)
|
||||
.map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
#[napi]
|
||||
pub fn update(&mut self, high: f64, low: f64) -> napi::Result<Option<TdMovingAverageValue>> {
|
||||
Ok(self
|
||||
.inner
|
||||
.update(cnd(high, low, low, 0.0)?)
|
||||
.map(|o| TdMovingAverageValue {
|
||||
st1: o.st1,
|
||||
st2: o.st2,
|
||||
}))
|
||||
}
|
||||
#[napi]
|
||||
pub fn batch(&mut self, high: Vec<f64>, low: Vec<f64>) -> napi::Result<Vec<f64>> {
|
||||
if high.len() != low.len() {
|
||||
return Err(NapiError::from_reason(
|
||||
"high, low must be equal length".to_string(),
|
||||
));
|
||||
}
|
||||
let n = high.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
if let Some(o) = self.inner.update(cnd(high[i], low[i], low[i], 0.0)?) {
|
||||
out[i * 2] = o.st1;
|
||||
out[i * 2 + 1] = o.st2;
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
#[napi]
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[napi(js_name = "isReady")]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[napi(js_name = "warmupPeriod")]
|
||||
pub fn warmup_period(&self) -> u32 {
|
||||
self.inner.warmup_period() as u32
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD Countdown ==============================
|
||||
|
||||
#[napi(js_name = "TDCountdown")]
|
||||
@@ -12807,6 +12925,11 @@ node_candle_pattern!(CrabNode, wc::Crab, "Crab");
|
||||
node_candle_pattern!(SharkNode, wc::Shark, "Shark");
|
||||
node_candle_pattern!(CypherNode, wc::Cypher, "Cypher");
|
||||
node_candle_pattern!(ThreeDrivesNode, wc::ThreeDrives, "ThreeDrives");
|
||||
node_candle_pattern!(TdCamouflageNode, wc::TdCamouflage, "TDCamouflage");
|
||||
node_candle_pattern!(TdClopNode, wc::TdClop, "TDClop");
|
||||
node_candle_pattern!(TdClopwinNode, wc::TdClopwin, "TDClopwin");
|
||||
node_candle_pattern!(TdPropulsionNode, wc::TdPropulsion, "TDPropulsion");
|
||||
node_candle_pattern!(TdTrapNode, wc::TdTrap, "TDTrap");
|
||||
|
||||
// ============================== Microstructure: Order Book ==============================
|
||||
//
|
||||
|
||||
@@ -322,6 +322,13 @@ from ._wickra import (
|
||||
WilliamsFractals,
|
||||
ZigZag,
|
||||
# DeMark
|
||||
TDMovingAverage,
|
||||
TDDWave,
|
||||
TDTrap,
|
||||
TDPropulsion,
|
||||
TDClopwin,
|
||||
TDClop,
|
||||
TDCamouflage,
|
||||
TDSetup,
|
||||
TDSequential,
|
||||
TDDeMarker,
|
||||
@@ -819,6 +826,13 @@ __all__ = [
|
||||
"WilliamsFractals",
|
||||
"ZigZag",
|
||||
# DeMark
|
||||
"TDMovingAverage",
|
||||
"TDDWave",
|
||||
"TDTrap",
|
||||
"TDPropulsion",
|
||||
"TDClopwin",
|
||||
"TDClop",
|
||||
"TDCamouflage",
|
||||
"TDSetup",
|
||||
"TDSequential",
|
||||
"TDDeMarker",
|
||||
|
||||
@@ -14086,6 +14086,131 @@ impl PyTdCombo {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD D-Wave ==============================
|
||||
|
||||
#[pyclass(name = "TDDWave", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyTdDWave {
|
||||
inner: wc::TdDWave,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyTdDWave {
|
||||
#[new]
|
||||
#[pyo3(signature = (strength=2))]
|
||||
fn new(strength: usize) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::TdDWave::new(strength).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<f64>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c))
|
||||
}
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: PyReadonlyArray1<'py, f64>,
|
||||
) -> PyResult<Bound<'py, PyArray1<f64>>> {
|
||||
let h = high
|
||||
.as_slice()
|
||||
.map_err(|_| PyValueError::new_err(NON_CONTIGUOUS))?;
|
||||
let l = low
|
||||
.as_slice()
|
||||
.map_err(|_| PyValueError::new_err(NON_CONTIGUOUS))?;
|
||||
let c = close
|
||||
.as_slice()
|
||||
.map_err(|_| PyValueError::new_err(NON_CONTIGUOUS))?;
|
||||
if h.len() != l.len() || l.len() != c.len() {
|
||||
return Err(PyValueError::new_err(
|
||||
"high, low, close must be equal length",
|
||||
));
|
||||
}
|
||||
let mut out = Vec::with_capacity(h.len());
|
||||
for i in 0..h.len() {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
out.push(self.inner.update(candle).unwrap_or(f64::NAN));
|
||||
}
|
||||
Ok(out.into_pyarray(py))
|
||||
}
|
||||
fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD Moving Averages ==============================
|
||||
|
||||
#[pyclass(
|
||||
name = "TDMovingAverage",
|
||||
module = "wickra._wickra",
|
||||
skip_from_py_object
|
||||
)]
|
||||
#[derive(Clone)]
|
||||
struct PyTdMovingAverage {
|
||||
inner: wc::TdMovingAverage,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyTdMovingAverage {
|
||||
#[new]
|
||||
#[pyo3(signature = (period_st1=5, period_st2=13))]
|
||||
fn new(period_st1: usize, period_st2: usize) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::TdMovingAverage::new(period_st1, period_st2).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
/// Returns `(st1, st2)`.
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.st1, o.st2)))
|
||||
}
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
) -> PyResult<Bound<'py, PyArray2<f64>>> {
|
||||
let h = high
|
||||
.as_slice()
|
||||
.map_err(|_| PyValueError::new_err(NON_CONTIGUOUS))?;
|
||||
let l = low
|
||||
.as_slice()
|
||||
.map_err(|_| PyValueError::new_err(NON_CONTIGUOUS))?;
|
||||
if h.len() != l.len() {
|
||||
return Err(PyValueError::new_err("high, low must be equal length"));
|
||||
}
|
||||
let n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(l[i], h[i], l[i], l[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.st1;
|
||||
out[i * 2 + 1] = o.st2;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TD Countdown ==============================
|
||||
|
||||
#[pyclass(name = "TDCountdown", module = "wickra._wickra", skip_from_py_object)]
|
||||
@@ -17703,6 +17828,11 @@ candle_pattern_no_param!(PyCrab, wc::Crab, "Crab");
|
||||
candle_pattern_no_param!(PyShark, wc::Shark, "Shark");
|
||||
candle_pattern_no_param!(PyCypher, wc::Cypher, "Cypher");
|
||||
candle_pattern_no_param!(PyThreeDrives, wc::ThreeDrives, "ThreeDrives");
|
||||
candle_pattern_no_param!(PyTdCamouflage, wc::TdCamouflage, "TDCamouflage");
|
||||
candle_pattern_no_param!(PyTdClop, wc::TdClop, "TDClop");
|
||||
candle_pattern_no_param!(PyTdClopwin, wc::TdClopwin, "TDClopwin");
|
||||
candle_pattern_no_param!(PyTdPropulsion, wc::TdPropulsion, "TDPropulsion");
|
||||
candle_pattern_no_param!(PyTdTrap, wc::TdTrap, "TDTrap");
|
||||
// ============================== Microstructure: Order Book ==============================
|
||||
//
|
||||
// Order-book indicators consume a depth snapshot rather than OHLCV. Streaming
|
||||
@@ -24028,6 +24158,8 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<PyTdRei>()?;
|
||||
m.add_class::<PyTdPressure>()?;
|
||||
m.add_class::<PyTdCombo>()?;
|
||||
m.add_class::<PyTdDWave>()?;
|
||||
m.add_class::<PyTdMovingAverage>()?;
|
||||
m.add_class::<PyTdCountdown>()?;
|
||||
m.add_class::<PyTdLines>()?;
|
||||
m.add_class::<PyTdRangeProjection>()?;
|
||||
@@ -24336,5 +24468,10 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<PyAdaptiveRsi>()?;
|
||||
m.add_class::<PyUniversalOscillator>()?;
|
||||
m.add_class::<PyAdaptiveCci>()?;
|
||||
m.add_class::<PyTdCamouflage>()?;
|
||||
m.add_class::<PyTdClop>()?;
|
||||
m.add_class::<PyTdClopwin>()?;
|
||||
m.add_class::<PyTdPropulsion>()?;
|
||||
m.add_class::<PyTdTrap>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -382,6 +382,30 @@ def test_relative_strength_streaming_matches_batch():
|
||||
# 6-tuple candle; the batch helper takes only the columns it needs.
|
||||
|
||||
CANDLE_SCALAR = {
|
||||
"TDDWave": (
|
||||
lambda: ta.TDDWave(2),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
),
|
||||
"TDTrap": (
|
||||
lambda: ta.TDTrap(),
|
||||
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
|
||||
),
|
||||
"TDPropulsion": (
|
||||
lambda: ta.TDPropulsion(),
|
||||
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
|
||||
),
|
||||
"TDClopwin": (
|
||||
lambda: ta.TDClopwin(),
|
||||
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
|
||||
),
|
||||
"TDClop": (
|
||||
lambda: ta.TDClop(),
|
||||
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
|
||||
),
|
||||
"TDCamouflage": (
|
||||
lambda: ta.TDCamouflage(),
|
||||
lambda ind, h, l, c, v: ind.batch(c, h, l, c),
|
||||
),
|
||||
"PivotReversal": (
|
||||
lambda: ta.PivotReversal(1, 1),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
@@ -952,6 +976,11 @@ def test_candle_scalar_streaming_matches_batch(name, ohlcv):
|
||||
# --- Candle-input, multi-output indicators --------------------------------
|
||||
|
||||
MULTI = {
|
||||
"TDMovingAverage": (
|
||||
lambda: ta.TDMovingAverage(5, 13),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l),
|
||||
2,
|
||||
),
|
||||
"VolumeWeightedSr": (
|
||||
lambda: ta.VolumeWeightedSr(3),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, v),
|
||||
@@ -3174,6 +3203,38 @@ def test_pivot_reversal_reference():
|
||||
assert t.update((13.0, 14.0, 12.5, 13.0, 1.0, 4)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
|
||||
def test_td_camouflage_reference():
|
||||
t = ta.TDCamouflage()
|
||||
assert t.update((10.0, 11.0, 8.0, 10.0, 1.0, 0)) == pytest.approx(0.0)
|
||||
assert t.update((9.0, 10.0, 7.0, 9.5, 1.0, 1)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_td_clop_reference():
|
||||
t = ta.TDClop()
|
||||
assert t.update((10.0, 12.0, 9.0, 11.0, 1.0, 0)) == pytest.approx(0.0)
|
||||
assert t.update((9.0, 13.0, 8.0, 12.0, 1.0, 1)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_td_clopwin_reference():
|
||||
t = ta.TDClopwin()
|
||||
assert t.update((10.0, 15.0, 9.0, 14.0, 1.0, 0)) == pytest.approx(0.0)
|
||||
assert t.update((11.0, 14.0, 10.0, 13.0, 1.0, 1)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_td_propulsion_reference():
|
||||
t = ta.TDPropulsion()
|
||||
assert t.update((9.5, 11.0, 9.0, 10.0, 1.0, 0)) == pytest.approx(0.0)
|
||||
assert t.update((10.5, 12.0, 10.0, 11.5, 1.0, 1)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
def test_td_trap_reference():
|
||||
t = ta.TDTrap()
|
||||
assert t.update((100.0, 110.0, 90.0, 100.0, 1.0, 0)) == pytest.approx(0.0)
|
||||
assert t.update((101.5, 108.0, 95.0, 102.0, 1.0, 1)) == pytest.approx(0.0)
|
||||
assert t.update((106.0, 112.0, 100.0, 109.0, 1.0, 2)) == pytest.approx(1.0)
|
||||
|
||||
|
||||
# --- Lifecycle ------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -7817,6 +7817,109 @@ impl WasmTdCombo {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- TD D-Wave ----------
|
||||
|
||||
#[wasm_bindgen(js_name = TDDWave)]
|
||||
pub struct WasmTdDWave {
|
||||
inner: wc::TdDWave,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = TDDWave)]
|
||||
impl WasmTdDWave {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(strength: usize) -> Result<WasmTdDWave, JsError> {
|
||||
Ok(Self {
|
||||
inner: wc::TdDWave::new(strength).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
pub fn update(&mut self, high: f64, low: f64, close: f64) -> Result<Option<f64>, JsError> {
|
||||
let c = make_candle(high, low, close, 0.0)?;
|
||||
Ok(self.inner.update(c))
|
||||
}
|
||||
pub fn batch(
|
||||
&mut self,
|
||||
high: &[f64],
|
||||
low: &[f64],
|
||||
close: &[f64],
|
||||
) -> Result<Float64Array, JsError> {
|
||||
if high.len() != low.len() || low.len() != close.len() {
|
||||
return Err(JsError::new("high, low, close must be equal length"));
|
||||
}
|
||||
let mut out = Vec::with_capacity(high.len());
|
||||
for i in 0..high.len() {
|
||||
let c = make_candle(high[i], low[i], close[i], 0.0)?;
|
||||
out.push(self.inner.update(c).unwrap_or(f64::NAN));
|
||||
}
|
||||
Ok(Float64Array::from(out.as_slice()))
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[wasm_bindgen(js_name = isReady)]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[wasm_bindgen(js_name = warmupPeriod)]
|
||||
pub fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- TD Moving Averages ----------
|
||||
|
||||
#[wasm_bindgen(js_name = TDMovingAverage)]
|
||||
pub struct WasmTdMovingAverage {
|
||||
inner: wc::TdMovingAverage,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(js_class = TDMovingAverage)]
|
||||
impl WasmTdMovingAverage {
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(period_st1: usize, period_st2: usize) -> Result<WasmTdMovingAverage, JsError> {
|
||||
Ok(Self {
|
||||
inner: wc::TdMovingAverage::new(period_st1, period_st2).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
pub fn update(&mut self, high: f64, low: f64) -> Result<JsValue, JsError> {
|
||||
let candle = make_candle(high, low, low, 0.0)?;
|
||||
match self.inner.update(candle) {
|
||||
Some(o) => {
|
||||
let obj = Object::new();
|
||||
Reflect::set(&obj, &"st1".into(), &o.st1.into()).ok();
|
||||
Reflect::set(&obj, &"st2".into(), &o.st2.into()).ok();
|
||||
Ok(obj.into())
|
||||
}
|
||||
None => Ok(JsValue::NULL),
|
||||
}
|
||||
}
|
||||
pub fn batch(&mut self, high: &[f64], low: &[f64]) -> Result<Float64Array, JsError> {
|
||||
if high.len() != low.len() {
|
||||
return Err(JsError::new("high, low must be equal length"));
|
||||
}
|
||||
let n = high.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = make_candle(high[i], low[i], low[i], 0.0)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.st1;
|
||||
out[i * 2 + 1] = o.st2;
|
||||
}
|
||||
}
|
||||
Ok(Float64Array::from(out.as_slice()))
|
||||
}
|
||||
pub fn reset(&mut self) {
|
||||
self.inner.reset();
|
||||
}
|
||||
#[wasm_bindgen(js_name = isReady)]
|
||||
pub fn is_ready(&self) -> bool {
|
||||
self.inner.is_ready()
|
||||
}
|
||||
#[wasm_bindgen(js_name = warmupPeriod)]
|
||||
pub fn warmup_period(&self) -> usize {
|
||||
self.inner.warmup_period()
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- TD Countdown ----------
|
||||
|
||||
#[wasm_bindgen(js_name = TDCountdown)]
|
||||
@@ -8942,6 +9045,11 @@ wasm_candle_pattern!(WasmCrab, wc::Crab, Crab);
|
||||
wasm_candle_pattern!(WasmShark, wc::Shark, Shark);
|
||||
wasm_candle_pattern!(WasmCypher, wc::Cypher, Cypher);
|
||||
wasm_candle_pattern!(WasmThreeDrives, wc::ThreeDrives, ThreeDrives);
|
||||
wasm_candle_pattern!(WasmTdCamouflage, wc::TdCamouflage, TDCamouflage);
|
||||
wasm_candle_pattern!(WasmTdClop, wc::TdClop, TDClop);
|
||||
wasm_candle_pattern!(WasmTdClopwin, wc::TdClopwin, TDClopwin);
|
||||
wasm_candle_pattern!(WasmTdPropulsion, wc::TdPropulsion, TDPropulsion);
|
||||
wasm_candle_pattern!(WasmTdTrap, wc::TdTrap, TDTrap);
|
||||
|
||||
// ============================== Microstructure: Order Book ==============================
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user