use crate::BarIndicatorId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RoleKind {
Smoother,
OscillatorBounded,
OscillatorUnbounded,
Channel,
Volatility,
TrendStrength,
VolumeFlow,
PivotIndicator,
PatternDetector,
RegimeFilter,
TrendStop,
StatisticalScoring,
Other,
}
pub fn role_kind_for(id: BarIndicatorId) -> RoleKind {
match id {
BarIndicatorId::Sma
| BarIndicatorId::Ema
| BarIndicatorId::Wma
| BarIndicatorId::Hma
| BarIndicatorId::Rma
| BarIndicatorId::Dema
| BarIndicatorId::Tema
| BarIndicatorId::Tma
| BarIndicatorId::Trima
| BarIndicatorId::T3
| BarIndicatorId::Alma
| BarIndicatorId::Ama
| BarIndicatorId::Jma
| BarIndicatorId::Mcginley
| BarIndicatorId::Lr
| BarIndicatorId::Vwap
| BarIndicatorId::Vwma
| BarIndicatorId::SessionVwap
| BarIndicatorId::AvFrama
| BarIndicatorId::AvVidya
| BarIndicatorId::Ehlersfa
| BarIndicatorId::Ehlersz
| BarIndicatorId::Framaadv
| BarIndicatorId::Adaptivema
| BarIndicatorId::Frama
| BarIndicatorId::Kama
| BarIndicatorId::Mama
| BarIndicatorId::Vidya
| BarIndicatorId::Abgfilter
| BarIndicatorId::Ekf
| BarIndicatorId::Kalman
| BarIndicatorId::Kslope
| BarIndicatorId::Kslopez
| BarIndicatorId::Particle
| BarIndicatorId::Rts
| BarIndicatorId::Zlsma
| BarIndicatorId::FootprintPoc => RoleKind::Smoother,
BarIndicatorId::Supertrend
| BarIndicatorId::Ssl
| BarIndicatorId::GannHilo => RoleKind::TrendStop,
BarIndicatorId::Rsi
| BarIndicatorId::StochRsi
| BarIndicatorId::Stoch
| BarIndicatorId::Stochkd
| BarIndicatorId::AdaptiveStoch
| BarIndicatorId::Cci
| BarIndicatorId::WilliamsR
| BarIndicatorId::Mfi
| BarIndicatorId::IftRsi
| BarIndicatorId::Demarker
| BarIndicatorId::ConnorsRsi
| BarIndicatorId::Imi
| BarIndicatorId::Kdj
| BarIndicatorId::Psl
| BarIndicatorId::Qqe
| BarIndicatorId::Uo
| BarIndicatorId::UoSmooth
| BarIndicatorId::Rsx
| BarIndicatorId::Rsioma
| BarIndicatorId::AtrRsi
| BarIndicatorId::Vwrsi
| BarIndicatorId::Smi
| BarIndicatorId::Pzo => RoleKind::OscillatorBounded,
BarIndicatorId::Macd
| BarIndicatorId::MacdHist
| BarIndicatorId::MacdHistZ
| BarIndicatorId::MacdSignal
| BarIndicatorId::Roc
| BarIndicatorId::RocPct
| BarIndicatorId::Cmo
| BarIndicatorId::Tsi
| BarIndicatorId::Ewmac
| BarIndicatorId::EwmacRobust
| BarIndicatorId::Ppo
| BarIndicatorId::PpoSignal
| BarIndicatorId::Apo
| BarIndicatorId::Coppock
| BarIndicatorId::Bop
| BarIndicatorId::Kst
| BarIndicatorId::Kvo
| BarIndicatorId::Trix
| BarIndicatorId::Stc
| BarIndicatorId::Pfe
| BarIndicatorId::Pmo
| BarIndicatorId::Bias
| BarIndicatorId::Dpo
| BarIndicatorId::DpoPct
| BarIndicatorId::Rvgi
| BarIndicatorId::MoFisher
| BarIndicatorId::Dss
| BarIndicatorId::Gator
| BarIndicatorId::Cog
| BarIndicatorId::Didi => RoleKind::OscillatorUnbounded,
BarIndicatorId::Bb
| BarIndicatorId::Kc
| BarIndicatorId::Dc
| BarIndicatorId::Atrchan
| BarIndicatorId::Envelope
| BarIndicatorId::Regchan
| BarIndicatorId::Starc
| BarIndicatorId::Adaptivebb
| BarIndicatorId::Vwapchan
| BarIndicatorId::Projbands
| BarIndicatorId::Theilsenchan
| BarIndicatorId::Stddevchan
| BarIndicatorId::Medchan
| BarIndicatorId::Adaptivechan
| BarIndicatorId::Darvas
| BarIndicatorId::Dpobands
| BarIndicatorId::Trimabands
| BarIndicatorId::Qrchan
| BarIndicatorId::Pivotchan
| BarIndicatorId::Pricechan
| BarIndicatorId::Percentilech
| BarIndicatorId::Ichimoku
| BarIndicatorId::Ichimokupos
| BarIndicatorId::Ichimokuthick => RoleKind::Channel,
BarIndicatorId::Atr
| BarIndicatorId::Natr
| BarIndicatorId::Atrp
| BarIndicatorId::Atrbw
| BarIndicatorId::Atrc
| BarIndicatorId::Atrpt
| BarIndicatorId::Atrz
| BarIndicatorId::Tr
| BarIndicatorId::Rvi
| BarIndicatorId::Rv
| BarIndicatorId::Rvz
| BarIndicatorId::Chop
| BarIndicatorId::Ui
| BarIndicatorId::Vov
| BarIndicatorId::Vovp
| BarIndicatorId::Vovpt
| BarIndicatorId::Avr
| BarIndicatorId::Bpv
| BarIndicatorId::C2cvp
| BarIndicatorId::Cv
| BarIndicatorId::Dvr
| BarIndicatorId::Har
| BarIndicatorId::Hvc2c
| BarIndicatorId::Kp
| BarIndicatorId::Nr
| BarIndicatorId::Pgry
| BarIndicatorId::Rbvj
| BarIndicatorId::Rcb
| BarIndicatorId::Rp
| BarIndicatorId::Rq
| BarIndicatorId::Sqmom
| BarIndicatorId::Vbd
| BarIndicatorId::Vbexp
| BarIndicatorId::VoDc
| BarIndicatorId::VoKc
| BarIndicatorId::VoMi
| BarIndicatorId::VoVr
| BarIndicatorId::Wvf
| BarIndicatorId::Fuzzy
| BarIndicatorId::Abb => RoleKind::Volatility,
BarIndicatorId::Adx
| BarIndicatorId::AdxSlope
| BarIndicatorId::Vhf
| BarIndicatorId::VhfMa
| BarIndicatorId::TrEr
| BarIndicatorId::Tii
| BarIndicatorId::Ravi
| BarIndicatorId::Sdl
| BarIndicatorId::Apen
| BarIndicatorId::Sampen
| BarIndicatorId::Gapo
| BarIndicatorId::Rwi
| BarIndicatorId::EmaSlope
| BarIndicatorId::KamaSlope
| BarIndicatorId::LrSlope => RoleKind::TrendStrength,
BarIndicatorId::Obv
| BarIndicatorId::Cmf
| BarIndicatorId::Vfi
| BarIndicatorId::Pvt
| BarIndicatorId::Vpt
| BarIndicatorId::Ad
| BarIndicatorId::Cho
| BarIndicatorId::Eom
| BarIndicatorId::Vzo
| BarIndicatorId::NviPvi
| BarIndicatorId::Poc
| BarIndicatorId::Pvo
| BarIndicatorId::Rvol
| BarIndicatorId::Vdelta
| BarIndicatorId::Cvd
| BarIndicatorId::Vo
| BarIndicatorId::Vpin
| BarIndicatorId::Vroc
| BarIndicatorId::Vz
| BarIndicatorId::Vprofile
| BarIndicatorId::Rvp
| BarIndicatorId::Di
| BarIndicatorId::Tmf
| BarIndicatorId::Wad
| BarIndicatorId::Asi
| BarIndicatorId::Fi
| BarIndicatorId::Ii
| BarIndicatorId::Iip
| BarIndicatorId::Iir
| BarIndicatorId::MoObv
| BarIndicatorId::FootprintChart
| BarIndicatorId::FootprintImbalance
| BarIndicatorId::UptickDowntickVolume => RoleKind::VolumeFlow,
BarIndicatorId::TradeFlowImbalance => RoleKind::OscillatorBounded,
BarIndicatorId::Pivot
| BarIndicatorId::Floorpivot
| BarIndicatorId::Camarilla
| BarIndicatorId::Demark
| BarIndicatorId::Woodie
| BarIndicatorId::Rmid
| BarIndicatorId::Rquart
| BarIndicatorId::Pivavwap
| BarIndicatorId::Avwap
| BarIndicatorId::Avwaprev
| BarIndicatorId::Avwaptouch
| BarIndicatorId::Hlva => RoleKind::PivotIndicator,
BarIndicatorId::Fvgrev
| BarIndicatorId::Fvgdur
| BarIndicatorId::Fvgalt
| BarIndicatorId::Liqgap
| BarIndicatorId::Swingstr
| BarIndicatorId::SwingAge
| BarIndicatorId::Kcomp
| BarIndicatorId::Kscr => RoleKind::StatisticalScoring,
BarIndicatorId::Bos
| BarIndicatorId::Fvg
| BarIndicatorId::Candleanatomy
| BarIndicatorId::Heikinashi
| BarIndicatorId::Wickspike => RoleKind::PatternDetector,
BarIndicatorId::Mrf
| BarIndicatorId::Hyst
| BarIndicatorId::Logicand
| BarIndicatorId::Logicor
| BarIndicatorId::Logicxor
| BarIndicatorId::Wcomp
| BarIndicatorId::Logicsign
| BarIndicatorId::HaTrend
| BarIndicatorId::Kregime => RoleKind::RegimeFilter,
BarIndicatorId::BookMicroprice => RoleKind::Smoother,
BarIndicatorId::LiquiditySweep => RoleKind::OscillatorUnbounded,
BarIndicatorId::BookPressure => RoleKind::OscillatorUnbounded,
BarIndicatorId::SpreadDistribution => RoleKind::OscillatorBounded,
BarIndicatorId::OrderBookVelocity => RoleKind::Other,
BarIndicatorId::IcebergDetector => RoleKind::PatternDetector,
BarIndicatorId::LevelReplenishRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::BookChurnRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingZScore => RoleKind::OscillatorUnbounded,
BarIndicatorId::OiChangeRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::OiZScore => RoleKind::OscillatorBounded,
BarIndicatorId::OiMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::OiPercentile => RoleKind::OscillatorBounded,
BarIndicatorId::LongSqueezeDetector => RoleKind::PatternDetector,
BarIndicatorId::OiPriceCorrelation => RoleKind::OscillatorBounded,
BarIndicatorId::Volume24hMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::HighLowRangeRatio => RoleKind::OscillatorUnbounded,
BarIndicatorId::PriceChange24hZScore => RoleKind::OscillatorBounded,
BarIndicatorId::LiquidationRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::LiquidationVolumeImbalance => RoleKind::PatternDetector,
BarIndicatorId::LiquidationCascade => RoleKind::PatternDetector,
BarIndicatorId::LiquidationVolumeVelocity => RoleKind::OscillatorUnbounded,
BarIndicatorId::StopHuntDetector => RoleKind::PatternDetector,
BarIndicatorId::LiquidationClusterDetector => RoleKind::PatternDetector,
BarIndicatorId::LiquidationCooldown => RoleKind::OscillatorUnbounded,
BarIndicatorId::LongShortRatioMomentum => RoleKind::OscillatorBounded,
BarIndicatorId::LongShortExtremeDetector => RoleKind::PatternDetector,
BarIndicatorId::RatioVsPriceDivergence => RoleKind::PatternDetector,
BarIndicatorId::AggTradeFlowImbalance => RoleKind::OscillatorBounded,
BarIndicatorId::AggTradeSizeDistribution => RoleKind::OscillatorUnbounded,
BarIndicatorId::PriceVsIndexSpread => RoleKind::OscillatorUnbounded,
BarIndicatorId::IndexComponentDrift => RoleKind::OscillatorBounded,
BarIndicatorId::IndexCorrelationBreakdown => RoleKind::OscillatorBounded,
BarIndicatorId::BasisMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::BasisExtreme => RoleKind::PatternDetector,
BarIndicatorId::BasisZScore => RoleKind::OscillatorBounded,
BarIndicatorId::HvMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::HvSpike => RoleKind::PatternDetector,
BarIndicatorId::VolIdxSpike => RoleKind::PatternDetector,
BarIndicatorId::VolIdxMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::DeltaExposureFlow => RoleKind::OscillatorUnbounded,
BarIndicatorId::GammaSqueezeDetector => RoleKind::PatternDetector,
BarIndicatorId::IvSkew => RoleKind::OscillatorUnbounded,
BarIndicatorId::CharmTracker => RoleKind::OscillatorUnbounded,
BarIndicatorId::VegaExposureFlow => RoleKind::OscillatorUnbounded,
BarIndicatorId::ThetaDecayTracker => RoleKind::OscillatorUnbounded,
BarIndicatorId::PinRiskDetector => RoleKind::PatternDetector,
BarIndicatorId::FundDepletionRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundStressDetector => RoleKind::PatternDetector,
BarIndicatorId::InsuranceFundMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::SettlementApproachSignal => RoleKind::OscillatorBounded,
BarIndicatorId::SettlementPriceMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::SettlementVsMarkSpread => RoleKind::OscillatorUnbounded,
BarIndicatorId::BlockTradeFlow => RoleKind::OscillatorUnbounded,
BarIndicatorId::BlockTradeImpact => RoleKind::OscillatorUnbounded,
BarIndicatorId::L3OrderRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::L3LargeOrderTracker => RoleKind::PatternDetector,
BarIndicatorId::L3CancelRatio => RoleKind::OscillatorBounded,
BarIndicatorId::BlockTradeSizeAnomaly => RoleKind::OscillatorBounded,
BarIndicatorId::QuoteStuffingDetector => RoleKind::PatternDetector,
BarIndicatorId::LeverageReductionWarning => RoleKind::PatternDetector,
BarIndicatorId::MmrTracker => RoleKind::OscillatorBounded,
BarIndicatorId::RiskLimitProximity => RoleKind::OscillatorBounded,
BarIndicatorId::FundingDrift => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingTimeDecay => RoleKind::OscillatorBounded,
BarIndicatorId::PredictedFundingExtreme => RoleKind::PatternDetector,
BarIndicatorId::SettledFundingMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingSettlementImpact => RoleKind::OscillatorUnbounded,
BarIndicatorId::AnnualizedFundingRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingDirectionShift => RoleKind::PatternDetector,
BarIndicatorId::FundingExtremeAlert => RoleKind::PatternDetector,
BarIndicatorId::MarkPriceMomentum => RoleKind::OscillatorUnbounded,
BarIndicatorId::MarkPriceVolatility => RoleKind::OscillatorUnbounded,
BarIndicatorId::MarkPriceGapDetector => RoleKind::PatternDetector,
BarIndicatorId::AuctionLiquidityScore => RoleKind::OscillatorUnbounded,
BarIndicatorId::AuctionPriceDeviation => RoleKind::OscillatorUnbounded,
BarIndicatorId::AuctionImbalance => RoleKind::OscillatorUnbounded,
BarIndicatorId::WarningRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::WarningFrequencyFilter => RoleKind::PatternDetector,
BarIndicatorId::TickerSpreadRatio => RoleKind::OscillatorBounded,
BarIndicatorId::Volume24hZScore => RoleKind::OscillatorBounded,
BarIndicatorId::L3SpooferScore => RoleKind::OscillatorBounded,
BarIndicatorId::QuoteLifecycleTracker => RoleKind::OscillatorUnbounded,
BarIndicatorId::FundingOiPressure => RoleKind::OscillatorUnbounded,
BarIndicatorId::IvHvSpread => RoleKind::OscillatorUnbounded,
BarIndicatorId::SqueezeProbability => RoleKind::OscillatorBounded,
BarIndicatorId::FundingSentimentAlignment => RoleKind::PatternDetector,
BarIndicatorId::VolRegimeEntry => RoleKind::PatternDetector,
BarIndicatorId::BlockTradeVolumeRatio => RoleKind::OscillatorBounded,
BarIndicatorId::CapitulationDetector => RoleKind::PatternDetector,
BarIndicatorId::IndexTrackingError => RoleKind::OscillatorUnbounded,
BarIndicatorId::BidAskAsymmetry => RoleKind::OscillatorBounded,
BarIndicatorId::BidAskBounceRate => RoleKind::OscillatorUnbounded,
BarIndicatorId::MidPriceVelocity => RoleKind::OscillatorUnbounded,
BarIndicatorId::BestLevelVolatility => RoleKind::OscillatorUnbounded,
BarIndicatorId::LayerConcentration => RoleKind::OscillatorBounded,
BarIndicatorId::PriceLevelDensity => RoleKind::OscillatorUnbounded,
BarIndicatorId::VwapDeviation => RoleKind::OscillatorUnbounded,
BarIndicatorId::TradeRunDetector => RoleKind::PatternDetector,
BarIndicatorId::SizeWeightedDirectionalMomentum => RoleKind::OscillatorBounded,
BarIndicatorId::TickFrequencyAnomaly => RoleKind::OscillatorUnbounded,
BarIndicatorId::AggressorBurstDetector => RoleKind::PatternDetector,
BarIndicatorId::LargeTickMomentum => RoleKind::OscillatorBounded,
BarIndicatorId::ValueAreaTracker => RoleKind::PivotIndicator,
BarIndicatorId::VolumeImbalanceZone => RoleKind::PatternDetector,
BarIndicatorId::MarketStressComposite => RoleKind::OscillatorBounded,
BarIndicatorId::RiskOffDetector => RoleKind::PatternDetector,
BarIndicatorId::SentimentComposite => RoleKind::OscillatorBounded,
BarIndicatorId::CompoundSqueezeProbability => RoleKind::OscillatorBounded,
BarIndicatorId::TpoSessionBalance => RoleKind::PivotIndicator,
BarIndicatorId::CompositeWeightDrift => RoleKind::OscillatorBounded,
BarIndicatorId::AdaptiveWindowSelector => RoleKind::OscillatorUnbounded,
BarIndicatorId::AdaptiveThreshold => RoleKind::OscillatorUnbounded,
_ => RoleKind::Other,
}
}
impl From<RoleKind> for crate::catalog::data::indicator_signature::IndicatorRoleKind {
fn from(r: RoleKind) -> Self {
use crate::catalog::data::indicator_signature::IndicatorRoleKind as Ik;
match r {
RoleKind::Smoother => Ik::Smoother,
RoleKind::OscillatorBounded => Ik::OscillatorBounded,
RoleKind::OscillatorUnbounded => Ik::OscillatorUnbounded,
RoleKind::Channel => Ik::Channel,
RoleKind::Volatility => Ik::Volatility,
RoleKind::TrendStrength => Ik::Regime,
RoleKind::VolumeFlow => Ik::Volume,
RoleKind::PivotIndicator => Ik::Level,
RoleKind::PatternDetector => Ik::Pattern,
RoleKind::RegimeFilter => Ik::Regime,
RoleKind::TrendStop => Ik::TrendStop,
RoleKind::StatisticalScoring => Ik::Statistical,
RoleKind::Other => Ik::Other,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn sma_is_smoother() {
assert_eq!(role_kind_for(BarIndicatorId::Sma), RoleKind::Smoother);
}
#[test]
fn rsi_is_oscillator_bounded() {
assert_eq!(role_kind_for(BarIndicatorId::Rsi), RoleKind::OscillatorBounded);
}
#[test]
fn bb_is_channel() {
assert_eq!(role_kind_for(BarIndicatorId::Bb), RoleKind::Channel);
}
#[test]
fn atr_is_volatility() {
assert_eq!(role_kind_for(BarIndicatorId::Atr), RoleKind::Volatility);
}
#[test]
fn adx_is_trend_strength() {
assert_eq!(role_kind_for(BarIndicatorId::Adx), RoleKind::TrendStrength);
}
#[test]
fn obv_is_volume_flow() {
assert_eq!(role_kind_for(BarIndicatorId::Obv), RoleKind::VolumeFlow);
}
#[test]
fn wickspike_is_pattern_detector() {
assert_eq!(role_kind_for(BarIndicatorId::Wickspike), RoleKind::PatternDetector);
}
#[test]
fn mrf_is_regime_filter() {
assert_eq!(role_kind_for(BarIndicatorId::Mrf), RoleKind::RegimeFilter);
}
#[test]
fn supertrend_is_trend_stop() {
assert_eq!(role_kind_for(BarIndicatorId::Supertrend), RoleKind::TrendStop);
}
#[test]
fn ssl_is_trend_stop() {
assert_eq!(role_kind_for(BarIndicatorId::Ssl), RoleKind::TrendStop);
}
#[test]
fn gann_hilo_is_trend_stop() {
assert_eq!(role_kind_for(BarIndicatorId::GannHilo), RoleKind::TrendStop);
}
#[test]
fn didi_is_oscillator_unbounded() {
assert_eq!(role_kind_for(BarIndicatorId::Didi), RoleKind::OscillatorUnbounded);
}
#[test]
fn hatrend_is_regime_filter() {
assert_eq!(role_kind_for(BarIndicatorId::HaTrend), RoleKind::RegimeFilter);
}
#[test]
fn kcomp_is_statistical_scoring() {
assert_eq!(role_kind_for(BarIndicatorId::Kcomp), RoleKind::StatisticalScoring);
}
#[test]
fn kregime_is_regime_filter() {
assert_eq!(role_kind_for(BarIndicatorId::Kregime), RoleKind::RegimeFilter);
}
#[test]
fn kscr_is_statistical_scoring() {
assert_eq!(role_kind_for(BarIndicatorId::Kscr), RoleKind::StatisticalScoring);
}
}