Skip to main content

IndicatorRefExt

Trait IndicatorRefExt 

Source
pub trait IndicatorRefExt: IndicatorRef + Sized {
    // Provided methods
    fn above(self, threshold: f64) -> Above<Self> { ... }
    fn above_ref<R: IndicatorRef>(self, other: R) -> AboveRef<Self, R> { ... }
    fn below(self, threshold: f64) -> Below<Self> { ... }
    fn below_ref<R: IndicatorRef>(self, other: R) -> BelowRef<Self, R> { ... }
    fn crosses_above(self, threshold: f64) -> CrossesAbove<Self> { ... }
    fn crosses_above_ref<R: IndicatorRef>(
        self,
        other: R,
    ) -> CrossesAboveRef<Self, R> { ... }
    fn crosses_below(self, threshold: f64) -> CrossesBelow<Self> { ... }
    fn crosses_below_ref<R: IndicatorRef>(
        self,
        other: R,
    ) -> CrossesBelowRef<Self, R> { ... }
    fn between(self, low: f64, high: f64) -> Between<Self> { ... }
    fn equals(self, value: f64, tolerance: f64) -> Equals<Self> { ... }
}
Expand description

Extension trait that adds condition-building methods to all indicator references.

This trait provides a fluent API for building conditions from indicator values. It is automatically implemented for all types that implement IndicatorRef.

§Example

use finance_query::backtesting::refs::*;

// All these methods are available on any IndicatorRef
let cond1 = rsi(14).above(70.0);
let cond2 = rsi(14).below(30.0);
let cond3 = rsi(14).crosses_above(30.0);
let cond4 = rsi(14).crosses_below(70.0);
let cond5 = rsi(14).between(30.0, 70.0);
let cond6 = sma(10).above_ref(sma(20));
let cond7 = sma(10).crosses_above_ref(sma(20));

Provided Methods§

Source

fn above(self, threshold: f64) -> Above<Self>

Create a condition that checks if this indicator is above a threshold.

§Example
let overbought = rsi(14).above(70.0);
Source

fn above_ref<R: IndicatorRef>(self, other: R) -> AboveRef<Self, R>

Create a condition that checks if this indicator is above another indicator.

§Example
let uptrend = price().above_ref(sma(200));
Source

fn below(self, threshold: f64) -> Below<Self>

Create a condition that checks if this indicator is below a threshold.

§Example
let oversold = rsi(14).below(30.0);
Source

fn below_ref<R: IndicatorRef>(self, other: R) -> BelowRef<Self, R>

Create a condition that checks if this indicator is below another indicator.

§Example
let downtrend = price().below_ref(sma(200));
Source

fn crosses_above(self, threshold: f64) -> CrossesAbove<Self>

Create a condition that checks if this indicator crosses above a threshold.

A crossover occurs when the previous value was at or below the threshold and the current value is above it.

§Example
let rsi_exit_oversold = rsi(14).crosses_above(30.0);
Source

fn crosses_above_ref<R: IndicatorRef>( self, other: R, ) -> CrossesAboveRef<Self, R>

Create a condition that checks if this indicator crosses above another indicator.

§Example
let golden_cross = sma(50).crosses_above_ref(sma(200));
Source

fn crosses_below(self, threshold: f64) -> CrossesBelow<Self>

Create a condition that checks if this indicator crosses below a threshold.

A crossover occurs when the previous value was at or above the threshold and the current value is below it.

§Example
let rsi_enter_overbought = rsi(14).crosses_below(70.0);
Source

fn crosses_below_ref<R: IndicatorRef>( self, other: R, ) -> CrossesBelowRef<Self, R>

Create a condition that checks if this indicator crosses below another indicator.

§Example
let death_cross = sma(50).crosses_below_ref(sma(200));
Source

fn between(self, low: f64, high: f64) -> Between<Self>

Create a condition that checks if this indicator is between two thresholds.

Returns true when low < value < high.

§Example
let neutral_rsi = rsi(14).between(40.0, 60.0);
Source

fn equals(self, value: f64, tolerance: f64) -> Equals<Self>

Create a condition that checks if this indicator equals a value (within tolerance).

§Example
let at_zero = macd(12, 26, 9).histogram().equals(0.0, 0.001);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§