Trait yata::core::OHLCV[][src]

pub trait OHLCV {
Show methods fn open(&self) -> ValueType;
fn high(&self) -> ValueType;
fn low(&self) -> ValueType;
fn close(&self) -> ValueType;
fn volume(&self) -> ValueType; fn tp(&self) -> ValueType { ... }
fn hl2(&self) -> ValueType { ... }
fn ohlc4(&self) -> ValueType { ... }
fn clv(&self) -> ValueType { ... }
fn tr(&self, prev_candle: &dyn OHLCV) -> ValueType { ... }
fn tr_close(&self, prev_close: ValueType) -> ValueType { ... }
fn validate(&self) -> bool { ... }
fn source(&self, source: Source) -> ValueType { ... }
fn volumed_price(&self) -> ValueType { ... }
fn is_rising(&self) -> bool { ... }
fn is_falling(&self) -> bool { ... }
}
Expand description

Basic trait for implementing Open-High-Low-Close-Volume timeseries data.

It has already implemented for tuple of 5 float values:

use yata::prelude::OHLCV;
//         open high low  close, volume
let row = (2.0, 5.0, 1.0,  4.0,   10.0 );
assert_eq!(row.open(), row.0);
assert_eq!(row.high(), row.1);
assert_eq!(row.low(), row.2);
assert_eq!(row.close(), row.3);
assert_eq!(row.volume(), row.4);

See also Candle.

Required methods

Should return an open value of the period

Should return an highest value of the period

Should return an lowest value of the period

Should return an close value of the candle

Should return volume value for the period

Provided methods

Calculates Typical price. It’s just a simple (High + Low + Close) / 3

Examples

use yata::prelude::*;
use yata::core::Candle;

let candle = Candle {
    high: 10.0,
    low: 5.0,
    close: 9.0,
    ..Candle::default()
};

assert_eq!(candle.tp(), 8.0);

Calculates arithmetic average of high and low values of the candle

Examples

use yata::prelude::*;
use yata::core::Candle;

let candle = Candle {
    high: 10.0,
    low: 5.0,
    ..Candle::default()
};

assert_eq!(candle.hl2(), 7.5);

Calculates arithmetic average of high, low, open and close values of the candle

Examples

use yata::prelude::*;
use yata::core::Candle;

let candle = Candle {
    high: 10.0,
    low: 5.0,
    open: 2.0,
    close: 3.0,
    ..Candle::default()
};

assert_eq!(candle.ohlc4(), 5.0);

CLV = [(close - low) - (high - close)] / (high - low)

Examples

use yata::prelude::*;
use yata::core::Candle;
let candle = Candle {
    high: 5.0,
    low: 2.0,
    close: 4.0,
    ..Candle::default()
};

assert_eq!(candle.clv(), ((candle.close()-candle.low()) - (candle.high() - candle.close()))/(candle.high() - candle.low()));
assert_eq!(candle.clv(), ((4. - 2.) - (5. - 4.))/(5. - 2.));

Calculates True Range over last two candles

Examples

use yata::prelude::*;
use yata::core::Candle;

let candle1 = Candle {
    close: 70.0,
    ..Candle::default()
};

let candle2 = Candle {
    high: 100.0,
    low: 50.0,
    ..Candle::default()
};

let tr = candle2.tr(&candle1);
assert_eq!(tr, 50.);
use yata::prelude::*;
use yata::core::Candle;

let candle1 = Candle {
    close: 30.0,
    ..Candle::default()
};

let candle2 = Candle {
    high: 100.0,
    low: 50.0,
    ..Candle::default()
};

let tr = candle2.tr(&candle1);
assert_eq!(tr, 70.);

Calculates True Range over last two candles using close price from the previous candle.

Validates candle attributes

Returns true if validates OK

Examples

use yata::prelude::*;
use yata::core::Candle;

let candle1 = Candle {
    open: 7.0,
    high: 10.0,
    low: 7.0,
    close: 11.0, // cannot be more than high

    ..Candle::default()
};
let candle2 = Candle {
    open: 10.0,
    high: 10.0,
    low: 11.0, // low cannot be more than any other value of the candle
    close: 10.0,

    ..Candle::default()
};

assert!(!candle1.validate());
assert!(!candle2.validate());

Returns Source field value of the candle.

Examples

use yata::prelude::*;
use yata::core::{Candle, Source};
let candle = Candle {
    open: 12.0,
    high: 15.0,
    low: 7.0,
    close: 10.0,
    ..Candle::default()
};
assert_eq!(OHLCV::source(&candle, Source::Low), 7.0);
assert_eq!(OHLCV::source(&candle, "close".to_string().parse().unwrap()), 10.0);

Volumed price

Same as OHLCV::tp() * OHLCV::volume()

Checks if candle is “rising”: it’s close value greater than open value

Checks if candle is “falling”: it’s close value smaller than open value

Trait Implementations

Performs the conversion.

Implementations on Foreign Types

Implementors