pub struct TtmSqueeze { /* private fields */ }Expand description
TTM Squeeze (John Carter): a Bollinger-vs-Keltner volatility squeeze paired with a detrended-close momentum reading.
Carter’s setup detects coiled markets (low realised volatility relative to ATR) and the direction of the breakout when they uncoil:
squeeze = 1.0 if BollingerBands(period, bb_mult)
⊂ KeltnerChannels-like(SMA(period), ATR(period), kc_mult)
else 0.0
hl_mid = (max(high, period) + min(low, period)) / 2
detrend = close − (hl_mid + SMA(close, period)) / 2
momentum = LinearRegression(detrend, period) // endpointThe “Keltner-like” envelope here uses an SMA centerline (not the EMA of
typical price that Keltner uses) plus an ATR offset,
exactly as Carter’s original publication and every chart-vendor
implementation define it. Common parameters: period = 20, bb_mult = 2.0,
kc_mult = 1.5.
§Example
use wickra_core::{Candle, Indicator, TtmSqueeze};
let mut indicator = TtmSqueeze::new(20, 2.0, 1.5).unwrap();
let mut last = None;
for i in 0..40 {
let base = 100.0 + f64::from(i);
let candle =
Candle::new(base, base + 2.0, base - 2.0, base + 1.0, 10.0, i64::from(i)).unwrap();
last = indicator.update(candle);
}
assert!(last.is_some());Implementations§
Source§impl TtmSqueeze
impl TtmSqueeze
Sourcepub fn new(period: usize, bb_mult: f64, kc_mult: f64) -> Result<Self>
pub fn new(period: usize, bb_mult: f64, kc_mult: f64) -> Result<Self>
§Errors
Returns Error::PeriodZero if period == 0 and
Error::NonPositiveMultiplier if either multiplier is not strictly
positive and finite. period >= 2 is required for the linear-regression
momentum component.
Sourcepub fn classic() -> Self
pub fn classic() -> Self
John Carter’s classic configuration: period = 20, bb_mult = 2.0,
kc_mult = 1.5.
Sourcepub fn parameters(&self) -> (usize, f64, f64)
pub fn parameters(&self) -> (usize, f64, f64)
Configured (period, bb_mult, kc_mult).
Trait Implementations§
Source§impl Clone for TtmSqueeze
impl Clone for TtmSqueeze
Source§fn clone(&self) -> TtmSqueeze
fn clone(&self) -> TtmSqueeze
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TtmSqueeze
impl Debug for TtmSqueeze
Source§impl Indicator for TtmSqueeze
impl Indicator for TtmSqueeze
Source§type Input = Candle
type Input = Candle
f64 for a price, or Candle / Tick).Source§type Output = TtmSqueezeOutput
type Output = TtmSqueezeOutput
Source§fn update(&mut self, candle: Candle) -> Option<TtmSqueezeOutput>
fn update(&mut self, candle: Candle) -> Option<TtmSqueezeOutput>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for TtmSqueeze
impl RefUnwindSafe for TtmSqueeze
impl Send for TtmSqueeze
impl Sync for TtmSqueeze
impl Unpin for TtmSqueeze
impl UnsafeUnpin for TtmSqueeze
impl UnwindSafe for TtmSqueeze
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more