Add B7 Trailing Stops family (6 indicators) (#193)
Adds the **Trailing Stops** family deepening (B7), six new indicators (434 -> 440):
- **KaseDevStop** — Cynthia Kase's volatility stop on the standard deviation of the two-bar true range.
- **ElderSafeZone** — Alexander Elder's stop offset by a multiple of average market noise.
- **AtrRatchet** — Kaufman ATR ratchet that tightens its multiple by a per-bar increment.
- **Nrtr** — Nick Rypock Trailing Reverse (percentage band).
- **TimeBasedStop** — exits after a fixed number of bars (scalar fraction of elapsed life).
- **ModifiedMaStop** — moving-average based trailing stop.
("Wilder Volatility System" is intentionally skipped — it overlaps the existing VoltyStop/Psar/SarExt.)
Each takes Candle input; the five band/structure stops emit a {value, direction} struct, TimeBasedStop a scalar. Wired across core, Python/Node/WASM bindings, fuzz target and tests. Verified locally: 3560 core lib + 398 doc tests, clippy clean, 515 node tests, 852 pytest, counter 440.
This commit is contained in:
@@ -25,6 +25,7 @@ from __future__ import annotations
|
||||
|
||||
from ._wickra import (
|
||||
__version__,
|
||||
TimeBasedStop,
|
||||
ProjectionOscillator,
|
||||
VolatilityCone,
|
||||
VolatilityRatio,
|
||||
@@ -168,6 +169,11 @@ from ._wickra import (
|
||||
HistoricalVolatility,
|
||||
BollingerBandwidth,
|
||||
PercentB,
|
||||
# Trailing Stops
|
||||
ModifiedMaStop,
|
||||
Nrtr,
|
||||
AtrRatchet,
|
||||
ElderSafeZone,
|
||||
SuperTrend,
|
||||
ChandelierExit,
|
||||
ChandeKrollStop,
|
||||
@@ -179,6 +185,7 @@ from ._wickra import (
|
||||
PercentageTrailingStop,
|
||||
StepTrailingStop,
|
||||
RenkoTrailingStop,
|
||||
KaseDevStop,
|
||||
TrueRange,
|
||||
ChaikinVolatility,
|
||||
RVIVolatility,
|
||||
@@ -487,6 +494,7 @@ from ._wickra import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"TimeBasedStop",
|
||||
"ProjectionOscillator",
|
||||
"VolatilityCone",
|
||||
"VolatilityRatio",
|
||||
@@ -631,6 +639,11 @@ __all__ = [
|
||||
"HistoricalVolatility",
|
||||
"BollingerBandwidth",
|
||||
"PercentB",
|
||||
# Trailing Stops
|
||||
"ModifiedMaStop",
|
||||
"Nrtr",
|
||||
"AtrRatchet",
|
||||
"ElderSafeZone",
|
||||
"SuperTrend",
|
||||
"ChandelierExit",
|
||||
"ChandeKrollStop",
|
||||
@@ -642,6 +655,7 @@ __all__ = [
|
||||
"PercentageTrailingStop",
|
||||
"StepTrailingStop",
|
||||
"RenkoTrailingStop",
|
||||
"KaseDevStop",
|
||||
"TrueRange",
|
||||
"ChaikinVolatility",
|
||||
"RVIVolatility",
|
||||
|
||||
@@ -3631,6 +3631,75 @@ impl PyProjectionOscillator {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== TimeBasedStop ==============================
|
||||
|
||||
#[pyclass(name = "TimeBasedStop", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyTimeBasedStop {
|
||||
inner: wc::TimeBasedStop,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyTimeBasedStop {
|
||||
#[new]
|
||||
#[pyo3(signature = (max_bars=5))]
|
||||
fn new(max_bars: usize) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::TimeBasedStop::new(max_bars).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<f64>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c))
|
||||
}
|
||||
/// Batch over numpy columns: high, low, close (all 1-D, equal length).
|
||||
/// Ignores price; counts bars. Returns progress in `[0, 1]`.
|
||||
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))
|
||||
}
|
||||
#[getter]
|
||||
fn max_bars(&self) -> usize {
|
||||
self.inner.max_bars()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
format!("TimeBasedStop(max_bars={})", self.inner.max_bars())
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Stochastic ==============================
|
||||
|
||||
#[pyclass(name = "IMI", module = "wickra._wickra", skip_from_py_object)]
|
||||
@@ -9813,6 +9882,390 @@ impl PyRenkoTrailingStop {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Kase DevStop ==============================
|
||||
|
||||
#[pyclass(name = "KaseDevStop", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyKaseDevStop {
|
||||
inner: wc::KaseDevStop,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyKaseDevStop {
|
||||
#[new]
|
||||
#[pyo3(signature = (period=30, dev=1.0))]
|
||||
fn new(period: usize, dev: f64) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::KaseDevStop::new(period, dev).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.value, o.direction)))
|
||||
}
|
||||
/// Batch over numpy columns high, low, close. Returns shape `(n, 2)` with
|
||||
/// columns `[value, direction]`; warmup rows are `NaN`.
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: 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))?;
|
||||
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 n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.value;
|
||||
out[i * 2 + 1] = o.direction;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
#[getter]
|
||||
fn params(&self) -> (usize, f64) {
|
||||
self.inner.params()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
let (period, dev) = self.inner.params();
|
||||
format!("KaseDevStop(period={period}, dev={dev})")
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Elder SafeZone ==============================
|
||||
|
||||
#[pyclass(name = "ElderSafeZone", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyElderSafeZone {
|
||||
inner: wc::ElderSafeZone,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyElderSafeZone {
|
||||
#[new]
|
||||
#[pyo3(signature = (period=14, coeff=2.0))]
|
||||
fn new(period: usize, coeff: f64) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::ElderSafeZone::new(period, coeff).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.value, o.direction)))
|
||||
}
|
||||
/// Batch over numpy columns high, low, close. Returns shape `(n, 2)` with
|
||||
/// columns `[value, direction]`; warmup rows are `NaN`.
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: 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))?;
|
||||
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 n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.value;
|
||||
out[i * 2 + 1] = o.direction;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
#[getter]
|
||||
fn params(&self) -> (usize, f64) {
|
||||
self.inner.params()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
let (period, coeff) = self.inner.params();
|
||||
format!("ElderSafeZone(period={period}, coeff={coeff})")
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== ATR Ratchet ==============================
|
||||
|
||||
#[pyclass(name = "AtrRatchet", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyAtrRatchet {
|
||||
inner: wc::AtrRatchet,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyAtrRatchet {
|
||||
#[new]
|
||||
#[pyo3(signature = (atr_period=14, start_mult=4.0, increment=0.1))]
|
||||
fn new(atr_period: usize, start_mult: f64, increment: f64) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::AtrRatchet::new(atr_period, start_mult, increment).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.value, o.direction)))
|
||||
}
|
||||
/// Batch over numpy columns high, low, close. Returns shape `(n, 2)` with
|
||||
/// columns `[value, direction]`; warmup rows are `NaN`.
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: 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))?;
|
||||
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 n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.value;
|
||||
out[i * 2 + 1] = o.direction;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
#[getter]
|
||||
fn params(&self) -> (usize, f64, f64) {
|
||||
self.inner.params()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
let (atr_period, start_mult, increment) = self.inner.params();
|
||||
format!(
|
||||
"AtrRatchet(atr_period={atr_period}, start_mult={start_mult}, increment={increment})"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== NRTR ==============================
|
||||
|
||||
#[pyclass(name = "Nrtr", module = "wickra._wickra", skip_from_py_object)]
|
||||
#[derive(Clone)]
|
||||
struct PyNrtr {
|
||||
inner: wc::Nrtr,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyNrtr {
|
||||
#[new]
|
||||
#[pyo3(signature = (pct=2.0))]
|
||||
fn new(pct: f64) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::Nrtr::new(pct).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.value, o.direction)))
|
||||
}
|
||||
/// Batch over numpy columns high, low, close. Returns shape `(n, 2)` with
|
||||
/// columns `[value, direction]`; warmup rows are `NaN`.
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: 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))?;
|
||||
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 n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.value;
|
||||
out[i * 2 + 1] = o.direction;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
#[getter]
|
||||
fn pct(&self) -> f64 {
|
||||
self.inner.pct()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
format!("Nrtr(pct={})", self.inner.pct())
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Modified MA Stop ==============================
|
||||
|
||||
#[pyclass(
|
||||
name = "ModifiedMaStop",
|
||||
module = "wickra._wickra",
|
||||
skip_from_py_object
|
||||
)]
|
||||
#[derive(Clone)]
|
||||
struct PyModifiedMaStop {
|
||||
inner: wc::ModifiedMaStop,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl PyModifiedMaStop {
|
||||
#[new]
|
||||
#[pyo3(signature = (period=14))]
|
||||
fn new(period: usize) -> PyResult<Self> {
|
||||
Ok(Self {
|
||||
inner: wc::ModifiedMaStop::new(period).map_err(map_err)?,
|
||||
})
|
||||
}
|
||||
fn update(&mut self, candle: &Bound<'_, PyAny>) -> PyResult<Option<(f64, f64)>> {
|
||||
let c = extract_candle(candle)?;
|
||||
Ok(self.inner.update(c).map(|o| (o.value, o.direction)))
|
||||
}
|
||||
/// Batch over numpy columns high, low, close. Returns shape `(n, 2)` with
|
||||
/// columns `[value, direction]`; warmup rows are `NaN`.
|
||||
fn batch<'py>(
|
||||
&mut self,
|
||||
py: Python<'py>,
|
||||
high: PyReadonlyArray1<'py, f64>,
|
||||
low: PyReadonlyArray1<'py, f64>,
|
||||
close: 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))?;
|
||||
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 n = h.len();
|
||||
let mut out = vec![f64::NAN; n * 2];
|
||||
for i in 0..n {
|
||||
let candle = wc::Candle::new(c[i], h[i], l[i], c[i], 0.0, 0).map_err(map_err)?;
|
||||
if let Some(o) = self.inner.update(candle) {
|
||||
out[i * 2] = o.value;
|
||||
out[i * 2 + 1] = o.direction;
|
||||
}
|
||||
}
|
||||
Ok(numpy::ndarray::Array2::from_shape_vec((n, 2), out)
|
||||
.expect("shape consistent")
|
||||
.into_pyarray(py))
|
||||
}
|
||||
#[getter]
|
||||
fn period(&self) -> usize {
|
||||
self.inner.period()
|
||||
}
|
||||
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()
|
||||
}
|
||||
fn __repr__(&self) -> String {
|
||||
format!("ModifiedMaStop(period={})", self.inner.period())
|
||||
}
|
||||
}
|
||||
|
||||
// ============================== Typical Price ==============================
|
||||
|
||||
#[pyclass(name = "TypicalPrice", module = "wickra._wickra", skip_from_py_object)]
|
||||
@@ -21894,6 +22347,11 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<PyPercentageTrailingStop>()?;
|
||||
m.add_class::<PyStepTrailingStop>()?;
|
||||
m.add_class::<PyRenkoTrailingStop>()?;
|
||||
m.add_class::<PyKaseDevStop>()?;
|
||||
m.add_class::<PyElderSafeZone>()?;
|
||||
m.add_class::<PyAtrRatchet>()?;
|
||||
m.add_class::<PyNrtr>()?;
|
||||
m.add_class::<PyModifiedMaStop>()?;
|
||||
m.add_class::<PyTypicalPrice>()?;
|
||||
m.add_class::<PyMedianPrice>()?;
|
||||
m.add_class::<PyWeightedClose>()?;
|
||||
@@ -22238,5 +22696,6 @@ fn _wickra(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
||||
m.add_class::<PyVolatilityOfVolatility>()?;
|
||||
m.add_class::<PyVolatilityCone>()?;
|
||||
m.add_class::<PyProjectionOscillator>()?;
|
||||
m.add_class::<PyTimeBasedStop>()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -368,6 +368,7 @@ def test_relative_strength_streaming_matches_batch():
|
||||
# 6-tuple candle; the batch helper takes only the columns it needs.
|
||||
|
||||
CANDLE_SCALAR = {
|
||||
"TimeBasedStop": (lambda: ta.TimeBasedStop(5), lambda ind, h, l, c, v: ind.batch(h, l, c)),
|
||||
"ProjectionOscillator": (lambda: ta.ProjectionOscillator(14), lambda ind, h, l, c, v: ind.batch(h, l, c)),
|
||||
"VolatilityRatio": (lambda: ta.VolatilityRatio(14), lambda ind, h, l, c, v: ind.batch(h, l, c)),
|
||||
"TTM_TREND": (lambda: ta.TTM_TREND(6), lambda ind, h, l, c, v: ind.batch(h, l, c)),
|
||||
@@ -908,6 +909,31 @@ def test_candle_scalar_streaming_matches_batch(name, ohlcv):
|
||||
# --- Candle-input, multi-output indicators --------------------------------
|
||||
|
||||
MULTI = {
|
||||
"ModifiedMaStop": (
|
||||
lambda: ta.ModifiedMaStop(14),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
2,
|
||||
),
|
||||
"Nrtr": (
|
||||
lambda: ta.Nrtr(2.0),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
2,
|
||||
),
|
||||
"AtrRatchet": (
|
||||
lambda: ta.AtrRatchet(14, 4.0, 0.1),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
2,
|
||||
),
|
||||
"ElderSafeZone": (
|
||||
lambda: ta.ElderSafeZone(14, 2.0),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
2,
|
||||
),
|
||||
"KaseDevStop": (
|
||||
lambda: ta.KaseDevStop(3, 1.0),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l, c),
|
||||
2,
|
||||
),
|
||||
"ProjectionBands": (
|
||||
lambda: ta.ProjectionBands(3),
|
||||
lambda ind, h, l, c, v: ind.batch(h, l),
|
||||
@@ -2967,6 +2993,53 @@ def test_projection_oscillator_reference():
|
||||
assert t.update((9.0, 12.0, 9.0, 11.0, 1.0, 1)) is None
|
||||
assert t.update((10.0, 11.0, 10.0, 11.0, 1.0, 2)) == pytest.approx(40.0)
|
||||
|
||||
|
||||
def test_kase_devstop_reference():
|
||||
t = ta.KaseDevStop(3, 1.0)
|
||||
assert t.update((100.0, 101.0, 99.0, 100.0, 1.0, 0)) is None
|
||||
assert t.update((101.0, 102.0, 100.0, 101.0, 1.0, 1)) is None
|
||||
assert t.update((102.0, 103.0, 101.0, 102.0, 1.0, 2)) is None
|
||||
assert t.update((102.5, 104.0, 102.0, 103.0, 1.0, 3)) == pytest.approx((101.0, 1.0))
|
||||
|
||||
|
||||
def _stop_candles(n):
|
||||
# Gently rising, valid OHLC: high >= open/close, low <= open/close.
|
||||
return [(100.0 + i, 101.5 + i, 98.5 + i, 100.5 + i, 1.0, i) for i in range(n)]
|
||||
|
||||
|
||||
def test_elder_safezone_reference():
|
||||
t = ta.ElderSafeZone(14, 2.0)
|
||||
candles = _stop_candles(15)
|
||||
for c in candles[:14]:
|
||||
assert t.update(c) is None
|
||||
assert t.update(candles[14]) == pytest.approx((112.5, 1.0))
|
||||
|
||||
|
||||
def test_atr_ratchet_reference():
|
||||
t = ta.AtrRatchet(14, 4.0, 0.1)
|
||||
candles = _stop_candles(14)
|
||||
for c in candles[:13]:
|
||||
assert t.update(c) is None
|
||||
assert t.update(candles[13]) == pytest.approx((101.5, 1.0))
|
||||
|
||||
|
||||
def test_nrtr_reference():
|
||||
t = ta.Nrtr(2.0)
|
||||
assert t.update((100.0, 100.0, 100.0, 100.0, 1.0, 0)) == pytest.approx((98.0, 1.0))
|
||||
|
||||
|
||||
def test_time_based_stop_reference():
|
||||
t = ta.TimeBasedStop(5)
|
||||
assert t.update((100.0, 101.0, 99.0, 100.0, 1.0, 0)) == pytest.approx(0.2)
|
||||
|
||||
|
||||
def test_modified_ma_stop_reference():
|
||||
t = ta.ModifiedMaStop(14)
|
||||
candles = _stop_candles(14)
|
||||
for c in candles[:13]:
|
||||
assert t.update(c) is None
|
||||
assert t.update(candles[13]) == pytest.approx((107.0, 1.0))
|
||||
|
||||
# --- Lifecycle ------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user